MuPDF X.Y.Z

fitz/hash.h

Index

typedef

macro

function

Hash

macro FZ_HASH_TABLE_KEY_LENGTH

#define FZ_HASH_TABLE_KEY_LENGTH 48

typedef fz_hash_table

typedef struct fz_hash_table fz_hash_table

Generic hash-table with fixed-length keys.

The keys and values are NOT reference counted by the hash table. Callers are responsible for taking care the reference counts are correct. Inserting a duplicate entry will NOT overwrite the old value, and will return the old value.

The drop_val callback function is only used to release values when the hash table is destroyed.

typedef fz_hash_table_drop_fn

typedef void (fz_hash_table_drop_fn)(fz_context *ctx, void *val)

Function type called when a hash table entry is dropped.

Only used when the entire hash table is dropped.

function fz_new_hash_table

fz_hash_table *
fz_new_hash_table (
        fz_context *ctx,
        int initialsize,
        int keylen,
        int lock,
        fz_hash_table_drop_fn *drop_val
)

Create a new hash table.

initialsize:
The initial size of the hashtable. The hashtable may grow (double in size) if it starts to get crowded (80% full).
keylen:
byte length for each key.
lock:
-1 for no lock, otherwise the FZ_LOCK to use to protect this table.
drop_val:
Function to use to destroy values on table drop.

function fz_drop_hash_table

void
fz_drop_hash_table (
        fz_context *ctx,
        fz_hash_table *table
)

Destroy the hash table.

Values are dropped using the drop function.

function fz_hash_find

void *
fz_hash_find (
        fz_context *ctx,
        fz_hash_table *table,
        const void *key
)

Search for a matching hash within the table, and return the associated value.

function fz_hash_insert

void *
fz_hash_insert (
        fz_context *ctx,
        fz_hash_table *table,
        const void *key,
        void *val
)

Insert a new key/value pair into the hash table.

If an existing entry with the same key is found, no change is made to the hash table, and a pointer to the existing value is returned.

If no existing entry with the same key is found, ownership of val passes in, key is copied, and NULL is returned.

function fz_hash_remove

void
fz_hash_remove (
        fz_context *ctx,
        fz_hash_table *table,
        const void *key
)

Remove the entry for a given key.

The value is NOT freed, so the caller is expected to take care of this.

typedef fz_hash_table_for_each_fn

typedef void (fz_hash_table_for_each_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val)

Callback function called on each key/value pair in the hash table, when fz_hash_for_each is run.

function fz_hash_for_each

void
fz_hash_for_each (
        fz_context *ctx,
        fz_hash_table *table,
        void *state,
        fz_hash_table_for_each_fn *callback
)

Iterate over the entries in a hash table.

typedef fz_hash_table_filter_fn

typedef int (fz_hash_table_filter_fn)(fz_context *ctx, void *state, void *key, int keylen, void *val)

Callback function called on each key/value pair in the hash table, when fz_hash_filter is run to remove entries where the callback returns true.

function fz_hash_filter

void
fz_hash_filter (
        fz_context *ctx,
        fz_hash_table *table,
        void *state,
        fz_hash_table_filter_fn *callback
)

Iterate over the entries in a hash table, removing all the ones where callback returns true. Does NOT free the value of the entry, so the caller is expected to take care of this.