ATLAS Offline Software
Loading...
Searching...
No Matches
HashTable.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef HEPHAESTUS_HASHTABLE_H
6#define HEPHAESTUS_HASHTABLE_H
7
8/*
9 Trivial memory-address based hash table
10*/
11
12#include <pthread.h>
13
14#ifdef __cplusplus
15extern "C" {
16#endif
17
18struct hhh_Cell {
19 void *key;
20 void *value;
21
22 struct hhh_Cell *next;
23};
24
26 pthread_mutex_t lock;
27
28 struct hhh_Cell **table;
29
30 unsigned int size;
31 unsigned int nentries;
32
34};
35
36
37/* create a new hash table of at least size minsize */
38struct hhh_HashTable *hhh_HashTable_new( unsigned long minsize );
39
40/* insert pair (key, value); return 0 on failure */
41int hhh_HashTable_insert( struct hhh_HashTable *ht, void *key, void *value );
42
43/* remove pair (key, value) from table; return 0 on failure */
45 struct hhh_HashTable *ht, void *key, void (*cleanup)( void *ptr ) );
46
47/* find value for pair; return NULL if not found */
48void *hhh_HashTable_find( struct hhh_HashTable *ht, void *key );
49
50/* merge one hash table into another */
51int hhh_HashTable_merge( struct hhh_HashTable *into, struct hhh_HashTable *from );
52
53/* delete table and (optional) contents */
54void hhh_HashTable_delete( struct hhh_HashTable *ht, void (*cleanup)( void *ptr ) );
55
56#ifdef __cplusplus
57} /* extern "C" */
58#endif
59
60#endif /* !HEPHAESTUS_HASHTABLE_H */
void hhh_HashTable_delete(struct hhh_HashTable *ht, void(*cleanup)(void *ptr))
void * hhh_HashTable_find(struct hhh_HashTable *ht, void *key)
struct hhh_HashTable * hhh_HashTable_new(unsigned long minsize)
int hhh_HashTable_remove(struct hhh_HashTable *ht, void *key, void(*cleanup)(void *ptr))
int hhh_HashTable_insert(struct hhh_HashTable *ht, void *key, void *value)
int hhh_HashTable_merge(struct hhh_HashTable *into, struct hhh_HashTable *from)
void * key
Definition HashTable.h:19
struct hhh_Cell * next
Definition HashTable.h:22
void * value
Definition HashTable.h:20
unsigned int size
Definition HashTable.h:30
struct hhh_Cell ** table
Definition HashTable.h:28
unsigned int nentries
Definition HashTable.h:31
struct hhh_Cell * lastfound
Definition HashTable.h:33
pthread_mutex_t lock
Definition HashTable.h:26