T Set_union(T s, T t) { if (s == NULL) { assert(t); return copy(t, t->m_size); } else if (t == NULL) { return copy(s, s->m_size); } else { T set = copy(s, Arith_max(s->m_size, t->m_size)); assert(s->m_compare == t->m_compare && s->m_hash == t->m_hash); { /*for each member q in t*/ size_t i; struct element* q; for (i = 0; i < t->m_size; i++) { for (q = t->m_buckets[i]; q != NULL; q = q->m_next) { /*\for each member q in t*/ Set_put(set, q->m_value); } } } return set; } }
void xref(const char *name, FILE *fp, Table_T identifiers){ char buf[128]; if (name == NULL) name = ""; name = Atom_string(name); linenum = 1; while (getword(fp, buf, sizeof buf, first, rest)) { Set_T set; Table_T files; const char *id = Atom_string(buf); files = Table_get(identifiers, id); if (files == NULL) { files = Table_new(0, NULL, NULL); Table_put(identifiers, id, files); } set = Table_get(files, name); if (set == NULL) { set = Set_new(0, intcmp, inthash); Table_put(files, name, set); } { int *p = &linenum; if (!Set_member(set, p)) { NEW(p); *p = linenum; Set_put(set, p); } } } }
/*Inserts the value into the table under the corresponding fingerprint*/ void insert_atom(Table_T* table, char* fingerprint, char* name) { const char *key; const char *value; Set_T old_set; /*Turns fingerprint and name strings into Hanson atoms*/ key = Atom_string(fingerprint); value = Atom_string(name); old_set = Table_get(*table, key); if (old_set == NULL) { Set_T new_set = Set_new(1, NULL, NULL); Set_put(new_set, value); Table_put(*table, key, new_set); } else { Set_put(old_set, value); } }
int addToTable( Set_T nameSet, Table_T fpTable, fpPair pair) { const char * nameAtom = Atom_string(pair.name); if( !Set_member( nameSet, nameAtom) ) { Set_put( nameSet, nameAtom); addToTableHelp( fpTable, pair ); return 1; } else{ free (pair.name); free (pair.fp); return 0; } }
T Set_union(T s, T t) { if (s == NULL) { assert(t); return copy(t, t->size); } else if (t == NULL) return copy(s, s->size); else { T set = copy(s, Arith_max(s->size, t->size)); assert(s->cmp == t->cmp && s->hash == t->hash); { int i; struct member *q; for (i = 0; i < t->size; i++) for (q = t->buckets[i]; q; q = q->link) Set_put(set, q->member); } return set; } }
void xref(const char *name, FILE *fp, Table_T identifiers){ char buf[128]; if (name == NULL){ name = ""; } name = Atom_string(name); linenum = 1; while (getword(fp, buf, sizeof(buf), first, rest)){ Set_T set; Table_T files; const char *id = Atom_string(buf); // files <- file table in identifiers associated with id files = Table_get(identifiers, id); if (files == NULL){ files = Table_new(0, NULL, NULL); Table_put(identifiers, id, files); } // set <- set in files associated with name set = Table_get(files, name); if (set == NULL){ set = Set_new(0, intcmp, inthash); Table_put(files, name, set); } // add linenum to set, if necessary { int *p = &linenum; if (!Set_member(set, p)){ NEW(p); *p = linenum; Set_put(set, p); } } } }
//calculate the most unique fld in item against the map of lists of templates //put the tuple in that list associated with the most unique key static int _add_template(T _this_, item_ *item) { Table_T items = _this_->items; //calc most unique key oe_scalar key = NULL; int key_idx = 0; int set_size = 0; Set_T curset = NULL; for ( int i = 0; item->object[i]; i++ ) { oe_scalar tmpkey = item->object[i]; if (strcmp("_", tmpkey) == 0) continue; //don't index by wildcard Set_T s = (Set_T) Table_get( items, tmpkey ); if (s) { int size = Set_length( s ); if ( !key || size < set_size ) { key = tmpkey; key_idx = i; set_size = size; curset = s; } } else { //found an unused key key = tmpkey; key_idx = i; set_size = 0; curset = Set_new( 10, _itemcmp, _itemhash ); Table_put( items, key, curset ); break; } } if (!curset) { OE_ERR(0, "Dispatcher can not add template, make sure it is not all '_' fields\n"); //i18n return -1; } item->items = curset; item->key_idx = key_idx; //for self remove of empty sets Set_put( curset, item ); return 0; }
void send_chunk_radius(struct PL_entry *player, int32_t xin, int32_t zin, int radius) { // Get "chunk coords" xin /= 16; zin /= 16; LOG(LOG_DEBUG, "Sending new chunks center:(%d, %d)", xin, zin); Set_T oldchunkset = player->loadedchunks; // Make a new set containing coordinates of all chunks client should have Set_T newchunkset = Set_new(400, chunkcoordcmp, chunkcoordhash); for(int x = -radius; x < radius; x++) { for(int z = -radius; z < radius; z++) { // Use a circular send pattern based on Bravo/MostAwesomeDude's algo if ( x*x + z*z <= radius*radius ) { chunk_coord *coord = Malloc(sizeof(chunk_coord)); coord->x = x + xin; coord->z = z + zin; Set_put(newchunkset, coord); } } } Set_T toremove = Set_minus(oldchunkset, newchunkset); Set_T toadd = Set_minus(newchunkset, oldchunkset); Set_map(toremove, &chunkradiusunload, (void *)player); Set_map(toadd, &chunkradiusload, (void *)player); player->loadedchunks = newchunkset; Set_map(oldchunkset, &chunkradiusfree, NULL); Set_free(&oldchunkset); }
void Oec_IdSet_put(T _this_, oe_id mid) { ID_ITEM *item; item = Mem_alloc(sizeof *item, __FILE__, __LINE__); item->mid = mid; Set_put(_this_->members, item); }