Turnstone Operating System
Loading...
Searching...
No Matches
hashmap.64.c File Reference

hashmap interface implementation More...

#include <hashmap.h>
#include <memory.h>
#include <cpu/sync.h>
#include <xxhash.h>
#include <strings.h>

Classes

struct  hashmap_item_t
 hashmap item More...
 
struct  hashmap_segment_t
 hashmap segment More...
 
struct  hashmap_t
 hashmap More...
 
struct  hashmap_iterator_metadata_t
 Metadata for the hashmap iterator. More...
 

Typedefs

typedef struct hashmap_item_t hashmap_item_t
 hashmap item
 
typedef struct hashmap_segment_t hashmap_segment_t
 hashmap segment
 
typedef struct hashmap_iterator_metadata_t hashmap_iterator_metadata_t
 Typedef for hashmap iterator metadata.
 

Functions

 MODULE ("turnstone.lib.hashmap")
 
uint64_t hashmap_default_kg (const void *key)
 default key generator More...
 
int8_t hashmap_default_kc (const void *item1, const void *item2)
 default key comparator More...
 
uint64_t hashmap_string_kg (const void *key)
 string key generator More...
 
int8_t hashmap_string_kc (const void *item1, const void *item2)
 string key comparator More...
 
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...
 
static hashmap_segment_thashmap_segment_next_new (hashmap_t *hm, hashmap_segment_t *seg)
 get next new segment More...
 
const void * hashmap_put (hashmap_t *hm, const void *key, const void *item)
 put item to 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...
 
const void * hashmap_get (hashmap_t *hm, const void *key)
 get item from 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...
 
const void * hashmap_iterator_get_item (iterator_t *iter)
 returns current item at iterator More...
 
const void * hashmap_iterator_get_extra_data (iterator_t *iter)
 returns current key at iterator More...
 
iterator_thashmap_iterator_next (iterator_t *iter)
 advances iterator to next item More...
 
int8_t hashmap_iterator_destroy (iterator_t *iter)
 destroys iterator More...
 
int8_t hashmap_iterator_end_of_iterator (iterator_t *iter)
 checks if iterator is at end More...
 
iterator_thashmap_iterator_create (hashmap_t *hm)
 create iterator of hashmap More...
 

Detailed Description

hashmap interface implementation

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

Function Documentation

◆ hashmap_default_kc()

int8_t hashmap_default_kc ( const void *  item1,
const void *  item2 
)

default key comparator

Parameters
[in]item1item1
[in]item2item2
Returns
-1 if item1 < item2, 0 if item1 == item2, 1 if item1 > item2

◆ hashmap_default_kg()

uint64_t hashmap_default_kg ( const void *  key)

default key generator

Parameters
[in]keykey
Returns
key hash xxhash64

◆ 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_iterator_destroy()

int8_t hashmap_iterator_destroy ( iterator_t iter)

destroys iterator

Parameters
[in]iteriterator
Returns
0 on success, -1 on failure

◆ hashmap_iterator_end_of_iterator()

int8_t hashmap_iterator_end_of_iterator ( iterator_t iter)

checks if iterator is at end

Parameters
[in]iteriterator
Returns
0 if iterator is at end, 1 otherwise

◆ hashmap_iterator_get_extra_data()

const void * hashmap_iterator_get_extra_data ( iterator_t iter)

returns current key at iterator

Parameters
[in]iteriterator
Returns
current key at iterator

◆ hashmap_iterator_get_item()

const void * hashmap_iterator_get_item ( iterator_t iter)

returns current item at iterator

Parameters
[in]iteriterator
Returns
current item at iterator

◆ hashmap_iterator_next()

iterator_t * hashmap_iterator_next ( iterator_t iter)

advances iterator to next item

Parameters
[in]iteriterator
Returns
iterator itself

◆ 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_segment_next_new()

static hashmap_segment_t * hashmap_segment_next_new ( hashmap_t hm,
hashmap_segment_t seg 
)
static

get next new segment

Parameters
[in]hmhashmap
[in]segsegment
Returns
next new segment

◆ 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

◆ hashmap_string_kc()

int8_t hashmap_string_kc ( const void *  item1,
const void *  item2 
)

string key comparator

Parameters
[in]item1item1
[in]item2item2
Returns
-1 if item1 < item2, 0 if item1 == item2, 1 if item1 > item2

◆ hashmap_string_kg()

uint64_t hashmap_string_kg ( const void *  key)

string key generator

Parameters
[in]keykey
Returns
key hash xxhash64

◆ MODULE()

MODULE ( "turnstone.lib.hashmap"  )

module name