offbrand
A collection of generic, reference counted datastructures in C for C
 All Classes Files Functions Variables Typedefs Macros Groups
Typedefs | Functions
obmap.h File Reference

obmap Public Interface More...

#include "offbrand.h"

Go to the source code of this file.

Typedefs

typedef struct obmap_struct obmap
 

Functions

obmapobmap_new (void)
 Constructor, creates a new, empty, obmap instance with a small initial capacity. More...
 
obmapobmap_new_with_capacity (uint32_t capacity)
 Constructor, creates a new, empty obmap instance with capacity given. More...
 
obmapobmap_copy (const obmap *to_copy)
 Copy constructor, creates a new obmap with the exact same contents of another obmap. More...
 
void obmap_insert (obmap *m, obj *key, obj *value)
 Add a key-value pair to an obmap. More...
 
objobmap_lookup (const obmap *m, const obj *key)
 Lookup the value stored at key in an obmap. More...
 
void obmap_remove (obmap *m, obj *key)
 Removes a key-value pair from an obmap. More...
 
void obmap_rehash (obmap *m)
 Rehashes all elements contained in an obmap. More...
 
void obmap_clear (obmap *m)
 Clears an obmap of all key-value pairs, essentially restoring it to the initial empty state that existed after creation. More...
 

Detailed Description

obmap Public Interface

Author
theck

Typedef Documentation

typedef struct obmap_struct obmap

Class type declaration

Function Documentation

void obmap_clear ( obmap m)

Clears an obmap of all key-value pairs, essentially restoring it to the initial empty state that existed after creation.

Parameters
mPointer to an instance of obmap
obmap* obmap_copy ( const obmap to_copy)

Copy constructor, creates a new obmap with the exact same contents of another obmap.

Parameters
to_copyPointer to an instance of obmap to copy
Returns
A copy of the provided obmap
void obmap_insert ( obmap m,
obj key,
obj value 
)

Add a key-value pair to an obmap.

Parameters
mPointer to an instance of obmap
keyPointer to any Offbrand compatible class to use as a lookup key
valuePointer to any Offbrand compatible class

If the key is already contained within the m then the old value stored at that key is replaced with the new value

obj* obmap_lookup ( const obmap m,
const obj key 
)

Lookup the value stored at key in an obmap.

Parameters
mPointer to an instance of obmap
keyPointer to any Offbrand compatible class to use as a lookup key
Return values
NULLKey not found in obmap instance or key bound to NULL value
non-NULLValue found at key in obmap
obmap* obmap_new ( void  )

Constructor, creates a new, empty, obmap instance with a small initial capacity.

Returns
Pointer to the newly created obmap instance
obmap* obmap_new_with_capacity ( uint32_t  capacity)

Constructor, creates a new, empty obmap instance with capacity given.

Parameters
capacityCapacity required for obmap instance
Returns
Pointer to the newly created obmap instance
void obmap_rehash ( obmap m)

Rehashes all elements contained in an obmap.

Parameters
mPointer to an instance of obmap

This method is useful for ensuring that mutable keys will still lead to valid lookups of the associated values even after key(s) have been altered

void obmap_remove ( obmap m,
obj key 
)

Removes a key-value pair from an obmap.

Parameters
mPointer to an instance of obmap
keyPointer to any Offbrand compatible class to use as a lookup key

If no key exists then the funciton will silently do nothing

Warning
This function runs in O(n), and is inherently more expensive than an add or lookup.