static struct object *find_obj_n P1(char *, s) { struct object *curr, *prev; int h = ObjHash(s); curr = obj_table[h]; prev = 0; obj_searches++; while (curr) { obj_probes++; if (!strcmp(curr->name, s)) { /* found it */ if (prev) { /* not at head of list */ prev->next_hash = curr->next_hash; curr->next_hash = obj_table[h]; obj_table[h] = curr; } objs_found++; return (curr); /* pointer to object */ } prev = curr; curr = curr->next_hash; } return (0); /* not found */ }
static void AddObjSetNew(Obj set, Obj obj) { UInt size = CONST_ADDR_WORD(set)[OBJSET_SIZE]; UInt hash = ObjHash(set, obj); GAP_ASSERT(TNUM_OBJ(set) == T_OBJSET); GAP_ASSERT(hash < size); for (;;) { Obj current; current = CONST_ADDR_OBJ(set)[OBJSET_HDRSIZE+hash]; if (!current) { ADDR_OBJ(set)[OBJSET_HDRSIZE+hash] = obj; ADDR_WORD(set)[OBJSET_USED]++; CHANGED_BAG(set); return; } if (current == Undefined) { ADDR_OBJ(set)[OBJSET_HDRSIZE+hash] = obj; ADDR_WORD(set)[OBJSET_USED]++; GAP_ASSERT(ADDR_WORD(set)[OBJSET_DIRTY] >= 1); ADDR_WORD(set)[OBJSET_DIRTY]--; CHANGED_BAG(set); return; } hash++; if (hash >= size) hash = 0; } }
void remove_object_hash(struct object *ob) { struct object * s; int h = ObjHash(ob->name); s = find_obj_n(ob->name); if (s != ob) fatal("Remove object \"%s\": found a different object!\n", ob->name); obj_table[h] = ob->next_hash; ob->next_hash = 0; objs_in_table--; if (ob->flags & O_CLONE) ob->prog->num_clones--; if (ob->prog->clones == ob) { if (ob->next_all->prog == ob->prog && ob->next_all->flags & O_CLONE && ob->next_all != ob) ob->prog->clones = ob->next_all; else ob->prog->clones = NULL; } if (ob->next_all == ob) obj_list = NULL; else if (ob == obj_list) obj_list = ob->next_all; ob->prev_all->next_all = ob->next_all; ob->next_all->prev_all = ob->prev_all; }
void remove_object_hash P1(struct object *, ob) { int h = ObjHash(ob->name); struct object *s; s = find_obj_n(ob->name); DEBUG_CHECK1(s != ob, "Remove object \"%s\": found a different object!", ob->name); obj_table[h] = ob->next_hash; ob->next_hash = 0; objs_in_table--; return; }
Int FindObjSet(Obj set, Obj obj) { UInt size = CONST_ADDR_WORD(set)[OBJSET_SIZE]; UInt hash = ObjHash(set, obj); GAP_ASSERT(hash < size); for (;;) { Obj current; current = CONST_ADDR_OBJ(set)[OBJSET_HDRSIZE+hash]; if (!current) return -1; if (current == obj) return (Int) hash; hash++; if (hash >= size) hash = 0; } }
void enter_object_hash(struct object *ob) { struct object *s, *sibling; int h = ObjHash(ob->name); /* Add to object list */ if (ob->flags & O_CLONE && ob->prog->clones) { sibling = ob->prog->clones; ob->next_all = sibling; ob->prev_all = sibling->prev_all; sibling->prev_all->next_all = ob; sibling->prev_all = ob; if (sibling == obj_list) obj_list = ob; } else if (obj_list) { ob->next_all = obj_list; ob->prev_all = obj_list->prev_all; obj_list->prev_all->next_all = ob; obj_list->prev_all = ob; obj_list = ob; } else obj_list = ob->next_all = ob->prev_all = ob; if (ob->flags & O_CLONE) { ob->prog->clones = ob; ob->prog->num_clones++; } s = find_obj_n(ob->name); if (s) { if (s != ob) fatal("Duplicate object \"%s\" in object hash table\n", ob->name); else fatal("Entering object \"%s\" twice in object table\n", ob->name); } if (ob->next_hash) fatal("Object \"%s\" not found in object table but next link not null\n", ob->name); ob->next_hash = obj_table[h]; obj_table[h] = ob; objs_in_table++; }
void enter_object_hash P1(struct object *, ob) { int h = ObjHash(ob->name); IF_DEBUG(struct object *s); IF_DEBUG(s = find_obj_n(ob->name)); DEBUG_CHECK1(s && s != ob, "Duplicate object \"%s\" in object hash table", ob->name); DEBUG_CHECK1(s, "Entering object \"%s\" twice in object table", ob->name); DEBUG_CHECK1(ob->next_hash, "Object \"%s\" not found in object table but next link not null", ob->name); ob->next_hash = obj_table[h]; obj_table[h] = ob; objs_in_table++; return; }