OCILIB uses hash tables internally for index/name columns mapping.
OCILIB makes public its hash table’s implementation public for general purpose uses.
OCI_HashTable objects manage string keys / values that can be :
This hash table implementation :
#include "ocilib.h" int main(void) { int i, n; OCI_Connection *cn; OCI_Statement *st; OCI_Resultset *rs; OCI_HashTable *table; OCI_HashEntry *e; OCI_HashValue *v; if (!OCI_Initialize(NULL, NULL, OCI_ENV_DEFAULT)) return EXIT_FAILURE; cn = OCI_ConnectionCreate("db", "usr", "pwd", OCI_SESSION_DEFAULT); st = OCI_StatementCreate(cn); table = OCI_HashCreate(256, OCI_HASH_INTEGER); /* fill the hash table with data from DB */ OCI_ExecuteStmt(st, "select code, name from products"); rs = OCI_GetResultset(st); while (OCI_FetchNext(rs)) OCI_HashAddInt(table, OCI_GetString2(rs, "name"), OCI_GetInt2(rs, "code")); printf("%d row(s) fetched\n", OCI_GetRowCount(rs)); /* lookup an entry */ printf("code for %s is : %d\n", "Cars", OCI_HashGetInt(table, "Cars")); /* browse the hash table */ n = OCI_HashGetSize(table); for (i = 0; i < n; i++) { e = OCI_HashGetEntry(table, i); while (e != NULL) { printf (">key: '%s'\n", e->key); v = e->values; while (v != NULL) { printf ("..... value : '%i'\n", v->value.num); v = v->next; } e = e->next; } } /* destroy table */ OCI_HashFree(table); OCI_Cleanup(); return EXIT_SUCCESS; }
Functions | |
OCI_EXPORT OCI_HashTable *OCI_API | OCI_HashCreate (unsigned int size, unsigned int type) |
Create a hash table. | |
OCI_EXPORT boolean OCI_API | OCI_HashFree (OCI_HashTable *table) |
Destroy a hash table. | |
OCI_EXPORT unsigned int OCI_API | OCI_HashGetSize (OCI_HashTable *table) |
Return the size of the hash table. | |
OCI_EXPORT unsigned int OCI_API | OCI_HashGetType (OCI_HashTable *table) |
Return the type of the hash table. | |
OCI_EXPORT boolean OCI_API | OCI_HashAddString (OCI_HashTable *table, const mtext *key, const mtext *value) |
Add a pair string key / string value to the hash table. | |
OCI_EXPORT const mtext *OCI_API | OCI_HashGetString (OCI_HashTable *table, const mtext *key) |
Return the string value associated to the given key. | |
OCI_EXPORT boolean OCI_API | OCI_HashAddInt (OCI_HashTable *table, const mtext *key, int value) |
Adds a pair string key / integer value to the hash table. | |
OCI_EXPORT int OCI_API | OCI_HashGetInt (OCI_HashTable *table, const mtext *key) |
Return the integer value associated to the given key. | |
OCI_EXPORT boolean OCI_API | OCI_HashAddPointer (OCI_HashTable *table, const mtext *key, void *value) |
Adds a pair string key / pointer value to the hash table. | |
OCI_EXPORT void *OCI_API | OCI_HashGetPointer (OCI_HashTable *table, const mtext *key) |
Return a pointer associated with the given key. | |
OCI_EXPORT OCI_HashEntry *OCI_API | OCI_HashLookup (OCI_HashTable *table, const mtext *key, boolean create) |
Lookup for an entry matching the key in the table. | |
OCI_EXPORT OCI_HashValue *OCI_API | OCI_HashGetValue (OCI_HashTable *table, const mtext *key) |
Return the first hash slot that matches the key. | |
OCI_EXPORT OCI_HashEntry *OCI_API | OCI_HashGetEntry (OCI_HashTable *table, unsigned int index) |
Return the entry slot of the hash table internal list at the given position. |
OCI_EXPORT OCI_HashTable* OCI_API OCI_HashCreate | ( | unsigned int | size, |
unsigned int | type | ||
) |
Create a hash table.
size | - size of the hash table |
type | - type of the hash table |
Definition at line 77 of file hash.c.
References OCI_HashFree().
Referenced by OCI_ThreadKeyCreate().
OCI_EXPORT boolean OCI_API OCI_HashFree | ( | OCI_HashTable * | table ) |
Destroy a hash table.
table | - Table handle |
Definition at line 119 of file hash.c.
Referenced by OCI_HashCreate().
OCI_EXPORT unsigned int OCI_API OCI_HashGetSize | ( | OCI_HashTable * | table ) |
OCI_EXPORT unsigned int OCI_API OCI_HashGetType | ( | OCI_HashTable * | table ) |
Return the type of the hash table.
table | - Table handle |
OCI_EXPORT boolean OCI_API OCI_HashAddString | ( | OCI_HashTable * | table, |
const mtext * | key, | ||
const mtext * | value | ||
) |
OCI_EXPORT const mtext* OCI_API OCI_HashGetString | ( | OCI_HashTable * | table, |
const mtext * | key | ||
) |
Return the string value associated to the given key.
table | - Table handle |
key | - String key |
Definition at line 252 of file hash.c.
References OCI_HashGetValue().
OCI_EXPORT boolean OCI_API OCI_HashAddInt | ( | OCI_HashTable * | table, |
const mtext * | key, | ||
int | value | ||
) |
OCI_EXPORT int OCI_API OCI_HashGetInt | ( | OCI_HashTable * | table, |
const mtext * | key | ||
) |
Return the integer value associated to the given key.
table | - Table handle |
key | - String key |
Definition at line 280 of file hash.c.
References OCI_HashGetValue().
OCI_EXPORT boolean OCI_API OCI_HashAddPointer | ( | OCI_HashTable * | table, |
const mtext * | key, | ||
void * | value | ||
) |
Adds a pair string key / pointer value to the hash table.
table | - Table handle |
key | - String key |
value | - Pointer value |
Definition at line 443 of file hash.c.
Referenced by OCI_ThreadKeyCreate().
OCI_EXPORT void* OCI_API OCI_HashGetPointer | ( | OCI_HashTable * | table, |
const mtext * | key | ||
) |
Return a pointer associated with the given key.
table | - Table handle |
key | - String key |
Definition at line 308 of file hash.c.
References OCI_HashGetValue().
Referenced by OCI_ThreadKeyGetValue(), and OCI_ThreadKeySetValue().
OCI_EXPORT OCI_HashEntry* OCI_API OCI_HashLookup | ( | OCI_HashTable * | table, |
const mtext * | key, | ||
boolean | create | ||
) |
Lookup for an entry matching the key in the table.
table | - Table handle |
key | - String key |
create | - Do create the entry if not exists |
Definition at line 468 of file hash.c.
Referenced by OCI_HashGetValue().
OCI_EXPORT OCI_HashValue* OCI_API OCI_HashGetValue | ( | OCI_HashTable * | table, |
const mtext * | key | ||
) |
Return the first hash slot that matches the key.
table | - Table handle |
key | - String key |
Definition at line 209 of file hash.c.
References OCI_HashLookup().
Referenced by OCI_HashGetInt(), OCI_HashGetPointer(), and OCI_HashGetString().
OCI_EXPORT OCI_HashEntry* OCI_API OCI_HashGetEntry | ( | OCI_HashTable * | table, |
unsigned int | index | ||
) |