示例#1
0
static void test_hash_string (void) {
  char s1[] = "hello";
  char s2[] = "hello";
  char s3[] = "world";

  assert (string_hash (s1) != string_hash (s3));
  assert (string_hash (s1) == string_hash (s2));
  }
示例#2
0
文件: utils.cpp 项目: szmurlor/fiver
//-----------------------------------------------------------------------------
dolfin::uint dolfin::hash(std::string signature)
{
  boost::hash<std::string> string_hash;
  std::size_t h = string_hash(signature);

  return h;
}
示例#3
0
		int cl_unlock_char(unsigned char *charname, unsigned char *realmname, unsigned int gsid)
		{
			t_charlockinfo	*pcl, *ptmp;
			unsigned int	hashval;

			if (!charname || !realmname) return -1;
			if (!clitbl_len || !gsqtbl) return 0;
			if (std::strlen((char*)charname) >= MAX_CHARNAME_LEN) return -1;

			hashval = string_hash((char*)charname) % clitbl_len;
			pcl = clitbl[hashval];
			ptmp = NULL;
			while (pcl)
			{
				if ((strcasecmp((char*)pcl->charname, (char*)charname) == 0) && (pcl->gsid == gsid)) {
					cl_delete_from_gsq_list(pcl);
					if (ptmp) ptmp->next = pcl->next;
					else clitbl[hashval] = pcl->next;
					xfree(pcl);
					return 0;
				}
				ptmp = pcl;
				pcl = pcl->next;
			}
			return 0;
		}
示例#4
0
void abstract_group::set(const char * slot_str, float val)
{
    size_t hashed_str = string_hash(slot_str);
    for(server_node_list::iterator it = child_nodes.begin();
        it != child_nodes.end(); ++it)
        it->set(slot_str, hashed_str, val);
}
示例#5
0
/* makes no error if it doesn't exist (make it return a bool?) */
void Hashtable::remove(const char * const key)
{
	const unsigned int hash = string_hash(key);
	const unsigned int partial_hash = hash & BUCKET_MASK;

	struct linked_list *ptr = buckets[partial_hash];
	struct linked_list *prev = NULL;
	while (ptr) {
		if (ptr->hash == hash &&
#if CASE_INSENSITIVE_HASHES
		    strcasecmp(ptr->key, key) == 0
#else
		    strcmp(ptr->key, key) == 0
#endif
		) {
			if (prev == NULL) {
				buckets[partial_hash] = ptr->next;
			} else {
				prev->next = ptr->next;
			}
			free(ptr->key);
			return;
		}
		prev = ptr;
		ptr = ptr->next;
	}
}
示例#6
0
hash_t obj_hash(obj_ptr obj)
{
    switch (TYPE(obj))
    {
    case TYPE_INT:
    case TYPE_BOOL:
        return (hash_t) INT(obj);

    case TYPE_SYMBOL:
        return string_hash_imp(SYMBOL(obj));
            
    case TYPE_STRING:
        return string_hash(&STRING(obj));

    case TYPE_CONS:
    {
        hash_t res = 0;

        for (;;)
        {
            if (NTYPEP(obj, TYPE_CONS))
            {
                res += obj_hash(obj);
                break;
            }

            res += obj_hash(CAR(obj));
            obj = CDR(obj);
        }

        return res;
    }

    case TYPE_VEC:
        return vec_hash(&obj->data.as_vec);

    /* These types shouldn't be keys anyway ... */
    case TYPE_FLOAT:
        assert(TYPE(obj) != TYPE_FLOAT);
        break;
    case TYPE_MAP:
        assert(TYPE(obj) != TYPE_MAP);
        break;
    case TYPE_CLOSURE:
        assert(TYPE(obj) != TYPE_CLOSURE);
        break;
    case TYPE_PRIMITIVE:
        assert(TYPE(obj) != TYPE_PRIMITIVE);
        break;
    case TYPE_ERROR:
        assert(TYPE(obj) != TYPE_ERROR);
        break;
    case TYPE_PORT:
        assert(TYPE(obj) != TYPE_PORT);
        break;
    }

    return 0;
}
示例#7
0
inline hash_t path_hash(const char* path, hash_t previous = 0)
{
#if defined(WIN32)
  return string_hash_nocase(path, previous);
#else // UNIX
  return string_hash(path, previous);
#endif
}
示例#8
0
unsigned int hashID( const int& pageid, const char* id )
{
	char szHash[256];
	sprintf_s(szHash, "%s-%d", id, pageid);
	boost::hash<std::string> string_hash;
	std::string hash(szHash);
	return string_hash(hash);
}
示例#9
0
文件: hash.c 项目: belluster/fabl-js
 // special case for parametric types
 hash_description3(Object tp,string nm,Object vl)
 {
        unsigned long hash;
		hash = 5863012 + (tp->hashkey);// 5863012 = hash('[d');		
		hash = ((hash << 5) + hash) + string_hash(nm);
		hash = ((hash << 5) + hash) + (vl->hashkey);
		hash = ((hash << 5) + hash) + 93;// 93 = ] ascii
		return hash;
 }
示例#10
0
int location_hash(location loc)
{
  int h;

  h = 0;
  h = loc->lineno;
  h = 33*h + 720 + loc->filepos;
  h = 33*h + 720 + string_hash(loc->filename);
  return h;
}
示例#11
0
static long stringlist_hash(const QStringList &l)
{
    long x = 0x345678L;
    long mult = 1000003L;
    int len = l.size();
    foreach (const QString &s, l) {
        --len;
        x = (x ^ string_hash(s)) * mult;
        mult += (long)(82520L + len + len);
    }
示例#12
0
文件: hash.c 项目: belluster/fabl-js
 hash_description2(Object tp,Object vl)
 {
        unsigned long hash,vlh;int vlk;
		hash = 5863012 + (tp->hashkey);// 5863012 = hash('[d');	
		vlk = vl->obkind;
		if ((vlk == nstring_kind)||(vlk == wstring_kind)) vlh = string_hash(vl);
		else vlh = vl->hashkey;
		hash = ((hash << 5) + hash) + vlh;
		hash = ((hash << 5) + hash) + 93;// 93 = ] ascii
		return hash;
 }
vector<int> CountMin::returnHashFunctionsOfString(std::string word){
	// First we hash the string to generate seeds for a random number generator
	boost::hash<std::string> string_hash;
	boost::mt19937 randGen(string_hash(word));
	boost::uniform_int<> numrange(0, NUM_BINS-1);
	boost::variate_generator< boost::mt19937&, boost::uniform_int<> > GetRand(randGen, numrange);
	vector<int> hashes;
	for(int i =0;i<NUM_HASH;i++){
		hashes.push_back(GetRand());
	}
	return hashes;
}
示例#14
0
	size_t hash() const {
		std::hash<int> int_hash;
		std::hash<std::string> string_hash;
		switch(state) {
			case State::Int:
				return int_hash(integerValue);
			case State::String:
				return string_hash(stringValue);
			default:
				throw std::exception();
		}
	};
示例#15
0
  size_t
hash(const Opnd opnd)
{
  if (is_reg(opnd)) {
    int reg = get_reg(opnd);
    if (is_virtual_reg(opnd))
      reg = -(reg + 1);
    return reg << 1;
  } else if (is_var(opnd)) {
    return (size_t)get_var(opnd) | 1;
  } else if (is_immed_integer(opnd)) {
    Integer i = get_immed_integer(opnd);
    if (i.is_c_string_int())
      return string_hash(i.chars());
    else
      return i.c_long();
  } else if (is_immed_string(opnd)) {
    return string_hash(get_immed_string(opnd).chars());
  }
  claim(false, "Operand kind %d isn't yet hashable", get_kind(opnd));
  return 0;
}
		bc_iservice* bc_service_manager::_get_service(const bcCHAR* p_service_name)
		{
			bc_iservice* l_result = nullptr;
			const auto l_service_hash = string_hash()(p_service_name);
			const auto l_ite = m_services.find(l_service_hash);

			if (l_ite != std::end(m_services))
			{
				l_result = l_ite->second.m_service.get();
			}

			return l_result;
		}
示例#17
0
void ProcessInformation::addProcess(const std::string &processName, const std::vector<std::string>& arguments /*= std::vector<std::string>()*/)
{
    ProcessInfo pinfo ;
    pinfo.m_name = processName ;
    pinfo.m_state = eNotRunning ;
    pinfo.m_args = arguments ;

    boost::hash<std::string> string_hash ;
    std::size_t id = string_hash(processName);
    if ( m_processes.find(id) != m_processes.end() )
        throw std::logic_error("Unable to add the same process twice");
    m_processes[id] = pinfo ;

}
示例#18
0
/**
 * This is a hash function for disjuncts
 */
static int hash_disjunct(disjunct_dup_table *dt, Disjunct * d)
{
	int i;
	Connector *e;
	i = 0;
	for (e = d->left ; e != NULL; e = e->next)
	{
		i = pconnector_hash(dt, e, i);
	}
	for (e = d->right ; e != NULL; e = e->next)
	{
		i = pconnector_hash(dt, e, i);
	}
	return string_hash(dt, d->string, i);
}
示例#19
0
long
sc_lookup_string(STRING_CACHE * sc,
	      char *string)
{
    long i, hash;

    hash = string_hash(sc, string) % sc->string_hash_size;
    i = sc->string_hash[hash];
    while(i >= 0)
	{
	    if(!strcmp(sc->string[i], string))
		return i;
	    i = sc->next_string[i];
	}
    return -1;
}
示例#20
0
void Hashtable::insert(const char * const key, void * const obj)
{
	const unsigned int hash = string_hash(key);
	const unsigned int partial_hash = hash & BUCKET_MASK;

	this->remove(key);
	
	/* insert in the beginning of the list */
	struct linked_list *ptr =
		(struct linked_list *)malloc(sizeof(struct linked_list));
	ptr->key = strdup(key);
	ptr->hash = hash;
	ptr->obj = obj;
	ptr->next = this->buckets[partial_hash];

	this->buckets[partial_hash] = ptr;
}
示例#21
0
文件: hash.c 项目: belluster/fabl-js
 // take into account the name, definedIn, the input types, but not result type
  hash_function(Smallob f)
 {
        unsigned long hash;int k,sqh;Type fnt;Seqob sq;
	    Arrayob cn;ob *dt;int ln,i,hk;ob v;Object dfi;
		hash = 5863012 + (FunctionT->hashkey);// 5863012 = hash('[d');		
		hash = ((hash << 5) + hash) + string_hash(functionName(f));	
		dfi = functionDefinedIn(f);
		hash = ((hash << 5) + hash) + (dfi->hashkey);		
		fnt = functionFunType(f);
		sq = (Seqob)typeParams(fnt);
		sqh = sq->hashkey;
		if (htverbose) printf("sq = %d sqh = %d\n",sq,sqh);
		if (!sqh) UM_ERROR("inputTypes of Function not interned");
		hash = ((hash << 5) + hash) + sqh;		
		hash = ((hash << 5) + hash) + 93;// 93 = ] ascii
		return hash;
 }
		bc_iservice* bc_service_manager::_register_service(const bcCHAR* p_service_name, bc_service_ptr<bc_iservice> p_service)
		{
			bcSIZE l_service_priority = m_services.size();

			const auto l_service_hash = string_hash()(p_service_name);
			auto l_ite = m_services.lower_bound(l_service_hash);
			if (l_ite == m_services.end() || m_services.key_comp()(l_service_hash, l_ite->first))
			{
				l_ite = m_services.emplace_hint(l_ite, l_service_hash, _bc_service_container(std::move(p_service), l_service_priority));
			}
			else
			{
				l_ite->second = _bc_service_container(std::move(p_service), l_service_priority);
			}

			return l_ite->second.m_service.get();
		}
 void TextEngineRenderer::MaybeRebuildAttenuationShader() {
   if (updater.GetCurrentState().selected_item) {
     std::set<textengine::Object *> objects, areas;
     for (auto &object : scene.objects) {
       objects.insert(object.get());
     }
     for (auto &area : scene.areas) {
       areas.insert(area.get());
     }
     const auto attenuation_shader_source = attenuation_template.AttenuationFragmentShaderSource(
         updater.GetCurrentState().selected_item, objects, areas);
     std::hash<std::string> string_hash;
     const auto source_hash = string_hash(attenuation_shader_source);
     if (source_hash != attenuation_fragment_shader_source_hash) {
       attenuation_vertex_shader.Create(GL_VERTEX_SHADER, {kAttenuationVertexShaderSource});
       
       attenuation_fragment_shader.Create(GL_FRAGMENT_SHADER, {attenuation_shader_source});
       attenuation_program.Create({&attenuation_vertex_shader, &attenuation_fragment_shader});
       attenuation_program.CompileAndLink();
       
       const auto attenuation3_shader_source = attenuation3_template.AttenuationFragmentShaderSource(
           updater.GetCurrentState().selected_item, objects, areas);
       
       attenuation3_fragment_shader.Create(GL_FRAGMENT_SHADER, {attenuation3_shader_source});
       attenuation3_program.Create({&attenuation_vertex_shader, &attenuation3_fragment_shader});
       attenuation3_program.CompileAndLink();
       
       attenuation.data.insert(attenuation.data.cend(), {
         1.0f, -1.0f,
         1.0f, 1.0f,
         -1.0f, -1.0f,
         -1.0f, 1.0f
       });
       attenuation.element_count = 4;
       attenuation.element_type = GL_TRIANGLE_STRIP;
       
       attenuation_buffer.Create(GL_ARRAY_BUFFER);
       attenuation_buffer.Data(attenuation.data_size(), attenuation.data.data(), GL_STATIC_DRAW);
       attenuation_array.Create();
       vertex_format.Apply(attenuation_array, attenuation_program);
       CHECK_STATE(!glGetError());
       attenuation_fragment_shader_source_hash = source_hash;
     }
   }
 }
示例#24
0
void ProcessInformation::startProcess(const std::string &processName)
{
    ProcessInfo pinfo ;
    boost::hash<std::string> string_hash ;
    std::size_t id = string_hash(processName);

    ProcessInfoList_t::iterator it = m_processes.find(id);
    if ( it == m_processes.end())
        throw std::runtime_error( " Unable to start process that is not in watchdog list");

    pinfo = it->second ;

    boost::process::context ctx ;
    ctx.stdout_behavior = boost::process::silence_stream() ;

    boost::process::child c = boost::process::launch(pinfo.m_name, pinfo.m_args, ctx ) ;


}
示例#25
0
文件: hash.c 项目: norandom/swish-e
struct swline * is_word_in_hash_table( WORD_HASH_TABLE table, char *word)
{
    unsigned hashval;
    struct swline *sp;

    if ( !table.hash_array )
        return 0;

    hashval = string_hash(word, table.hash_size);
    sp = table.hash_array[hashval];

    while (sp != NULL)
    {
        if (!strcmp(sp->line, word))
            return sp;
        sp = sp->next;
    }
    return NULL;
}
示例#26
0
void *Hashtable::lookup(const char * const key) const
{
	const unsigned int hash = string_hash(key);
	const unsigned int partial_hash = hash & BUCKET_MASK;
	
	struct linked_list *ptr = buckets[partial_hash];
	while (ptr) {
		if (ptr->hash == hash &&
#if CASE_INSENSITIVE_HASHES
		    strcasecmp(ptr->key, key) == 0
#else
		    strcmp(ptr->key, key) == 0
#endif
		) {
			return ptr->obj;
		}
		ptr = ptr->next;
	}
	return NULL;
}
示例#27
0
/*
  modify a sbuf return to ensure that inodes in the shadow directory
  are different from those in the main directory
 */
static void convert_sbuf(vfs_handle_struct *handle, const char *fname, SMB_STRUCT_STAT *sbuf)
{
	if (lp_parm_bool(SNUM(handle->conn), "shadow", "fixinodes", False)) {		
		/* some snapshot systems, like GPFS, return the name
		   device:inode for the snapshot files as the current
		   files. That breaks the 'restore' button in the shadow copy
		   GUI, as the client gets a sharing violation.

		   This is a crude way of allowing both files to be
		   open at once. It has a slight chance of inode
		   number collision, but I can't see a better approach
		   without significant VFS changes
		*/
		uint32_t shash = string_hash(fname) & 0xFF000000;
		if (shash == 0) {
			shash = 1;
		}
		sbuf->st_ex_ino ^= shash;
	}
}
示例#28
0
文件: hash.c 项目: norandom/swish-e
struct swline *add_word_to_hash_table( WORD_HASH_TABLE *table_ptr, char *word, int hash_size)
{
    struct swline **hash_array = table_ptr->hash_array;
    unsigned hashval;
    struct swline *sp;
    int len;

    /* Create the array if it doesn't exist */
    if ( !hash_array )
    {
        int ttl_bytes = sizeof(struct swline *) * (hash_size = (hash_size ? hash_size : HASHSIZE));
       
        table_ptr->mem_zone = (void *) Mem_ZoneCreate("Word Hash Zone", 0, 0); 
        //hash_array = (struct swline  **)emalloc( ttl_bytes );
        hash_array = (struct swline  **) Mem_ZoneAlloc( (MEM_ZONE *)table_ptr->mem_zone, ttl_bytes );
        memset( hash_array, 0, ttl_bytes );
        table_ptr->hash_array = hash_array;
        table_ptr->hash_size = hash_size;
        table_ptr->count = 0;
    }
    else
        if ( (sp = is_word_in_hash_table( *table_ptr, word )) )
            return sp;

    hashval = string_hash(word,hash_size);

    /* Create a new entry */            
    len = strlen(word);
    sp = (struct swline *) Mem_ZoneAlloc((MEM_ZONE *)table_ptr->mem_zone, sizeof(struct swline) + len);

    memcpy(sp->line,word,len + 1);

    /* Add word to head of list */
    
    sp->next = hash_array[hashval];
    hash_array[hashval] = sp;

    table_ptr->count++;

    return sp;
}
示例#29
0
文件: hash.c 项目: belluster/fabl-js
// for sequences of objects or strings
 hash_seqob(Seqob sq)
 {
        unsigned long hash;int k;
	    Arrayob cn;ob *dt;int ln,i,hk;ob v;
		hash = 5863027;// 5863027 = hash('[s');		
		cn = sq -> data;
		ln = cn -> length;
		dt = Arrayob_contents(cn);
		for (i=0;i<ln;i++)
		{
			v = *(dt++);
			k = v->obkind;
			if ((k == nstring_kind) || (k == wstring_kind)) hk = string_hash(v);
			else if (k < 16)  UM_ERROR("Expected object or string");
			else hk = ((Object)v)->hashkey;
			if (!hk) UM_ERROR("No hashkey");
		    hash = ((hash << 5) + hash) + hk;
		}
		hash = ((hash << 5) + hash) + 93;// 93 = ] ascii
		if (htverbose) printf("sq = %d rs = %d\n",sq,hash);
		return hash;
 }
示例#30
0
void
generate_sc_hash(STRING_CACHE * sc)
{
    long i;
    long hash;

    if(sc->string_hash != NULL)
		free(sc->string_hash);
    if(sc->next_string != NULL)
		free(sc->next_string);
    sc->string_hash_size = sc->size * 2 + 11;
    sc->string_hash = (long *)sc_do_alloc(sc->string_hash_size, sizeof(long));
    sc->next_string = (long *)sc_do_alloc(sc->size, sizeof(long));
    memset(sc->string_hash, 0xff, sc->string_hash_size * sizeof(long));
    memset(sc->next_string, 0xff, sc->size * sizeof(long));
    for(i = 0; i < sc->free; i++)
	{
	    hash = string_hash(sc, sc->string[i]) % sc->string_hash_size;
	    sc->next_string[i] = sc->string_hash[hash];
	    sc->string_hash[hash] = i;
	}
}