当前位置: 首页>>代码示例>>C++>>正文


C++ hashtable类代码示例

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


在下文中一共展示了hashtable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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:

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

示例5: 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

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: 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

示例15: gui

 void gui(g3d_gui &g, bool firstpass)
 {
     if(guistack.empty()) return;
     char *name = guistack.last();
     char **contents = guis.access(name);
     if(!contents) return;
     cgui = &g;
     cgui->start(menustart, 0.03f, &menutab);
     guitab(name);
     execute(*contents);
     cgui->end();
     cgui = NULL;
 };
开发者ID:acidbarrel,项目名称:Torment,代码行数:13,代码来源:menus.cpp


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