Back to index

plt-scheme  4.2.1
Defines | Functions
hashtab.c File Reference
#include "xpmP.h"
#include <strings.h>

Go to the source code of this file.

Defines

#define HASH_FUNCTION   hash = (hash << 5) - hash + *hp++;
#define INITIAL_HASH_SIZE   256 /* should be enough for colors */
#define HASH_TABLE_GROWS   size = size * 2;

Functions

 LFUNC (AtomMake, xpmHashAtom,(char *name, void *data))
 LFUNC (HashTableGrows, int,(xpmHashTable *table))
static xpmHashAtom AtomMake (char *name, void *data)
xpmHashAtomxpmHashSlot (xpmHashTable *table, char *s)
static int HashTableGrows (xpmHashTable *table)
int xpmHashIntern (xpmHashTable *table, char *tag, void *data)
int xpmHashTableInit (xpmHashTable *table)
void xpmHashTableFree (xpmHashTable *table)

Define Documentation

#define HASH_FUNCTION   hash = (hash << 5) - hash + *hp++;

Definition at line 75 of file hashtab.c.

#define HASH_TABLE_GROWS   size = size * 2;

Definition at line 78 of file hashtab.c.

#define INITIAL_HASH_SIZE   256 /* should be enough for colors */

Definition at line 77 of file hashtab.c.


Function Documentation

static xpmHashAtom AtomMake ( char *  name,
void data 
) [static]

Definition at line 47 of file hashtab.c.

{
    xpmHashAtom object = (xpmHashAtom) XpmMalloc(sizeof(struct _xpmHashAtom));

    if (object) {
       object->name = name;
       object->data = data;
    }
    return object;
}

Here is the caller graph for this function:

static int HashTableGrows ( xpmHashTable table) [static]

Definition at line 139 of file hashtab.c.

{
    xpmHashAtom *atomTable = table->atomTable;
    int size = table->size;
    xpmHashAtom *t, *p;
    int i;
    int oldSize = size;

    t = atomTable;
    HASH_TABLE_GROWS
       table->size = size;
    table->limit = size / 3;
    atomTable = (xpmHashAtom *) XpmMalloc(size * sizeof(*atomTable));
    if (!atomTable)
       return (XpmNoMemory);
    table->atomTable = atomTable;
    for (p = atomTable + size; p > atomTable;)
       *--p = NULL;
    for (i = 0, p = t; i < oldSize; i++, p++)
       if (*p) {
           xpmHashAtom *ps = xpmHashSlot(table, (*p)->name);

           *ps = *p;
       }
    XpmFree(t);
    return (XpmSuccess);
}

Here is the call graph for this function:

Here is the caller graph for this function:

LFUNC ( AtomMake  ,
xpmHashAtom  ,
(char *name, void *data  
)
LFUNC ( HashTableGrows  ,
int  ,
(xpmHashTable *table)   
)
int xpmHashIntern ( xpmHashTable table,
char *  tag,
void data 
)

Definition at line 174 of file hashtab.c.

{
    xpmHashAtom *slot;

    if (!*(slot = xpmHashSlot(table, tag))) {
       /* undefined, make a new atom with the given data */
       if (!(*slot = AtomMake(tag, data)))
           return (XpmNoMemory);
       if (table->used >= table->limit) {
           int ErrorStatus;

           if ((ErrorStatus = HashTableGrows(table)) != XpmSuccess)
              return (ErrorStatus);
           table->used++;
           return (XpmSuccess);
       }
       table->used++;
    }
    return (XpmSuccess);
}

Here is the call graph for this function:

Here is the caller graph for this function:

xpmHashAtom* xpmHashSlot ( xpmHashTable table,
char *  s 
)

Definition at line 112 of file hashtab.c.

{
    xpmHashAtom *atomTable = table->atomTable;
    unsigned int hash;
    xpmHashAtom *p;
    char *hp = s;
    char *ns;

    hash = 0;
    while (*hp) {                  /* computes hash function */
       HASH_FUNCTION
    }
    p = atomTable + hash % table->size;
    while (*p) {
       ns = (*p)->name;
       if (ns[0] == s[0] && strcmp(ns, s) == 0)
           break;
       p--;
       if (p < atomTable)
           p = atomTable + table->size - 1;
    }
    return p;
}

Here is the caller graph for this function:

Definition at line 226 of file hashtab.c.

{
    xpmHashAtom *p;
    xpmHashAtom *atomTable = table->atomTable;

    for (p = atomTable + table->size; p > atomTable;)
       if (*--p)
           XpmFree(*p);
    XpmFree(atomTable);
    table->atomTable = NULL;
}

Here is the caller graph for this function:

Definition at line 203 of file hashtab.c.

{
    xpmHashAtom *p;
    xpmHashAtom *atomTable;

    table->size = INITIAL_HASH_SIZE;
    table->limit = table->size / 3;
    table->used = 0;
    atomTable = (xpmHashAtom *) XpmMalloc(table->size * sizeof(*atomTable));
    if (!atomTable)
       return (XpmNoMemory);
    for (p = atomTable + table->size; p > atomTable;)
       *--p = NULL;
    table->atomTable = atomTable;
    return (XpmSuccess);
}

Here is the caller graph for this function: