engine/source/scriptlib/List.c
/* add a single node to the hash list */
add a single node to the hash list
add a single node to the hash list
void List_AddHash(List *list, Node *node)
{
#ifdef DEBUG
    chklist((List *)list);
#endif
    unsigned char h;
    size_t save;
    assert(node);
    if(!node->name)
    {
        return;
    }
    if (!list->buckets)
    {
        list->buckets = calloc(1, sizeof(Bucket *) * 256);
    }
    h = strhash((char *)node->name);
    if (!list->buckets[h])
    {
        list->buckets[h] = calloc(1, sizeof(Bucket));
        list->buckets[h]->nodes = calloc(1, sizeof(Node *) * 8);
        assert(list->buckets[h]->nodes != NULL);
        list->buckets[h]->size = 8;
    }
    save = list->buckets[h]->size;
    assert(list->buckets[h]->used <= save);
    if (list->buckets[h]->used == save)
    {
        list->buckets[h]->nodes = realloc(list->buckets[h]->nodes, sizeof(Node *) * (save * 2));
        assert(list->buckets[h]->nodes != NULL);
        list->buckets[h]->size = save * 2;
    }
    list->buckets[h]->nodes[list->buckets[h]->used] = node;
    list->buckets[h]->used++;
}
void List_AddHash ( List * list , Node * node ) { #ifdef DEBUG chklist ( ( List * ) list ) ; #endif unsigned char h ; size_t save ; assert ( node ) ; if ( ! node -> name ) { return ; } if ( ! list -> buckets ) { list -> buckets = calloc ( 1 , sizeof ( Bucket * ) * 256 ) ; } h = strhash ( ( char * ) node -> name ) ; if ( ! list -> buckets [ h ] ) { list -> buckets [ h ] = calloc ( 1 , sizeof ( Bucket ) ) ; list -> buckets [ h ] -> nodes = calloc ( 1 , sizeof ( Node * ) * 8 ) ; assert ( list -> buckets [ h ] -> nodes != NULL ) ; list -> buckets [ h ] -> size = 8 ; } save = list -> buckets [ h ] -> size ; assert ( list -> buckets [ h ] -> used <= save ) ; if ( list -> buckets [ h ] -> used == save ) { list -> buckets [ h ] -> nodes = realloc ( list -> buckets [ h ] -> nodes , sizeof ( Node * ) * ( save * 2 ) ) ; assert ( list -> buckets [ h ] -> nodes != NULL ) ; list -> buckets [ h ] -> size = save * 2 ; } list -> buckets [ h ] -> nodes [ list -> buckets [ h ] -> used ] = node ; list -> buckets [ h ] -> used ++ ; }
add a single node to the hash list
add a single node to the hash list