FFmpeg
Data Structures | Macros | Functions
hashtable.c File Reference
#include <stdint.h>
#include <string.h>
#include "libavutil/attributes.h"
#include "libavutil/crc.h"
#include "libavutil/error.h"
#include "libavutil/macros.h"
#include "libavutil/mem.h"
#include "hashtable.h"

Go to the source code of this file.

Data Structures

struct  FFHashtableContext
 

Macros

#define ALIGN   _Alignof(size_t)
 
#define ENTRY_PSL_VAL(entry)   (*(size_t*)(entry))
 
#define ENTRY_KEY_PTR(entry)   ((entry) + sizeof(size_t))
 
#define ENTRY_VAL_PTR(entry)   (ENTRY_KEY_PTR(entry) + ctx->key_size)
 
#define KEYS_EQUAL(k1, k2)   (!memcmp((k1), (k2), ctx->key_size))
 

Functions

av_cold int ff_hashtable_alloc (FFHashtableContext **ctx, size_t key_size, size_t val_size, size_t max_entries)
 Create a fixed-sized Robin Hood hash table. More...
 
static size_t hash_key (const struct FFHashtableContext *ctx, const void *key)
 
int ff_hashtable_get (const struct FFHashtableContext *ctx, const void *key, void *val)
 Look up a value from a hash table given a key. More...
 
int ff_hashtable_set (struct FFHashtableContext *ctx, const void *key, const void *val)
 Store a value in a hash table given a key. More...
 
int ff_hashtable_delete (struct FFHashtableContext *ctx, const void *key)
 Delete a value from a hash table given a key. More...
 
void ff_hashtable_clear (struct FFHashtableContext *ctx)
 Delete all values from a hash table. More...
 
av_cold void ff_hashtable_freep (FFHashtableContext **ctx)
 Free a hash table. More...
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN   _Alignof(size_t)

Definition at line 32 of file hashtable.c.

◆ ENTRY_PSL_VAL

#define ENTRY_PSL_VAL (   entry)    (*(size_t*)(entry))

Definition at line 53 of file hashtable.c.

◆ ENTRY_KEY_PTR

#define ENTRY_KEY_PTR (   entry)    ((entry) + sizeof(size_t))

Definition at line 54 of file hashtable.c.

◆ ENTRY_VAL_PTR

#define ENTRY_VAL_PTR (   entry)    (ENTRY_KEY_PTR(entry) + ctx->key_size)

Definition at line 55 of file hashtable.c.

◆ KEYS_EQUAL

#define KEYS_EQUAL (   k1,
  k2 
)    (!memcmp((k1), (k2), ctx->key_size))

Definition at line 57 of file hashtable.c.

Function Documentation

◆ ff_hashtable_alloc()

av_cold int ff_hashtable_alloc ( struct FFHashtableContext **  ctx,
size_t  key_size,
size_t  val_size,
size_t  max_entries 
)

Create a fixed-sized Robin Hood hash table.

Parameters
ctxcontext to allocate and initialize
key_sizesize of key type in bytes
val_sizesize of value type in bytes
max_entriesmaximum number of key-value pairs to store
Returns
zero on success, nonzero on error

Definition at line 59 of file hashtable.c.

Referenced by dxv_init(), and main().

◆ hash_key()

static size_t hash_key ( const struct FFHashtableContext ctx,
const void *  key 
)
static

Definition at line 92 of file hashtable.c.

Referenced by ff_hashtable_delete(), ff_hashtable_get(), and ff_hashtable_set().

◆ ff_hashtable_get()

int ff_hashtable_get ( const struct FFHashtableContext ctx,
const void *  key,
void *  val 
)

Look up a value from a hash table given a key.

Parameters
ctxhash table context
keypointer to key data
valdestination pointer for value data
Returns
1 if the key is found, zero if the key is not found

Definition at line 97 of file hashtable.c.

Referenced by dxv_compress_dxt1(), and main().

◆ ff_hashtable_set()

int ff_hashtable_set ( struct FFHashtableContext ctx,
const void *  key,
const void *  val 
)

Store a value in a hash table given a key.

Parameters
ctxhash table context
keypointer to key data
valpointer for value data
Returns
1 if the key is written, zero if the key is not written due to the hash table reaching max capacity

Definition at line 119 of file hashtable.c.

Referenced by dxv_compress_dxt1(), and main().

◆ ff_hashtable_delete()

int ff_hashtable_delete ( struct FFHashtableContext ctx,
const void *  key 
)

Delete a value from a hash table given a key.

Parameters
ctxhash table context
keypointer to key data
Returns
1 if the key is deleted, zero if the key is not deleted due to not being found

Definition at line 163 of file hashtable.c.

Referenced by dxv_compress_dxt1(), and main().

◆ ff_hashtable_clear()

void ff_hashtable_clear ( struct FFHashtableContext ctx)

Delete all values from a hash table.

Parameters
ctxhash table context

Definition at line 201 of file hashtable.c.

Referenced by dxv_compress_dxt1().

◆ ff_hashtable_freep()

av_cold void ff_hashtable_freep ( struct FFHashtableContext **  ctx)

Free a hash table.

Parameters
ctxhash table context

Definition at line 206 of file hashtable.c.

Referenced by dxv_close(), ff_hashtable_alloc(), and main().