예제 #1
0
파일: value.c 프로젝트: jiribenes/scheme
uint32_t hash_value(value_t val) {
#if NANTAG
    if (IS_PTR(val)) {
        return hash_ptr(AS_PTR(val));
    } else {
        value_conv_t data;
        data.bits = val;
        return hash_number(data.bits);
    }
#else   // ! NANTAG
    switch (val.type) {
        case V_NIL:
            return 0;
        case V_TRUE:
            return 1;
        case V_FALSE:
            return 2;
        case V_UNDEFINED:
            return 3;
        case V_NUM:
            return hash_number(AS_NUM(val));
        case V_PTR:
            return hash_ptr(AS_PTR(val));
        default:
            return 0;
    }
#endif  // NANTAG
}
예제 #2
0
파일: callgraph.c 프로젝트: MatzeB/libfirm
/**
 * Pre-Walker called by compute_callgraph(), analyses all Call nodes.
 */
static void ana_Call(ir_node *n, void *env)
{
	(void)env;
	if (!is_Call(n))
		return;

	ir_graph *irg = get_irn_irg(n);
	for (size_t i = 0, n_callees = cg_get_call_n_callees(n); i < n_callees;
	     ++i) {
		ir_entity *callee_e = cg_get_call_callee(n, i);
		ir_graph  *callee   = get_entity_linktime_irg(callee_e);

		if (callee) {
			cg_callee_entry buf;
			buf.irg = callee;
			pset_insert((pset *)callee->callers, irg, hash_ptr(irg));
			cg_callee_entry *found = (cg_callee_entry*) pset_find((pset *)irg->callees, &buf, hash_ptr(callee));
			if (found) {  /* add Call node to list, compute new nesting. */
				ir_node **arr = found->call_list;
				ARR_APP1(ir_node *, arr, n);
				found->call_list = arr;
			} else { /* New node, add Call node and init nesting. */
				found = OALLOC(get_irg_obstack(irg), cg_callee_entry);
				found->irg = callee;
				found->call_list = NEW_ARR_F(ir_node *, 1);
				found->call_list[0] = n;
				found->max_depth = 0;
				pset_insert((pset *)irg->callees, found, hash_ptr(callee));
			}
			unsigned depth = get_loop_depth(get_irn_loop(get_nodes_block(n)));
			found->max_depth = MAX(found->max_depth, depth);
		}
	}
}
예제 #3
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_typeof_type(const typeof_type_t *type)
{
	unsigned result = hash_ptr(type->expression);
	result         ^= hash_ptr(type->typeof_type);

	return result;
}
예제 #4
0
/*
 * update_blk - update block info, rehash if pointers are different,
 * update location info if needed
 */
static void update_blk(void* p, void* np, size_t size, const char* file, int line)
{
  BlkHdr* bh;
  if (p != np) {
    BlkHdr* bh_prev = 0;
    unsigned long h = hash_ptr(p);

    /* 
     * remove the old entry from the hash table 
     */
    for (bh = bhTab[h]; bh; bh = bh->next) {
      if (p == bh->buf) {
        if (0 == bh_prev)
          bhTab[h] = bh->next;
        else
          bh_prev->next = bh->next;
        /* 
         * put it back in the hash table at hash(np) 
         */
        h = hash_ptr(np);
        bh->next = bhTab[h];
        bhTab[h] = bh;
        break;
      }
      bh_prev = bh;
    }
  }
  else
    bh = find_blk(p);
  /*
   * invalid ptr? 
   */
  assert(0 != bh);
  byteCount -= bh->size;
  byteCount += size;
  bh->buf = np;
  bh->size = size;
  /* 
   * update location info 
   */
  if (bh->location->file != file || bh->location->line != line) {
    if (--bh->location->count == 0)
      freeLocation(bh->location);
    if ((bh->location = findLocation(file, line)) == 0) {
      if ((bh->location = addLocation(file, line)) == 0)
        noMemFn();
    }
    assert(0 != bh->location);
    ++bh->location->count;
  }
}
예제 #5
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_function_type(const function_type_t *type)
{
	unsigned result = hash_ptr(type->return_type);

	function_parameter_t *parameter = type->parameters;
	while (parameter != NULL) {
		result   ^= hash_ptr(parameter->type);
		parameter = parameter->next;
	}
	result += type->modifiers;
	result += type->linkage;
	result += type->calling_convention;

	return result;
}
예제 #6
0
/*
 * free_blk - remove a block header and free it
 */
static void free_blk(const void* p)
{
  BlkHdr* bh_prev = 0;
  BlkHdr* bh;
  unsigned long h = hash_ptr(p);

  for (bh = bhTab[h]; bh; bh = bh->next) {
    if (p == bh->buf) {
      if (0 == bh_prev)
        bhTab[h] = bh->next;
      else
        bh_prev->next = bh->next;
      break;
    }
    bh_prev = bh;
  }
  /* 
   * if bh is NULL p was not allocated here 
   */
  assert(0 != bh);
  assert(bh->location->count > 0);
  if (--bh->location->count == 0)
    freeLocation(bh->location);

  byteCount -= bh->size;
  --blockCount;

  SHRED_MEM(bh, sizeof(BlkHdr));
  free(bh);
}
예제 #7
0
hash_entry Moca_RemoveFromMap(hash_map map,hash_entry e)
{
    unsigned long h;
    int ind, ind_prev=MOCA_HASHMAP_END;
    if(!map)
        return NULL;
    MOCA_DEBUG_PRINT("Moca removing %p from %p\n", e->key, map);
    h=hash_ptr(e->key, map->hash_bits);
    ind=map->hashs[h];
    while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
    {
        ind_prev=ind;
        ind=tableElt(map,ind)->next;
    }
    MOCA_DEBUG_PRINT("Moca removing %p from %p ind %d prev %d\n", e->key, map,
            ind, ind_prev);
    //key wasn't in map
    if(ind<0 )
        return NULL;
    //Remove from list
    if(ind_prev>=0)
    {
        tableElt(map,ind_prev)->next=tableElt(map,ind)->next;
    }
    else
    {
        map->hashs[h]=tableElt(map,ind)->next;
    }
    tableElt(map,ind)->next=MOCA_HASHMAP_UNUSED;
    --map->nbentry;
    MOCA_DEBUG_PRINT("Moca removing %p from %p ind %d ok\n", e->key, map, ind);
    return tableElt(map,ind);
}
예제 #8
0
int register_kprobe(struct kprobe *p)
{
	int ret = 0;
	unsigned long flags = 0;

	if ((ret = arch_prepare_kprobe(p)) != 0) {
		goto rm_kprobe;
	}
	spin_lock_irqsave(&kprobe_lock, flags);
	INIT_HLIST_NODE(&p->hlist);
	if (get_kprobe(p->addr)) {
		ret = -EEXIST;
		goto out;
	}
	arch_copy_kprobe(p);

	hlist_add_head(&p->hlist,
		       &kprobe_table[hash_ptr(p->addr, KPROBE_HASH_BITS)]);

	p->opcode = *p->addr;
	*p->addr = BREAKPOINT_INSTRUCTION;
	flush_icache_range((unsigned long) p->addr,
			   (unsigned long) p->addr + sizeof(kprobe_opcode_t));
out:
	spin_unlock_irqrestore(&kprobe_lock, flags);
rm_kprobe:
	if (ret == -EEXIST)
		arch_remove_kprobe(p);
	return ret;
}
예제 #9
0
/*
 * Insert key in map
 * Returns A pointer to the hash_entry corresponding to key
 *         Null in case of error
 * status is set to:
 *         The position of hash_entry in case of success
 *         One of the following in case of errors:
 *          MOCA_HASHMAP_ALREADY_IN_MAP
 *          MOCA_HASHMAP_FULL
 *          MOCA_HASHMAP_ERROR
 */
hash_entry Moca_AddToMap(hash_map map, hash_entry e, int *status)
{
    unsigned long h;
    int ind=0;
    unsigned int nextPos;
    if(!map)
    {
        *status=MOCA_HASHMAP_ERROR;
        return NULL;
    }
    if(map->nbentry==map->tableSize)
    {
        *status=MOCA_HASHMAP_FULL;
        return NULL;
    }
    //Do the insertion
    nextPos=Moca_FindNextAvailPosMap(map);
    MOCA_DEBUG_PRINT("Moca inserting %p ind %d/%lu total %d\n",
            e->key,nextPos,map->tableSize, map->nbentry);
    if(nextPos >= map->tableSize)
    {
        *status=MOCA_HASHMAP_ERROR;
        Moca_Panic("Moca hashmap BUG in AddToMap");
        return NULL;
    }
    //Update the link
    h=hash_ptr(e->key, map->hash_bits);
    ind=map->hashs[h];
    //TODO refactor here
    if(ind<0)
    {
        memcpy(tableElt(map,nextPos),e,map->elt_size);
        tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
        map->hashs[h]=nextPos;
    }
    else
    {
        while(map->comp(tableElt(map,ind),e)!=0 &&
                tableElt(map,ind)->next>=0)
            ind=tableElt(map,ind)->next;
        if(map->comp(tableElt(map,ind),e)==0)
        {
            MOCA_DEBUG_PRINT("Moca %p already in map %p\n", e->key, map);
            *status=MOCA_HASHMAP_ALREADY_IN_MAP;
            //This seems useless
            tableElt(map,nextPos)->key=NULL;
            return tableElt(map,ind);
        }
        MOCA_DEBUG_PRINT("Moca collision in map %p key %p\n", map, e->key);
        //TODO: Use Memcpy
        memcpy(tableElt(map,nextPos),e,map->elt_size);
        tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
        tableElt(map,ind)->next=nextPos;
    }
    ++map->nbentry;
    MOCA_DEBUG_PRINT("Moca Inserted %p in map %p\n", e->key, map);
    *status=nextPos;
    return tableElt(map,nextPos);
}
예제 #10
0
/*
 * find_blk - return the block struct associated with the
 * pointer p.
 */
static BlkHdr* find_blk(const void* p)
{
  BlkHdr* bh = bhTab[hash_ptr(p)];
  for ( ; bh; bh = bh->next) {
    if (p == bh->buf)
      return bh;
  }
  return find_blk_exhaustive(p);
}
예제 #11
0
static inline int svc_expkey_hash(struct svc_expkey *item)
{
	int hash = item->ek_fsidtype;
	char * cp = (char*)item->ek_fsid;
	int len = key_len(item->ek_fsidtype);

	hash ^= hash_mem(cp, len, EXPKEY_HASHBITS);
	hash ^= hash_ptr(item->ek_client, EXPKEY_HASHBITS);
	return hash & EXPKEY_HASHMASK;
}
예제 #12
0
/*
 * Returns -1 if key is not in map
 *         the position of key in the map if it is present
 */
int Moca_PosInMap(hash_map map,hash_entry e)
{
    unsigned long h;
    int ind=0;
    if(!map)
        return -1;
    h=hash_ptr(e->key, map->hash_bits);
    ind=map->hashs[h];
    while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
        ind=tableElt(map,ind)->next;
    return ind;
}
예제 #13
0
/*
* EMSA1 BSI Encode Operation
*/
SecureVector<byte> EMSA1_BSI::encoding_of(const MemoryRegion<byte>& msg,
                                          u32bit output_bits,
                                          RandomNumberGenerator&)
   {
   if(msg.size() != hash_ptr()->OUTPUT_LENGTH)
      throw Encoding_Error("EMSA1_BSI::encoding_of: Invalid size for input");

   if(8*msg.size() <= output_bits)
      return msg;

   throw Encoding_Error("EMSA1_BSI::encoding_of: max key input size exceeded");
   }
예제 #14
0
/* You have to be holding the kprobe_lock */
struct kprobe *get_kprobe(void *addr)
{
	struct hlist_head *head;
	struct hlist_node *node;

	head = &kprobe_table[hash_ptr(addr, KPROBE_HASH_BITS)];
	hlist_for_each(node, head) {
		struct kprobe *p = hlist_entry(node, struct kprobe, hlist);
		if (p->addr == addr)
			return p;
	}
	return NULL;
}
예제 #15
0
// Clear map, after this call, map is still usable
void Moca_ClearMap(hash_map map)
{
    unsigned int i;
    unsigned long h;
    if(!map)
        return;
    for(i=0;i<map->nbentry;++i)
    {
        h=hash_ptr(tableElt(map,i)->key, map->hash_bits);
        map->hashs[h]=MOCA_HASHMAP_END;
        tableElt(map,i)->next=MOCA_HASHMAP_UNUSED;
    }
}
예제 #16
0
/*
 * Return the hash entry corresponding to key,
 *        NULL if key is not in the map
 */
hash_entry Moca_EntryFromKey(hash_map map, hash_entry e)
{
    unsigned long h;
    int ind=0;
    if(!map || !e)
        return NULL;
    h=hash_ptr(e->key, map->hash_bits);
    ind=map->hashs[h];
    while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
        ind=tableElt(map,ind)->next;
    if(ind >=0)
        return tableElt(map,ind);
    return NULL;
}
예제 #17
0
/*! 2016-06-04 study -ing */
static unsigned int kernfs_name_hash(const char *name, const void *ns)
{
	unsigned long hash = init_name_hash();
	unsigned int len = strlen(name);
	while (len--)
		hash = partial_name_hash(*name++, hash);
	hash = (end_name_hash(hash) ^ hash_ptr((void *)ns, 31));
	hash &= 0x7fffffffU;
	/* Reserve hash numbers 0, 1 and INT_MAX for magic directory entries */
	if (hash < 2)
		hash += 2;
	if (hash >= INT_MAX)
		hash = INT_MAX - 1;
	return hash;
}
예제 #18
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_type(const type_t *type)
{
	unsigned hash = 0;

	switch (type->kind) {
	case TYPE_ERROR:
		return 0;
	case TYPE_IMAGINARY:
	case TYPE_COMPLEX:
	case TYPE_ATOMIC:
		hash = hash_atomic_type(&type->atomic);
		break;
	case TYPE_ENUM:
		hash = hash_enum_type(&type->enumt);
		break;
	case TYPE_COMPOUND_STRUCT:
	case TYPE_COMPOUND_UNION:
		hash = hash_compound_type(&type->compound);
		break;
	case TYPE_FUNCTION:
		hash = hash_function_type(&type->function);
		break;
	case TYPE_POINTER:
		hash = hash_pointer_type(&type->pointer);
		break;
	case TYPE_REFERENCE:
		hash = hash_reference_type(&type->reference);
		break;
	case TYPE_ARRAY:
		hash = hash_array_type(&type->array);
		break;
	case TYPE_TYPEDEF:
		hash = hash_ptr(type->typedeft.typedefe);
		break;
	case TYPE_TYPEOF:
		hash = hash_typeof_type(&type->typeoft);
		break;
	case TYPE_VOID:
	case TYPE_BUILTIN_TEMPLATE:
		break;
	}

	unsigned some_prime = 99991;
	hash ^= some_prime * type->base.qualifiers;

	return hash;
}
예제 #19
0
static void fq_rehash(struct fq_sched_data *q,
		      struct rb_root *old_array, u32 old_log,
		      struct rb_root *new_array, u32 new_log)
{
	struct rb_node *op, **np, *parent;
	struct rb_root *oroot, *nroot;
	struct fq_flow *of, *nf;
	int fcnt = 0;
	u32 idx;

	for (idx = 0; idx < (1U << old_log); idx++) {
		oroot = &old_array[idx];
		while ((op = rb_first(oroot)) != NULL) {
			rb_erase(op, oroot);
			of = rb_entry(op, struct fq_flow, fq_node);
			if (fq_gc_candidate(of)) {
				fcnt++;
				kmem_cache_free(fq_flow_cachep, of);
				continue;
			}
			nroot = &new_array[hash_ptr(of->sk, new_log)];

			np = &nroot->rb_node;
			parent = NULL;
			while (*np) {
				parent = *np;

				nf = rb_entry(parent, struct fq_flow, fq_node);
				BUG_ON(nf->sk == of->sk);

				if (nf->sk > of->sk)
					np = &parent->rb_right;
				else
					np = &parent->rb_left;
			}

			rb_link_node(&of->fq_node, parent, np);
			rb_insert_color(&of->fq_node, nroot);
		}
	}
	q->flows -= fcnt;
	q->inactive_flows -= fcnt;
	q->stat_gc_flows += fcnt;
}
예제 #20
0
/*
 * make_blk - create a block header and add it to the hash table
 */
static int make_blk(unsigned char* p, size_t size, Location* loc)
{
  BlkHdr* bh;

  assert(0 != p);
  assert(0 < size);
  assert(0 != loc);

  if ((bh = (BlkHdr*) malloc(sizeof(BlkHdr))) != 0) {
    unsigned long h = hash_ptr(p);
    bh->ref       = 0;
    bh->buf       = p;
    bh->size      = size;
    bh->location  = loc;
    bh->timestamp = time(0);
    bh->next      = bhTab[h];
    bhTab[h]      = bh;
    ++bh->location->count;
    byteCount += size;
    ++blockCount;
  }
  return (0 != bh);
}
예제 #21
0
파일: reach.c 프로젝트: DevL/ponyc
static size_t reachable_type_hash(reachable_type_t* t)
{
  return hash_ptr(t->name);
}
예제 #22
0
파일: reach.c 프로젝트: DevL/ponyc
static size_t reachable_method_name_hash(reachable_method_name_t* m)
{
  return hash_ptr(m->name);
}
예제 #23
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_array_type(const array_type_t *type)
{
	return hash_ptr(type->element_type);
}
예제 #24
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_compound_type(const compound_type_t *type)
{
	return hash_ptr(type->compound);
}
예제 #25
0
파일: codegen.c 프로젝트: dckc/ponyc
static uint64_t compile_local_hash(compile_local_t* p)
{
  return hash_ptr(p->name);
}
예제 #26
0
/**
 * Hash an element of type entry_t.
 *
 * @param entry  The element to be hashed.
 */
static unsigned hash_entry(const entry_t *entry)
{
	return hash_ptr(entry->q.ent) ^ hash_ptr(entry->q.tv) ^ (unsigned)(entry->q.pos * 9);
}
예제 #27
0
파일: paint.c 프로젝트: DevL/ponyc
// We keep our name records in a hash map
static size_t name_record_hash(name_record_t* p)
{
  return hash_ptr(p->name);
}
예제 #28
0
// Functions required for our hash table type.
static uint64_t flag_hash(flag_t* flag)
{
  assert(flag != NULL);
  return hash_ptr(flag->name);
}
예제 #29
0
파일: type_hash.c 프로젝트: oliwer/cparser
static unsigned hash_enum_type(const enum_type_t *type)
{
	return hash_ptr(type->enume);
}
예제 #30
0
unsigned ia32_hash_Immediate(const ir_node *irn)
{
	const ia32_immediate_attr_t *a = get_ia32_immediate_attr_const(irn);
	return hash_ptr(a->imm.entity) + (unsigned)a->imm.offset;
}