engine/source/scriptlib/List.c
/* add a single node to the index list */
add a single node to the index list
add a single node to the index list
void List_AddIndex(List *list, Node *node, size_t index)
{
#ifdef DEBUG
    chklist((List *)list);
#endif
    unsigned char h;
    size_t save;
    assert(node);
    if (!list->mindices)
    {
        list->mindices = calloc(1, sizeof(LIndex *) * 256);
    }
    h = ptrhash(node->value);
    if (!list->mindices[h])
    {
        list->mindices[h] = calloc(1, sizeof(LIndex));
        list->mindices[h]->nodes = calloc(1, sizeof(Node *) * 8);
        assert(list->mindices[h]->nodes != NULL);
        list->mindices[h]->indices = calloc(1, sizeof(ptrdiff_t) * 8);
        assert(list->mindices[h]->indices != NULL);
        list->mindices[h]->size = 8;
    }
    save = list->mindices[h]->size;
    assert(list->mindices[h]->used <= save);
    if (list->mindices[h]->used == save)
    {
        list->mindices[h]->nodes = realloc(list->mindices[h]->nodes, sizeof(Node *) * (save * 2));
        assert(list->mindices[h]->nodes != NULL);
        list->mindices[h]->indices = realloc(list->mindices[h]->indices, sizeof(ptrdiff_t) * (save * 2));
        assert(list->mindices[h]->indices != NULL);
        list->mindices[h]->size = save * 2;
    }
    list->mindices[h]->nodes[list->mindices[h]->used] = node;
    list->mindices[h]->indices[list->mindices[h]->used] = index;
    list->mindices[h]->used++;
}
void List_AddIndex ( List * list , Node * node , size_t index ) { #ifdef DEBUG chklist ( ( List * ) list ) ; #endif unsigned char h ; size_t save ; assert ( node ) ; if ( ! list -> mindices ) { list -> mindices = calloc ( 1 , sizeof ( LIndex * ) * 256 ) ; } h = ptrhash ( node -> value ) ; if ( ! list -> mindices [ h ] ) { list -> mindices [ h ] = calloc ( 1 , sizeof ( LIndex ) ) ; list -> mindices [ h ] -> nodes = calloc ( 1 , sizeof ( Node * ) * 8 ) ; assert ( list -> mindices [ h ] -> nodes != NULL ) ; list -> mindices [ h ] -> indices = calloc ( 1 , sizeof ( ptrdiff_t ) * 8 ) ; assert ( list -> mindices [ h ] -> indices != NULL ) ; list -> mindices [ h ] -> size = 8 ; } save = list -> mindices [ h ] -> size ; assert ( list -> mindices [ h ] -> used <= save ) ; if ( list -> mindices [ h ] -> used == save ) { list -> mindices [ h ] -> nodes = realloc ( list -> mindices [ h ] -> nodes , sizeof ( Node * ) * ( save * 2 ) ) ; assert ( list -> mindices [ h ] -> nodes != NULL ) ; list -> mindices [ h ] -> indices = realloc ( list -> mindices [ h ] -> indices , sizeof ( ptrdiff_t ) * ( save * 2 ) ) ; assert ( list -> mindices [ h ] -> indices != NULL ) ; list -> mindices [ h ] -> size = save * 2 ; } list -> mindices [ h ] -> nodes [ list -> mindices [ h ] -> used ] = node ; list -> mindices [ h ] -> indices [ list -> mindices [ h ] -> used ] = index ; list -> mindices [ h ] -> used ++ ; }
add a single node to the index list
add a single node to the index list