Exemple #1
0
term_t embed_list_bucket(term_t bucket, heap_t *hp)
{
	embed_buck_t *eb = find_bucket(bucket);
	if (eb == 0)
		return noval;

	term_t names = nil;
	for (int i = eb->start_index; i < eb->end_index; i++)
		names = heap_cons(hp, embed_bins[i].name, names);
	return names;
}
Exemple #2
0
unsigned long
erts_gfalc_test(unsigned long op, unsigned long a1, unsigned long a2)
{
    switch (op) {
    case 0x100:	return (unsigned long) BKT_IX((GFAllctr_t *) a1, (Uint) a2);
    case 0x101:	return (unsigned long) BKT_MIN_SZ((GFAllctr_t *) a1, (int) a2);
    case 0x102:	return (unsigned long) NO_OF_BKTS;
    case 0x103:	return (unsigned long)
		    find_bucket(&((GFAllctr_t *) a1)->bucket_mask, (int) a2);
    default:	ASSERT(0); return ~((unsigned long) 0);
    }
}
UWord
erts_gfalc_test(UWord op, UWord a1, UWord a2)
{
    switch (op) {
    case 0x100:	return (UWord) BKT_IX((GFAllctr_t *) a1, (Uint) a2);
    case 0x101:	return (UWord) BKT_MIN_SZ((GFAllctr_t *) a1, (int) a2);
    case 0x102:	return (UWord) NO_OF_BKTS;
    case 0x103:	return (UWord)
		    find_bucket(&((GFAllctr_t *) a1)->bucket_mask, (int) a2);
    default:	ASSERT(0); return ~((UWord) 0);
    }
}
Exemple #4
0
void hash_record(HFILE *hf, void* record, int i, RID rid, INDEX_FILE *index_file){
	//void *buf;
	int offset=0;
	int j;
	long long hash_index;
	long long bid;
	int split;
	int mo;
	void *bucket;
	char *path;

	bucket = calloc(BSIZE,sizeof(char));
	if (bucket==NULL){
		printf("Malloc failed");
		exit(1);
	}
	//buf = malloc(105*sizeof(char));
	/*if (buf==NULL){
		printf("Malloc failed");
		exit(1);
	}*/
	for(j=0;j<i;j++){
		offset+=atoi((hf->schema[j])+1);
	}

	//(*decode[hf->schema_array[i]])(record, buf, &offset,atoi((hf->schema[i])+1));
	hash_index = (*calculate_index[hf->schema_array[i]])(record,index_file->s,index_file->n,offset);

	split = find_bucket(hash_index, &bid, &mo, index_file);

	if (mo==0){
		path = index_file->main_path;
	} else {
		path = index_file->overflow_path;
	}
	read_bucket(bucket, bid, path);

	(*update_bucket[hf->schema_array[i]])(bucket,record,rid,atoi((hf->schema[i])+1)+sizeof(long long),offset);

	write_bucket(bucket, bid, path);

	if (split==1){
		rehash(hf, i, index_file);
	}

	free(bucket);
	//free(buf);
}
Exemple #5
0
object *get_symbol(char *val , table* t)
{
  int hval = find_bucket(val);
  bucket *b = t->htable[hval];
  if (b == NULL) {
    return NULL;
  }

  while (b != NULL) {
    if (strcmp(val, b->sym->data.symbol.val) == 0) {
      return b->sym;
    }
    b = b->next;
  }
  return NULL;
}
Exemple #6
0
/* We just learnt about a node, not necessarily a new one. Confirm is 1 if
   the node sent a message, 2 if it sent us a reply. */
static struct node*
new_node(const unsigned char *id, const struct sockaddr *sa,
         int salen, int confirm){
    struct bucket *b = find_bucket(id, sa->sa_family);
    struct node *n;
    int mybucket, split;

    if(b == NULL){
        return NULL;
    }

    if(id_cmp(id, myid) == 0){
        return NULL;
    }

    if(is_martian(sa) || node_blacklisted(sa, salen)){
        return NULL;
    }

	mybucket = in_bucket(myid, b);

	if(confirm == 2){
		b->time = now.tv_sec;
	}

	n = b->nodes;
	while(n){
		if(id_cmp(n->id, id) == 0){
			if(confirm || n->time < now.tv_sec - 15 * 60){
				/* Known node.  Update stuff. */
				memcpy((struct sockaddr*)&n->ss, sa, salen);
				if(confirm){
					n->time = now.tv_sec
				}
				if(confirm >= 2){
					n->reply_time = now.tv_sec;
					n->pinged = 0;
					n->pinged_time = 0;
				}
			}
			return 0;
		}
		n = n->next;
	}
Exemple #7
0
static void
corpus_build_link(struct corpus *c)
{
  int i;
  for (i = 0; i < c->nr_values; i++) {
    struct element *elm = &c->elms[i];
    struct bucket *bkt = find_bucket(c, elm->val);
    if (!bkt) {
      continue;
    }
    if (bkt->first_idx < 0) {
      /* 最初の出現 */
      bkt->first_idx = c->elms[i].idx;
    } else {
      c->elms[bkt->last_idx].next_idx = c->elms[i].idx;
    }
    bkt->last_idx = c->elms[i].idx;
    c->elms[i].next_idx = -1;
  }
}
Exemple #8
0
uint8_t *embed_lookup(term_t bucket, term_t name, int *size)
{
	*size = 0;

	embed_buck_t *eb = find_bucket(bucket);
	if (eb == 0)
		return 0;
	
	embed_bin_t *ptr = embed_bins +eb->start_index;
	embed_bin_t *end = embed_bins +eb->end_index;
	while (ptr < end)
	{
		if (ptr->name == name)
		{
			*size = ptr->ends - ptr->starts;
			return ptr->starts;
		}
		ptr++;
	}
	return 0;
}
Exemple #9
0
void smtlib2_hashtable_set(smtlib2_hashtable *t, intptr_t key, intptr_t val)
{
    size_t i;
    uint32_t h;
    smtlib2_hashtable_bucket *b;
    if (load_factor(t) > 0.7) {
        rehash(t, smtlib2_vector_size(t->table_)+1);
    }
    h = t->hf_(key);
    i = h % smtlib2_vector_size(t->table_);
    b = find_bucket(t, key, i);
    if (b) {
        b->val_ = val;
    } else {
        b = (smtlib2_hashtable_bucket *)malloc(
            sizeof(smtlib2_hashtable_bucket));
        b->next_ = (smtlib2_hashtable_bucket *)smtlib2_vector_at(t->table_, i);
        b->key_ = key;
        b->val_ = val;
        smtlib2_vector_at(t->table_, i) = (intptr_t)b;
        ++t->size_;
    }
}
Exemple #10
0
void put_symbol(object * val, table* t)
{
  add_entry(find_bucket(val->data.symbol.val), val, t);
}