• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ hashtable类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中hashtable的典型用法代码示例。如果您正苦于以下问题:C++ hashtable类的具体用法?C++ hashtable怎么用?C++ hashtable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了hashtable类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ht_remove

/* does not free, regardless of the value of
   ht->free_keyval, invoked only when deleting. */
boolean ht_remove(hashtable ht, const void *key) {
  unsigned int hkey;
  hashentry *he, *prehe;
  assert(ht!=NULL);
  hkey = ht->hash(key);
  prehe = NULL;
  LOCK;
  he = ht->table[hkey%ht->table_size];
  while(he!=NULL) {
    if(he->hashkey == hkey && ht->isequal(he->keyval,key)) {
      if(prehe != NULL) {
        prehe->next = he->next;
      } else {
        ht->table[hkey%ht->table_size] = he->next;
      }
      UNLOCK;
      free(he);
      return TRUE;
    }
    prehe = he;
    he = he->next;
  }
  UNLOCK;
  return FALSE;
}
开发者ID:gcross,项目名称:QC-Talks,代码行数:27,代码来源:hashtable.c


示例2:

bool 
hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>::_M_equal(
						  const hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht1,
						  const hashtable<_Val,_Key,_HF,_ExK,_EqK,_All>& __ht2)
{
  //  typedef _Hashtable_node<_Val> _Node;
  if (__ht1.bucket_count() != __ht2.bucket_count())
    return false;
  for (size_t __n = 0; __n < __ht1.bucket_count(); ++__n) {
    const _Node* __cur1 = __ht1._M_get_bucket(__n);
    const _Node* __cur2 = __ht2._M_get_bucket(__n);
    for ( ; __cur1 && __cur2 && __cur1->_M_val == __cur2->_M_val;
          __cur1 = __cur1->_M_next, __cur2 = __cur2->_M_next)
      {}
    if (__cur1 || __cur2)
      return false;
  }
  return true;
}  
开发者ID:rickyharis39,项目名称:nolf2,代码行数:19,代码来源:_hashtable.c


示例3: ht_insert

void ht_insert(hashtable ht, const void *keyval) {
  hashentry *he;
  assert(ht!=NULL);
  he = malloc_ordie(sizeof(hashentry));
  he->hashkey = ht->hash(keyval);
  he->keyval = keyval;
  LOCK;
  he->next = ht->table[he->hashkey%ht->table_size];
  ht->table[he->hashkey%ht->table_size] = he;
  UNLOCK;
}
开发者ID:gcross,项目名称:QC-Talks,代码行数:11,代码来源:hashtable.c


示例4: find_entry

static
entry find_entry (hashtable ht, void *key, unsigned int hash, int remove)
{
  entry e;
  entry *prev;
  unsigned int index;

  index = INDEX_FOR (hash, ht->tablelength);
  for (prev = &(ht->table[index]); (e = *prev) ; prev = &e->next) {
    if (hash != e->hash) continue;
    if (key != e->key)
      if (!ht->eqfn (key, e->key, hash))
        continue;

    if (remove) {
      *prev = e->next;
      ht->entrycount--;
      free_entry (ht->pool, e);
    }

    return e;
  }
  return NULL;
}
开发者ID:DenielX,项目名称:psptools,代码行数:24,代码来源:hash.c


示例5: print

void print(hashtable& mytable) {
	for(hashtable::iterator i=mytable.begin(); i!=mytable.end(); i++)
	{
		std::cout<< i->key << ","<<i->data <<std::endl;
	}
}
开发者ID:flyfaster,项目名称:toysrc,代码行数:6,代码来源:hashtable.cpp


示例6: hashtable_insert

void hashtable_insert (hashtable ht, void *key, void *value)
{
  hashtable_inserthash (ht, key, value, ht->hashfn (key));
}
开发者ID:DenielX,项目名称:psptools,代码行数:4,代码来源:hash.c


示例7: hashtable_haskey

int hashtable_haskey (hashtable ht, void *key, void **key_found)
{
  return hashtable_haskeyhash (ht, key, key_found, ht->hashfn (key));
}
开发者ID:DenielX,项目名称:psptools,代码行数:4,代码来源:hash.c


示例8: ht_free_entry

void ht_free_entry(hashtable ht, const void *keyval) {
  if(ht->free_keyval!= NULL)
    ht->free_keyval((void *)keyval);
}
开发者ID:gcross,项目名称:QC-Talks,代码行数:4,代码来源:hashtable.c


示例9: fileio

void fileio()
{
    string filename;
    int n;
    
    cout << endl;
    cout << "Please enter the name of your file." << endl;
    cout << "User Entry: ";
    cin >> filename;
    
    cout << endl;
    cout << "Processing file..." << endl;
    
    //***start clock***//
    clock_t start, finish;
    double dur;
    start = clock();
    //*****************//
    
    ifstream filein;
    filein.open(filename);
    
    //grab n number of lines
    string nlines;
    getline(filein, nlines, ' ');
    n = atoi(nlines.c_str());
    
    //grab each line, process for words, and map to hashtable
    while (!filein.eof())
    {
        string line;
        getline(filein, line);
        
        stringstream stream(line);
        while (!stream.eof())
        {
            string word;
            getline(stream, word, ' ');
            
            //accounts for more than one white space by looking for first letter
            size_t letter = word.find_first_of("abcdefghijklmnopqrstuvwxyz");
            
            //create a sub-string to remove the extra spaces
            string substring =  word.substr(letter, word.npos);
            
            //hash the substring, then add its corresponding line to the table
            HashFunction H;
            int HashKey = H.Hash(substring);
            Table.add(HashKey, line);
        }
    }
    
    cout << "Processing Complete." << endl;
    
    //***stop clock***//
    finish = clock();
    dur = (double)(finish - start);
    dur /= CLOCKS_PER_SEC;
    cout << "Elapsed seconds: " << scientific << dur << endl;
    //****************//
}
开发者ID:sh0rtfuse,项目名称:CS104_DataStructures,代码行数:61,代码来源:Q6.cpp


示例10:

model *loadmodel(const char *name, int i)
{
    if(!name)
    {
        if(!mapmodels.inrange(i)) return NULL;
        mapmodelinfo &mmi = mapmodels[i];
        if(mmi.m) return mmi.m;
        name = mmi.name;
    };
    model **mm = mdllookup.access(name);
    model *m;
    if(mm) m = *mm;
    else
    { 
        m = new md2(name);
        loadingmodel = m;
        if(!m->load())
        {
            delete m;
            m = new md3(name);
            loadingmodel = m;
            if(!m->load())
            {    
                delete m;
                loadingmodel = NULL;
                return NULL; 
            };
        };
        loadingmodel = NULL;
        mdllookup.access(m->name(), &m);
    };
    if(mapmodels.inrange(i) && !mapmodels[i].m) mapmodels[i].m = m;
    return m;
};
开发者ID:acidbarrel,项目名称:Torment,代码行数:34,代码来源:rendermodel.cpp


示例11: destroyvbo

void destroyvbo(GLuint vbo)
{
    vboinfo *exists = vbos.access(vbo);
    if(!exists) return;
    vboinfo &vbi = *exists;
    if(vbi.uses <= 0) return;
    vbi.uses--;
    if(!vbi.uses)
    {
        glDeleteBuffers_(1, &vbo);
        if(vbi.data) delete[] vbi.data;
        vbos.remove(vbo);
    }
}
开发者ID:Infallible,项目名称:tess,代码行数:14,代码来源:octarender.cpp


示例12: newfont

void newfont(char *name, char *tex, int *defaultw, int *defaulth, int *offsetx, int *offsety, int *offsetw, int *offseth)
{
    if(*defaulth < 10) return;          // (becomes FONTH)
    Texture *_tex = textureload(tex);
    if(_tex == notexture || !_tex->xs || !_tex->ys) return;
    font *f = fonts.access(name);
    if(!f)
    {
        name = newstring(name);
        f = &fonts[name];
        f->name = name;
    }

    f->tex = _tex;
    f->chars.shrink(0);
    f->defaultw = *defaultw;
    f->defaulth = *defaulth;
    f->offsetx = *offsetx;
    f->offsety = *offsety;
    f->offsetw = *offsetw;
    f->offseth = *offseth;
    f->skip = 33;

    fontdef = f;
}
开发者ID:assaultcube,项目名称:AC,代码行数:25,代码来源:rendertext.cpp


示例13: setfont

bool setfont(const char *name)
{
    font *f = fonts.access(name);
    if(!f) return false;
    curfont = f;
    return true;
}
开发者ID:t7g,项目名称:intensityengine,代码行数:7,代码来源:rendertext.cpp


示例14: delmenu

void delmenu(const char *name)
{
    if (!name) return;
    gmenu *m = menus.access(name);
    if (!m) return;
    else menureset(m);
}
开发者ID:Fru5trum,项目名称:acr,代码行数:7,代码来源:menus.cpp


示例15: closemenu

void closemenu(const char *name)
{
    gmenu *m;
    if(!name)
    {
        if(curmenu) curmenu->close();
        while(!menustack.empty())
        {
            m = menustack.pop();
            if(m) m->close();
        }
        curmenu = NULL;
        return;
    }
    m = menus.access(name);
    if(!m) return;
    if(curmenu==m) menuset(menustack.empty() ? NULL : menustack.pop(), false);
    else loopv(menustack)
    {
        if(menustack[i]==m)
        {
            menustack.remove(i);
            return;
        }
    }
}
开发者ID:Fru5trum,项目名称:acr,代码行数:26,代码来源:menus.cpp


示例16: menu

void menu()
{
    int input = 0;
    
    do
    {
        cout << endl;
        cout << "Menu (Enter the number)" << endl;
        cout << "1. Search." << endl;
        cout << "2. Exit. " << endl;
        cout << "User Entry: ";
        cin >> input;
        cout << endl;
    }
    while ((input != 1) && (input != 2));
    
    if (input == 1)
    {
        string query;
        int num_of_results = 0;
        
        cout << "Enter your single-word query: ";
        cin >> query;
        
        //***start clock***//
        clock_t start, finish;
        double dur;
        start = clock();
        //*****************//
        
        //hash query
        HashFunction H;
        int HashKey = H.Hash(query);
        
        stack<string> result;
        result = Table.get2(HashKey);
        
        //print out results
        cout << "Result(s): " << endl;
        
        while (!result.empty())
        {
            cout << "   " << result.top() << endl;
            result.pop();
            num_of_results++;
        }
        
        cout << "********************" << endl;
        cout << num_of_results << " Results." << endl;
        
        //***stop clock***//
        finish = clock();
        dur = (double)(finish - start);
        dur /= CLOCKS_PER_SEC;
        cout << "Search Time: " << scientific << dur << endl;
        //****************//
        
        menu();
    }
开发者ID:sh0rtfuse,项目名称:CS104_DataStructures,代码行数:59,代码来源:Q6.cpp


示例17: findnormal

void findnormal(const vec &key, const vec &surface, vec &v)
{
    const nval *val = normalgroups.access(key);
    if(!val) { v = surface; return; }

    v = vec(0, 0, 0);
    int total = 0;
    if(surface.x >= lerpthreshold) { int n = (val->flat>>4)&0xF; v.x += n; total += n; }
开发者ID:christianleger,项目名称:OF-Engine,代码行数:8,代码来源:normal.cpp


示例18: newgui

void newgui(char *name, char *contents)
{
    if(guis.access(name))
    {
        delete[] guis[name];
        guis[name] = newstring(contents);
    }
    else guis[newstring(name)] = newstring(contents);
};
开发者ID:acidbarrel,项目名称:Torment,代码行数:9,代码来源:menus.cpp


示例19: malloc

KHMEXP void
perf_set_thread_desc(const char * file, int line,
                     const wchar_t * name, const wchar_t * creator) {
    thread_info * t;
    char * fn_copy;

    perf_once();

    t = malloc(sizeof(*t));
    ZeroMemory(t, sizeof(*t));

#ifdef _WIN32
    t->thread = GetCurrentThreadId();
#else
#error Unsupported platform
#endif

    StringCbCopy(t->name, sizeof(t->name), name);
    if (creator)
        StringCbCopy(t->creator, sizeof(t->creator), creator);

    if (file[0] == '.' && file[1] == '\\')
        file += 2;

    EnterCriticalSection(&cs_alloc);

    fn_copy = hash_lookup(&fn_hash, file);
    if (fn_copy == NULL) {
        size_t cblen = 0;
        if (FAILED(StringCbLengthA(file, MAX_PATH * sizeof(char),
                                   &cblen)))
            fn_copy = NULL;
        else {
            fn_copy = malloc(cblen + sizeof(char));
            if (fn_copy) {
                hash_bin * b;
                int hv;

                StringCbCopyA(fn_copy, cblen + sizeof(char), file);

                hv = fn_hash.hash(fn_copy) % fn_hash.n;

                b = malloc(sizeof(*b));
                b->data = fn_copy;
                b->key = fn_copy;
                LINIT(b);
                LPUSH(&fn_hash.bins[hv], b);
            }
        }
    }

    t->file = fn_copy;
    t->line = line;

    LPUSH(&threads, t);
    LeaveCriticalSection(&cs_alloc);
}
开发者ID:aosm,项目名称:Kerberos,代码行数:57,代码来源:perfstat.c


示例20: chmenumdl

void chmenumdl(char *menu, char *mdl, char *anim, int *rotspeed, int *scale)
{
    if(!menu || !menus.access(menu)) return;
    gmenu &m = menus[menu];
    DELETEA(m.mdl);
    if(!mdl ||!*mdl) return;
    m.mdl = newstring(mdl);
    m.anim = findanim(anim)|ANIM_LOOP;
    m.rotspeed = clamp(*rotspeed, 0, 100);
    m.scale = clamp(*scale, 0, 100);
}
开发者ID:Fru5trum,项目名称:acr,代码行数:11,代码来源:menus.cpp



注:本文中的hashtable类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ hdMouseEvent类代码示例发布时间:2022-05-31
下一篇:
C++ hashset类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap