Пример #1
0
static int register_user_by_sockaddr(struct sockaddr_storage *sa,
				     size_t sa_len,
				     struct curve25519_proto *proto)
{
	void **pos;
	struct sockaddr_map_entry *entry;
	unsigned int hash = hash_name((char *) sa, sa_len);

	rwlock_wr_lock(&sockaddr_map_lock);

	entry = xzmalloc(sizeof(*entry));
	entry->sa = xmemdupz(sa, sa_len);
	entry->sa_len = sa_len;
	entry->proto = proto;

	pos = insert_hash(hash, entry, &sockaddr_mapper);
	if (pos) {
		entry->next = (*pos);
		(*pos) = entry;
	}

	rwlock_unlock(&sockaddr_map_lock);

	return 0;
}
Пример #2
0
void remove_user_by_sockaddr(struct sockaddr_storage *sa, size_t sa_len)
{
	struct sockaddr_map_entry *pos;
	struct sockaddr_map_entry *entry;
	unsigned int hash = hash_name((char *) sa, sa_len);

	entry = sockaddr_to_sockaddr_map_entry(sa, sa_len);
	if (!entry)
		return;

	rwlock_wr_lock(&sockaddr_map_lock);

	pos = remove_hash(hash, entry, entry->next, &sockaddr_mapper);
	while (pos && pos->next && pos->next != entry)
		pos = pos->next;
	if (pos && pos->next && pos->next == entry)
		pos->next = entry->next;

	memset(entry->proto->enonce, 0, sizeof(entry->proto->enonce));
	memset(entry->proto->dnonce, 0, sizeof(entry->proto->dnonce));

	entry->proto = NULL;
	entry->next = NULL;

	xfree(entry->sa);
	xfree(entry);

	rwlock_unlock(&sockaddr_map_lock);
}
Пример #3
0
int get_user_by_sockaddr(struct sockaddr_storage *sa, size_t sa_len,
			 struct curve25519_proto **proto)
{
	int ret = -1;
	struct sockaddr_map_entry *entry;
	unsigned int hash = hash_name((char *) sa, sa_len);

	errno = 0;

	rwlock_rd_lock(&sockaddr_map_lock);

	entry = lookup_hash(hash, &sockaddr_mapper);
	while (entry && entry->sa_len == sa_len &&
	       memcmp(sa, entry->sa, entry->sa_len))
		entry = entry->next;
	if (entry && entry->sa_len == sa_len &&
	    !memcmp(sa, entry->sa, entry->sa_len)) {
		(*proto) = entry->proto;
		ret = 0;
	} else {
		(*proto) = NULL;
		errno = ENOENT;
	}

	rwlock_unlock(&sockaddr_map_lock);

	return ret;
}
Пример #4
0
qint64 RCCFileInfo::writeDataName(FILE *out, qint64 offset)
{
    //capture the offset
    nameOffset = offset;

    //write the length
    qt_rcc_write_number(out, name.length(), 2);
    fprintf(out, "\\\n");
    offset += 2;

    //write the hash
    qt_rcc_write_number(out, hash_name(name), 4);
    fprintf(out, "\\\n");
    offset += 4;

    //write the name
    const QChar *unicode = name.unicode();
    for (int i=0; i<name.length(); i++) {
        qt_rcc_write_number(out, unicode[i].unicode(), 2);
        if(!(i % 16))
            fprintf(out, "\\\n");
    }
    offset += name.length()*2;

    //done
    fprintf(out, "\\\n");
    return offset;
}
Пример #5
0
/*
 * The layout hash is used during the equivalency checking.  We have a node in
 * the child graph that may be equivalent to a node in the parent graph.  To
 * find the corresponding node (if any) in the parent, we need a quick way to
 * get to all nodes in the parent that look like the node in the child.  Since a
 * large number of nodes don't have names, we need to incorporate the layout of
 * the node into the hash.  If we don't, we'll end up with the vast majority of
 * nodes in bucket zero, with one or two nodes in each of the remaining buckets.
 *
 * There are a couple of constraints, both of which concern forward
 * declarations.  Recall that a forward declaration tdesc is equivalent to a
 * tdesc that actually defines the structure or union.  As such, we cannot
 * incorporate anything into the hash for a named struct or union node that
 * couldn't be found by looking at the forward, and vice versa.
 */
int
tdesc_layouthash(int nbuckets, void *node)
{
	tdesc_t *tdp = node;
	char *name = NULL;
	ulong_t h = 0;

	if (tdp->t_name)
		name = tdp->t_name;
	else {
		switch (tdp->t_type) {
		case POINTER:
		case TYPEDEF:
		case VOLATILE:
		case CONST:
		case RESTRICT:
			name = tdp->t_tdesc->t_name;
			break;
		case FUNCTION:
			h = tdp->t_fndef->fn_nargs +
			    tdp->t_fndef->fn_vargs;
			name = tdp->t_fndef->fn_ret->t_name;
			break;
		case ARRAY:
			h = tdp->t_ardef->ad_nelems;
			name = tdp->t_ardef->ad_contents->t_name;
			break;
		case STRUCT:
		case UNION:
			/*
			 * Unnamed structures, which cannot have forward
			 * declarations pointing to them.  We can therefore
			 * incorporate the name of the first member into
			 * the hash value, assuming there are any.
			 */
			if (tdp->t_members != NULL)
				name = tdp->t_members->ml_name;
			break;
		case ENUM:
			/* Use the first element in the hash value */
			name = tdp->t_emem->el_name;
			break;
		default:
			/*
			 * Intrinsics, forwards, and typedefs all have
			 * names.
			 */
			warning("Unexpected unnamed %d tdesc (ID %d)\n",
			    tdp->t_type, tdp->t_id);
		}
	}

	if (name)
		return (hash_name(nbuckets, name));

	return (h % nbuckets);
}
Пример #6
0
int
iidesc_hash(int nbuckets, void *arg)
{
	iidesc_t *ii = arg;
	int h = 0;

	if (ii->ii_name)
		return (hash_name(nbuckets, ii->ii_name));

	return (h);
}
Пример #7
0
int
DviCharIndex (DviCharNameMap *map, const char *name)
{
	int		i;
	DviCharNameHash	*h;

	i = hash_name (name) % DVI_HASH_SIZE;
	for (h = map->buckets[i]; h; h=h->next)
		if (!strcmp (h->name, name))
			return h->position;
	return -1;
}
Пример #8
0
//查找服务号,无此服务返回1,=echo() 
int get_srv_no(T_CLI_Var *clip,char *key)
{
register srvhs *cp;
svc_table *svcp;
	if(!clip || !clip->svc_tbl) return 1;
	svcp=clip->svc_tbl;
srvhs *colp=((srvhs *)(svcp->srv_hash));
	for(cp=colp+hash_name(key,svcp->srvn);
	   strcmp(cp->name,key); cp=colp+cp->link) {
		if(cp->link==-1) return 1;
	} 
	return ((srv_list *)svcp->srvlist)[cp->colno].srv_no;
}
Пример #9
0
//产生索引 
static char *mk_srv_hash(srv_list slist[],int coln)
{
int i,hashnum;
srvhs *colp;
int *lp;
char *p;
	colp=(srvhs *)malloc(coln * sizeof(srvhs));
	if(!colp) return NULL;

srvhs *top,stack[coln];

	top=stack;
	for(i=0;i<coln;i++) {
		colp[i].colno=-1;
		colp[i].link=-1;
	}
	for(i=0;i<coln;i++) {
		p=slist[i].srv_name;
	    	hashnum=hash_name(p,coln);
//ShowLog(5,"%s:name[%d]=%s,hashnum=%d\n",__FUNCTION__,i,p,hashnum);
	    if(colp[hashnum].colno==-1) {	//没有散列冲突 
		colp[hashnum].name=p;
		colp[hashnum].colno=i;
	    } else {				//有散列冲突,存储冲突链
		top->name=p;
		top->colno=i;
		top->link=hashnum;
		top++;
	    }
	}
	if(top != stack) { //有散列冲突,构建冲突链 
		for(i=0;i<coln;i++) {
			if(colp[i].colno != -1) continue;
			top--;
//找到索引表里的空项 
			colp[i].name=top->name;
			colp[i].colno=top->colno;
			for(lp=&colp[top->link].link;*lp != -1;lp=&colp[*lp].link)
				;
			*lp=i;
		}
	}

	return (char *)colp;
}
Пример #10
0
static void
compute_hash (DviCharNameMap *map)
{
	DviCharNameHash	**buckets;
	int		c, s, i;
	DviCharNameHash	*h;

	buckets = map->buckets;
	for (i = 0; i < DVI_HASH_SIZE; i++)
		buckets[i] = 0;
	for (c = 0; c < DVI_MAP_SIZE; c++)
		for (s = 0; s < DVI_MAX_SYNONYMS; s++) {
			if (!map->dvi_names[c][s])
				break;
			i = hash_name (map->dvi_names[c][s]) % DVI_HASH_SIZE;
			h = allocHash ();
			h->next = buckets[i];
			buckets[i] = h;
			h->name = map->dvi_names[c][s];
			h->position = c;
		}
	
}
Пример #11
0
static struct sockaddr_map_entry *
sockaddr_to_sockaddr_map_entry(struct sockaddr_storage *sa, size_t sa_len)
{
	struct sockaddr_map_entry *entry, *ret = NULL;
	unsigned int hash = hash_name((char *) sa, sa_len);

	errno = 0;

	rwlock_rd_lock(&sockaddr_map_lock);

	entry = lookup_hash(hash, &sockaddr_mapper);
	while (entry && entry->sa_len == sa_len &&
	       memcmp(sa, entry->sa, entry->sa_len))
		entry = entry->next;
	if (entry && entry->sa_len == sa_len &&
	    !memcmp(sa, entry->sa, entry->sa_len))
		ret = entry;
	else
		errno = ENOENT;

	rwlock_unlock(&sockaddr_map_lock);

	return ret;
}
Пример #12
0
static bool qt_rcc_compare_hash(const RCCFileInfo *left, const RCCFileInfo *right)
{
    return hash_name(left->name) < hash_name(right->name);
}
Пример #13
0
ERRORCODE FileListRecord::do_find_file(LPCSTR name, DB_RECORD_NUMBER far *lprecord, FILE_SEARCH_KEY *key)
{
#if 0
	od("Dump: ");
	for (int i = 0; i < m_file_array.count(); i++)
	{
		FILE_ARRAY_ELEMENT_PTR elem = m_file_array.get_file(i);
		od("(h:%x, r:%ld)", elem->hash, elem->record_number);
	}
	od("\r\n");
#endif
/*
// We want to perform a binary search on the array.
// The search key will be the hash value.
*/

	key->this_record = this;
	key->search_name = name;
	key->search_hash = hash_name(name);
	key->last_searched_element = NULL;

//	od("Look for file name '%s' (hash: %x)\r\n", name, key->search_hash);

	SHORT count;

	if ((count = m_file_array.count()) != 0)
	{
	/*
	// Get the first entry.
	// All entries in the array have the same selector.
	*/
		FILE_ARRAY_ELEMENT_PTR elem = m_file_array.get_file(0);

	/* Do the search. */

		void *ret = bsearch(key, elem, count,
								  sizeof(FILE_ARRAY_ELEMENT),
								  file_element_compare);

	/* Did we find it? */

		if (ret != NULL)
		{
			if (key->last_result != 0)
			{
			/* This is actually an error. */
				return (ERRORCODE)key->last_result;
			}

		/* Found it! */

			elem = (FILE_ARRAY_ELEMENT_PTR)ret;

		/* Update our time stamp. */

			elem->last_access = (DWORD)time(NULL);

			if (lprecord != NULL)
			{
				*lprecord = elem->record_number;
			}

			return ERRORCODE_None;
		}
	}

/* Not found. */

	return ERRORCODE_DoesNotExist;
}
Пример #14
0
inline SetId Approximator::lazy_find(const std::string& name, Target target,
                                     Parity parity, SetId arg0, SetId arg1) {
    auto i = m_binary_cache.find(CacheKey{hash_name(name), target, parity});
    POMAGMA_ASSERT1(i != m_binary_cache.end(), "programmer error");
    return i->second->try_find({arg0, arg1});
}
Пример #15
0
Approximator::Approximator(Structure& structure, DenseSetStore& sets,
                           WorkerPool& worker_pool)
    :  // structure
      m_structure(structure),
      m_item_dim(structure.carrier().item_dim()),
      m_top(structure.nullary_function("TOP").find()),
      m_bot(structure.nullary_function("BOT").find()),
      m_less(structure.binary_relation("LESS")),
      m_nless(structure.binary_relation("NLESS")),
      // dense set stores
      m_sets(sets),
      m_empty_set(sets.store(std::move(DenseSet(m_item_dim)))),
      m_known(1 + m_item_dim),
      m_unknown(),
      // lazy map caches
      m_disjoint_cache(worker_pool,
                       [this](const std::pair<SetId, SetId>& pair) {
          return m_sets.load(pair.first).disjoint(m_sets.load(pair.second))
                     ? Trool::TRUE
                     : Trool::FALSE;
      }),
      m_union_cache(worker_pool, [this](const std::vector<SetId>& sets) {
          const size_t count = sets.size();
          POMAGMA_ASSERT1(count >= 2, "too few sets: " << count);
          DenseSet val(m_item_dim);
          val.set_union(m_sets.load(sets[0]), m_sets.load(sets[1]));
          for (size_t i = 2; i < count; ++i) {
              val += m_sets.load(sets[i]);
          }
          return m_sets.store(std::move(val));
      }),
      m_nullary_cache(),
      m_binary_cache() {
    POMAGMA_ASSERT(m_top, "TOP is not defined");
    POMAGMA_ASSERT(m_bot, "BOT is not defined");

    POMAGMA_INFO("Inserting LESS and NLESS in DenseSetStore");
    for (auto iter = m_structure.carrier().iter(); iter.ok(); iter.next()) {
        const Ob ob = *iter;
        m_known[ob][ABOVE] = m_sets.store(m_less.get_Lx_set(ob));
        m_known[ob][BELOW] = m_sets.store(m_less.get_Rx_set(ob));
        m_known[ob][NABOVE] = m_sets.store(m_nless.get_Lx_set(ob));
        m_known[ob][NBELOW] = m_sets.store(m_nless.get_Rx_set(ob));
    }
    m_unknown[ABOVE] = m_known[m_top][ABOVE];
    m_unknown[BELOW] = m_known[m_bot][BELOW];
    m_unknown[NABOVE] = m_empty_set;
    m_unknown[NBELOW] = m_empty_set;

    POMAGMA_INFO("Initializing nullary_function cache");
    for (const auto& i : signature().nullary_functions()) {
        const std::string& name = i.first;
        Ob ob = i.second->find();
        Approximation approx = ob ? known(ob) : unknown();
        POMAGMA_INSERT(m_nullary_cache, name, approx);
    }

    POMAGMA_INFO("Initializing binary_function cache");
    for (const auto& i : signature().binary_functions()) {
        const auto& fun = *i.second;
        const uint64_t hash = hash_name(i.first);
        typedef SetPairToSetCache Cache;
        for (Parity p : {ABOVE, BELOW}) {
            POMAGMA_INSERT(
                m_binary_cache, CacheKey(hash, VAL, p),
                new Cache(worker_pool,
                          [this, &fun, p](const std::pair<SetId, SetId>& x) {
                    return function_lhs_rhs(fun, x.first, x.second, p);
                }));
        }
        for (Parity p : {NABOVE, NBELOW}) {
            POMAGMA_INSERT(
                m_binary_cache, CacheKey(hash, RHS, p),
                new Cache(worker_pool,
                          [this, &fun, p](const std::pair<SetId, SetId>& x) {
                    return function_lhs_val(fun, x.first, x.second, p);
                }));
            POMAGMA_INSERT(
                m_binary_cache, CacheKey(hash, LHS, p),
                new Cache(worker_pool,
                          [this, &fun, p](const std::pair<SetId, SetId>& x) {
                    return function_rhs_val(fun, x.first, x.second, p);
                }));
        }
    }

    POMAGMA_INFO("Initializing symmetric_function cache");
    for (const auto& i : signature().symmetric_functions()) {
        const auto& fun = *i.second;
        const uint64_t hash = hash_name(i.first);
        typedef SetPairToSetCache Cache;
        for (Parity p : {ABOVE, BELOW}) {
            POMAGMA_INSERT(
                m_binary_cache, CacheKey(hash, VAL, p),
                new Cache(worker_pool,
                          [this, &fun, p](const std::pair<SetId, SetId>& x) {
                    return function_lhs_rhs(fun, x.first, x.second, p);
                }));
        }
        for (Parity p : {NABOVE, NBELOW}) {
            auto* cache = new Cache(
                worker_pool, [this, &fun, p](const std::pair<SetId, SetId>& x) {
                    return function_lhs_val(fun, x.first, x.second, p);
                });
            POMAGMA_INSERT(m_binary_cache, CacheKey(hash, RHS, p), cache);
            POMAGMA_INSERT(m_binary_cache, CacheKey(hash, LHS, p), cache);
        }
    }
}