Turnstone Operating System
Loading...
Searching...
No Matches
hashmap.h File Reference

hashmap interface More...

#include <types.h>
#include <iterator.h>

Macros

#define ___HASHMAP_H   0
 
#define hashmap_new_with_hkg(c, hkg)   hashmap_new_with_hkg_with_hkc(c, hkg, NULL)
 create hashmap with key generator, uses default key comparator More...
 
#define hashmap_new_with_hkc(c, hkc)   hashmap_new_with_hkg_with_hkc(c, NULL, hkc)
 create hashmap with key comparator, uses default key generator More...
 
#define hashmap_new(c)   hashmap_new_with_hkg_with_hkc(c, NULL, NULL)
 create hashmap, uses default key generator and key comparator More...
 
#define hashmap_integer(c)   hashmap_new(c)
 create hashmap with integer key, uses integer key generator and key comparator More...
 

Typedefs

typedef struct hashmap_t hashmap_t
 opaque hashmap type
 
typedef uint64_t(* hashmap_key_generator_f) (const void *item)
 hashmap key generator function type More...
 
typedef int8_t(* hashmap_key_comparator_f) (const void *item1, const void *item2)
 hashmap key comparator function type More...
 

Functions

hashmap_thashmap_new_with_hkg_with_hkc (uint64_t capacity, hashmap_key_generator_f hkg, hashmap_key_comparator_f hkc)
 create hashmap with key generator and key comparator More...
 
hashmap_thashmap_string (uint64_t capacity)
 create hashmap with string key, uses string key generator and key comparator More...
 
boolean_t hashmap_destroy (hashmap_t *hm)
 destroy hashmap More...
 
const void * hashmap_put (hashmap_t *hm, const void *key, const void *item)
 put item to hashmap More...
 
const void * hashmap_get (hashmap_t *hm, const void *key)
 get item from hashmap More...
 
const void * hashmap_get_key (hashmap_t *hm, const void *key)
 get key from hashmap More...
 
boolean_t hashmap_exists (hashmap_t *hm, const void *key)
 check existence of key in hashmap More...
 
boolean_t hashmap_delete (hashmap_t *hm, const void *key)
 delete item from hashmap More...
 
uint64_t hashmap_size (hashmap_t *hm)
 get size of hashmap More...
 
iterator_thashmap_iterator_create (hashmap_t *hm)
 create iterator of hashmap More...
 

Detailed Description

hashmap interface

This work is licensed under TURNSTONE OS Public License. Please read and understand latest version of Licence.

Macro Definition Documentation

◆ ___HASHMAP_H

#define ___HASHMAP_H   0

macro for avoiding multiple inclusion

◆ hashmap_integer

#define hashmap_integer (   c)    hashmap_new(c)

create hashmap with integer key, uses integer key generator and key comparator

Parameters
[in]ccapacity of hashmap
Returns
hashmap

◆ hashmap_new

#define hashmap_new (   c)    hashmap_new_with_hkg_with_hkc(c, NULL, NULL)

create hashmap, uses default key generator and key comparator

Parameters
[in]ccapacity of hashmap
Returns
hashmap

◆ hashmap_new_with_hkc

#define hashmap_new_with_hkc (   c,
  hkc 
)    hashmap_new_with_hkg_with_hkc(c, NULL, hkc)

create hashmap with key comparator, uses default key generator

Parameters
[in]ccapacity of hashmap
[in]hkckey comparator function
Returns
hashmap

◆ hashmap_new_with_hkg

#define hashmap_new_with_hkg (   c,
  hkg 
)    hashmap_new_with_hkg_with_hkc(c, hkg, NULL)

create hashmap with key generator, uses default key comparator

Parameters
[in]ccapacity of hashmap
[in]hkgkey generator function
Returns
hashmap

Typedef Documentation

◆ hashmap_key_comparator_f

hashmap_key_comparator_f

hashmap key comparator function type

Parameters
[in]item1item to compare
[in]item2item to compare
Returns
0 if item1 == item2, -1 if item1 < item2, 1 if item1 > item2

◆ hashmap_key_generator_f

hashmap_key_generator_f

hashmap key generator function type

Parameters
[in]itemitem to generate key
Returns
key generated from item

Function Documentation

◆ hashmap_delete()

boolean_t hashmap_delete ( hashmap_t hm,
const void *  key 
)

delete item from hashmap

Parameters
[in]hmhashmap to delete item
[in]keykey of item
Returns
true if logically same key exists and deleted successfully, false otherwise

◆ hashmap_destroy()

boolean_t hashmap_destroy ( hashmap_t hm)

destroy hashmap

Parameters
[in]hmhashmap to destroy
Returns
true if hashmap is destroyed successfully, false otherwise

◆ hashmap_exists()

boolean_t hashmap_exists ( hashmap_t hm,
const void *  key 
)

check existence of key in hashmap

Parameters
[in]hmhashmap to check existence
[in]keykey of item
Returns
true if logically same key exists, false otherwise

◆ hashmap_get()

const void * hashmap_get ( hashmap_t hm,
const void *  key 
)

get item from hashmap

Parameters
[in]hmhashmap to get item
[in]keykey of item
Returns
item if same key exists, NULL otherwise

◆ hashmap_get_key()

const void * hashmap_get_key ( hashmap_t hm,
const void *  key 
)

get key from hashmap

Parameters
[in]hmhashmap to get key
[in]keykey of item
Returns
real key if input key logically exists, NULL otherwise

◆ hashmap_iterator_create()

iterator_t * hashmap_iterator_create ( hashmap_t hm)

create iterator of hashmap

Parameters
[in]hmhashmap to create iterator
Returns
iterator of hashmap

◆ hashmap_new_with_hkg_with_hkc()

hashmap_t * hashmap_new_with_hkg_with_hkc ( uint64_t  capacity,
hashmap_key_generator_f  hkg,
hashmap_key_comparator_f  hkc 
)

create hashmap with key generator and key comparator

Parameters
[in]capacitycapacity of hashmap
[in]hkgkey generator function
[in]hkckey comparator function
Returns
hashmap

◆ hashmap_put()

const void * hashmap_put ( hashmap_t hm,
const void *  key,
const void *  item 
)

put item to hashmap

Parameters
[in]hmhashmap to put item
[in]keykey of item
[in]itemitem to put
Returns
old item if same key exists and put successfully, NULL otherwise

◆ hashmap_size()

uint64_t hashmap_size ( hashmap_t hm)

get size of hashmap

Parameters
[in]hmhashmap to get size
Returns
size of hashmap

◆ hashmap_string()

hashmap_t * hashmap_string ( uint64_t  capacity)

create hashmap with string key, uses string key generator and key comparator

Parameters
[in]capacitycapacity of hashmap
Returns
hashmap