indirect_table * new_indirect_table(void) { indirect_table *tab = PL_malloc(sizeof(*tab)); indirect_array *arr = &tab->array; indirect_buckets *newtab = PL_malloc(sizeof(*newtab)); int i; memset(tab, 0, sizeof(*tab)); #ifdef O_PLMT simpleMutexInit(&tab->mutex); #endif for(i=0; i<MSB(PREALLOCATED_INDIRECT_BLOCKS); i++) { arr->blocks[i] = arr->preallocated; } newtab->size = 8; newtab->buckets = PL_malloc(newtab->size*sizeof(*newtab->buckets)); memset(newtab->buckets, 0, newtab->size*sizeof(*newtab->buckets)); newtab->prev = NULL; tab->table = newtab; tab->no_hole_before = 1; tab->highest = 1; return tab; }
Table copyHTable(Table org) { Table ht; int n; ht = allocHeapOrHalt(sizeof(struct table)); LOCK_TABLE(org); *ht = *org; /* copy all attributes */ #ifdef O_PLMT ht->mutex = NULL; #endif ht->entries = allocHTableEntries(ht->buckets); for(n=0; n < ht->buckets; n++) { Symbol s, *q; q = &ht->entries[n]; for(s = org->entries[n]; s; s = s->next) { Symbol s2 = allocHeapOrHalt(sizeof(*s2)); *q = s2; q = &s2->next; s2->name = s->name; s2->value = s->value; if ( ht->copy_symbol ) (*ht->copy_symbol)(s2); } *q = NULL; } #ifdef O_PLMT if ( org->mutex ) { ht->mutex = allocHeapOrHalt(sizeof(simpleMutex)); simpleMutexInit(ht->mutex); } #endif UNLOCK_TABLE(org); return ht; }
Table newHTable(int buckets) { Table ht; ht = allocHeapOrHalt(sizeof(struct table)); ht->buckets = (buckets & ~TABLE_MASK); ht->size = 0; ht->enumerators = NULL; ht->free_symbol = NULL; ht->copy_symbol = NULL; #ifdef O_PLMT if ( (buckets & TABLE_UNLOCKED) ) ht->mutex = NULL; else { ht->mutex = allocHeapOrHalt(sizeof(simpleMutex)); simpleMutexInit(ht->mutex); } #endif ht->entries = allocHTableEntries(ht->buckets); return ht; }