FFmpeg
Loading...
Searching...
No Matches
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)
 
#define ENTRY_KEY_PTR(entry)
 
#define ENTRY_VAL_PTR(entry)
 
#define KEYS_EQUAL(k1, k2)
 

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.
 
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.
 
int ff_hashtable_set (struct FFHashtableContext *ctx, const void *key, const void *val)
 Store a value in a hash table given a key.
 
int ff_hashtable_delete (struct FFHashtableContext *ctx, const void *key)
 Delete a value from a hash table given a key.
 
void ff_hashtable_clear (struct FFHashtableContext *ctx)
 Delete all values from a hash table.
 
av_cold void ff_hashtable_freep (FFHashtableContext **ctx)
 Free a hash table.
 

Macro Definition Documentation

◆ ALIGN

#define ALIGN   _Alignof(size_t)

◆ ENTRY_PSL_VAL

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

Definition at line 53 of file hashtable.c.

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

◆ ENTRY_KEY_PTR

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

Definition at line 54 of file hashtable.c.

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

◆ ENTRY_VAL_PTR

#define ENTRY_VAL_PTR ( entry)
Value:
(ENTRY_KEY_PTR(entry) + ctx->key_size)
#define ENTRY_KEY_PTR(entry)
Definition hashtable.c:54
static AVFormatContext * ctx
Definition movenc.c:49

Definition at line 55 of file hashtable.c.

Referenced by ff_hashtable_get().

◆ KEYS_EQUAL

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

Definition at line 57 of file hashtable.c.

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

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().