static void CheckObjSetForCleanUp(Obj set, UInt expand) { UInt size = CONST_ADDR_WORD(set)[OBJSET_SIZE]; UInt bits = CONST_ADDR_WORD(set)[OBJSET_BITS]; UInt used = CONST_ADDR_WORD(set)[OBJSET_USED] + expand; UInt dirty = CONST_ADDR_WORD(set)[OBJSET_DIRTY]; if (used * 3 >= size * 2) ResizeObjSet(set, bits+1); else if (dirty && dirty >= used) ResizeObjSet(set, bits); }
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; } }
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; } }
static void PrintObjSet(Obj set) { UInt i, size = CONST_ADDR_WORD(set)[OBJSET_SIZE]; Int comma = 0; Pr("OBJ_SET([ ", 0L, 0L); for (i=0; i < size; i++) { Obj obj = CONST_ADDR_OBJ(set)[OBJSET_HDRSIZE + i ]; if (obj && obj != Undefined) { if (comma) { Pr(", ", 0L, 0L); } else { comma = 1; } PrintObj(obj); } } Pr(" ])", 0L, 0L); }
static void PrintObjMap(Obj map) { UInt i, size = CONST_ADDR_WORD(map)[OBJSET_SIZE]; Int comma = 0; Pr("OBJ_MAP([ ", 0L, 0L); for (i=0; i < size; i++) { Obj obj = CONST_ADDR_OBJ(map)[OBJSET_HDRSIZE + i * 2 ]; if (obj && obj != Undefined) { if (comma) { Pr(", ", 0L, 0L); } else { comma = 1; } PrintObj(obj); Pr(", ", 0L, 0L); PrintObj(CONST_ADDR_OBJ(map)[OBJSET_HDRSIZE + i * 2 + 1]); } } Pr(" ])", 0L, 0L); }
static inline UInt ObjHash(Obj set, Obj obj) { return FibHash((UInt) obj, CONST_ADDR_WORD(set)[OBJSET_BITS]); }
static void MarkObjMap(Obj obj) { UInt size = CONST_ADDR_WORD(obj)[OBJSET_SIZE]; MarkArrayOfBags( ADDR_OBJ(obj) + OBJSET_HDRSIZE, 2 * size ); }