Back to index

lightning-sunbird  0.9+nobinonly
Classes | Typedefs | Functions | Variables
hash.c File Reference
#include "rdf-int.h"

Go to the source code of this file.

Classes

struct  _HashEntryStruct
struct  _HashTableStruct

Typedefs

typedef struct _HashEntryStruct HashEntryStruct
typedef HashEntryStructHashEntry
typedef struct _HashTableStruct HashTableStruct

Functions

int hashKey (HashTable ht, char *key)
HashTable NewHashTable (int size)
voidHashLookup (HashTable ht, char *key)
void HashAdd (HashTable ht, char *key, void *value)

Variables

int catCount = 0
int itemCount = 0

Class Documentation

struct _HashEntryStruct

Definition at line 44 of file hash.c.

Collaboration diagram for _HashEntryStruct:
Class Members
char * key
struct _HashEntryStruct * next
void * value
struct _HashTableStruct

Definition at line 52 of file hash.c.

Collaboration diagram for _HashTableStruct:
Class Members
HashEntry * buckets
int size

Typedef Documentation

Definition at line 50 of file hash.c.


Function Documentation

void HashAdd ( HashTable  ht,
char *  key,
void value 
)

Definition at line 94 of file hash.c.

                                               {
    int offset = hashKey(ht, key);
    HashEntry he = ht->buckets[offset];
    HashEntry prev = he;
    while (he) {
       if (strcmp(he->key, key) == 0) {
           if (value == he->value) {
              return;
           } else {
              he->value = value;
              return;
           }
       }
       prev = he;
       he = he->next;
    }
       if (startsWith("http://", key)) {
              itemCount++;
       } else {
              catCount++;
       }
    he = (HashEntry) fgetMem(sizeof(HashEntryStruct));
    he->value = value;
    he->key   = key;
    if (prev) {
      prev->next = he;
    } else {
      ht->buckets[offset] = he;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int hashKey ( HashTable  ht,
char *  key 
)

Definition at line 60 of file hash.c.

                                  {
    size_t len = strlen(key);
    int    sum = 0;
    size_t    n = 0;
       int ans;
    for (n = 0; n < len; n++) sum = sum + (int)key[n];
    ans = sum & ht->size;
       if (ans == ht->size) ans = ans-1;
       return ans; 
}

Here is the caller graph for this function:

void* HashLookup ( HashTable  ht,
char *  key 
)

Definition at line 80 of file hash.c.

                                    {
    int offset = hashKey(ht, key);
    HashEntry he = ht->buckets[offset];
    while (he) {
       if (strcmp(he->key, key) == 0) return he->value;
       he = he->next;
    }
    return NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 72 of file hash.c.

                       {
    HashTable ht = (HashTable)getMem(sizeof(HashTableStruct));
    ht->size = size;
    ht->buckets = (HashEntry*)getMem(sizeof(HashEntry) * size);
    return ht;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 90 of file hash.c.

Definition at line 91 of file hash.c.