예제 #1
0
파일: unit.c 프로젝트: UweKopf/server
void uunhash(unit * u)
{
  int key = HASH1(u->no, UMAXHASH), gk = HASH2(u->no, UMAXHASH);
  while (unithash[key] != NULL && unithash[key] != u) {
    key = (key + gk) % UMAXHASH;
  }
  assert(unithash[key] == u || !"trying to remove a unit that is not hashed");
  unithash[key] = delmarker;
}
예제 #2
0
파일: unit.c 프로젝트: UweKopf/server
void uhash(unit * u)
{
  int key = HASH1(u->no, UMAXHASH), gk = HASH2(u->no, UMAXHASH);
  while (unithash[key] != NULL && unithash[key] != delmarker
    && unithash[key] != u) {
    key = (key + gk) % UMAXHASH;
  }
  assert(unithash[key] != u || !"trying to add the same unit twice");
  unithash[key] = u;
}
예제 #3
0
파일: region.c 프로젝트: Xolgrim/server
void rhash(region * r)
{
    unsigned int rid = coor_hashkey(r->x, r->y);
    int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);
    while (regionhash[key] != NULL && regionhash[key] != DELMARKER
        && regionhash[key] != r) {
        key = (key + gk) % RMAXHASH;
    }
    assert(regionhash[key] != r || !"trying to add the same region twice");
    regionhash[key] = r;
}
예제 #4
0
파일: main.c 프로젝트: Elimut/ALM2
/* ht3: dvojite hasovani
 * viz http://en.wikipedia.org/wiki/Double_hashing
 */
char* ht3_insert (char* key) {
    unsigned hash, idx, i;
    hash = HASH1(key);
    idx = hash % PRIHRADEK;
    i = 1;
    while (ht3[idx]) {
        idx = (idx + i*HASH2(key)) % PRIHRADEK;
        i++;
        //printf("key3: %s, idx=%d, i=%d\n" ,key ,idx, i);
        pocitadlo3 ++;
    }
    return ht3[idx] = strdup(key);
}
예제 #5
0
void
bdd_insert_in_cache13(cmu_bdd_manager bddm, int tag, INT_PTR d1, INT_PTR result1, INT_PTR result2, INT_PTR result3)
{
  long hash;
  cache_entry p;

  hash=HASH1(d1);
  BDD_REDUCE(hash, bddm->op_cache.size);
  p=bdd_get_entry(bddm, tag, bddm->op_cache.table[hash].entry);
  p->slot[0]=d1;
  p->slot[1]=result1;
  p->slot[2]=result2;
  p->slot[3]=result3;
  bddm->op_cache.inserts++;
}
예제 #6
0
파일: region.c 프로젝트: Xolgrim/server
static region *rfindhash(int x, int y)
{
    unsigned int rid = coor_hashkey(x, y);
    int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);
#if HASH_STATISTICS
    ++hash_requests;
#endif
    while (regionhash[key] != NULL && (regionhash[key] == DELMARKER
        || regionhash[key]->x != x || regionhash[key]->y != y)) {
        key = (key + gk) % RMAXHASH;
#if HASH_STATISTICS
        ++hash_misses;
#endif
    }
    return regionhash[key];
}
예제 #7
0
파일: main.c 프로젝트: Elimut/ALM2
/* ulozi key do ht1 tabulky, linearni hledani.
 *
 * pokud uz je key ulozen, vracime NULL
 * pokud neni, vracime ho, resp. strdup()likat
 */
char* ht1_insert (char* key) {
    unsigned hash, idx;
    char *key0;//ukazatel na klic aktualni prihradky ht1[idx]
    hash = HASH1(key);//HASH1 je makro pro vymenu hash funkce
    idx = hash % PRIHRADEK;
    while (key0 = ht1[idx]) {
      //je [idx] prihradka obsazena? pokud je obsazena stejnym key nebudeme ukladat!
      //pozn: nez zavolame strcmp(), pozovname prvni znaky -- kvuli rychlosti
        if (key0[0]==key[0] && 0==strcmp(key0, key)) {
           return NULL;
        }
        idx = (idx + 1) % PRIHRADEK;
        // printf("key: %s, %d \n" ,key ,idx);
        pocitadlo1 ++;
    }
    return ht1[idx] = strdup(key);
}
예제 #8
0
파일: unit.c 프로젝트: UweKopf/server
unit *ufindhash(int uid)
{
  assert(uid >= 0);
#if HASH_STATISTICS
  ++hash_requests;
#endif
  if (uid >= 0) {
    int key = HASH1(uid, UMAXHASH), gk = HASH2(uid, UMAXHASH);
    while (unithash[key] != NULL && (unithash[key] == delmarker
        || unithash[key]->no != uid)) {
      key = (key + gk) % UMAXHASH;
#if HASH_STATISTICS
      ++hash_misses;
#endif
    }
    return unithash[key];
  }
  return NULL;
}
예제 #9
0
파일: Hash.c 프로젝트: TihoElek/lzw
//insert element with prefix and character into hash table
int insertInHashTable(HashTable* h, int prefix, int character){             
    if (rehashCheck(h))                                                     //if rehash is needed, rehash and don't insert
        return 0;

    int position = HASH1 (prefix, character);                               //get position to insert
	int skipper = HASH2 (prefix,character);                                 //skip skipper #slots if full (double hashing)

    while (((((*h)[position]).letter != -1)) || (position == 0)  || (position == 1)) {          //skip full slots
  		position = ((position  + skipper) % SizeOfTable);
   	}

    ((*h)[position]).prefix = prefix;                                       //insert at first empty slot
    ((*h)[position]).letter = character;
    ((*h)[position]).isRehashed = 0;
    NumberOfElements++;

    return position;                                                        //return position where inserted
    
}
예제 #10
0
파일: Hash.c 프로젝트: TihoElek/lzw
//search element in hash table given it's prefix and character(letter)
int searchInHashTable(HashTable *h, int prefix, int letter ){
    int position = HASH1( prefix, letter );
    int skipper = HASH2(prefix, letter);
    int counter = 0;

    while  ((counter < SizeOfTable) &&
           (((*h)[position]).prefix != prefix || 
           ((*h)[position]).letter != letter)){                                 //if not at that position skip

            if(((((*h)[position]).letter == -1)) && (position != 0) && (position != 1)) return -1; //in the same manner as insert was

                position = (position + skipper) % SizeOfTable;
                counter++;
    }

    if (((((*h)[ position ]).prefix == prefix) &&
       ((*h)[ position ]).letter == letter))                                    // return index in hash when found                                               
        return position;

    return -1;
}
예제 #11
0
int
bdd_lookup_in_cache13(cmu_bdd_manager bddm, int tag, INT_PTR d1, INT_PTR *result1, INT_PTR *result2, INT_PTR *result3)
{
  long hash;
  cache_entry *bin;
  cache_entry p;
  cache_entry q;
  void (*return_fn)(cmu_bdd_manager, cache_entry);

  bddm->op_cache.lookups++;
  hash=HASH1(d1);
  BDD_REDUCE(hash, bddm->op_cache.size);
  bin=bddm->op_cache.table[hash].entry;
  if ((p=bin[0]))
    {
      q=CACHE_POINTER(p);
      if (q->slot[0] != d1 || TAG(p) != tag)
	{
	if ((p=bin[1]))
	  {
	    q=CACHE_POINTER(p);
	    if (q->slot[0] != d1 || TAG(p) != tag)
	      return (0);
	    bin[1]=bin[0];
	    bin[0]=p;
	  }
	else
	  return (0);
	}
    }
  else
    return (0);
  bddm->op_cache.hits++;
  if ((return_fn=bddm->op_cache.return_fn[TAG(p)]))
    (*return_fn)(bddm, q);
  *result1=q->slot[1];
  *result2=q->slot[2];
  *result3=q->slot[3];
  return (1);
}
예제 #12
0
파일: region.c 프로젝트: Xolgrim/server
void runhash(region * r)
{
    unsigned int rid = coor_hashkey(r->x, r->y);
    int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);

#ifdef FAST_CONNECT
    int d, di;
    for (d = 0, di = MAXDIRECTIONS / 2; d != MAXDIRECTIONS; ++d, ++di) {
        region *rc = r->connect[d];
        if (rc != NULL) {
            if (di >= MAXDIRECTIONS)
                di -= MAXDIRECTIONS;
            rc->connect[di] = NULL;
            r->connect[d] = NULL;
        }
    }
#endif
    while (regionhash[key] != NULL && regionhash[key] != r) {
        key = (key + gk) % RMAXHASH;
    }
    assert(regionhash[key] == r || !"trying to remove a unit that is not hashed");
    regionhash[key] = DELMARKER;
}
예제 #13
0
static
long
bdd_rehash1(cmu_bdd_manager bddm, cache_entry p)
{
  return (HASH1(p->slot[0]));
}