Esempio n. 1
0
/* 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;
}
Esempio n. 2
0
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;
};
Esempio n. 3
0
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);
    }
}
Esempio n. 4
0
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;
}
Esempio n. 5
0
bool setfont(const char *name)
{
    font *f = fonts.access(name);
    if(!f) return false;
    curfont = f;
    return true;
}
Esempio n. 6
0
void delmenu(const char *name)
{
    if (!name) return;
    gmenu *m = menus.access(name);
    if (!m) return;
    else menureset(m);
}
Esempio n. 7
0
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;
        }
    }
}
Esempio n. 8
0
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();
    }
Esempio n. 9
0
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; }
Esempio n. 10
0
void newgui(char *name, char *contents)
{
    if(guis.access(name))
    {
        delete[] guis[name];
        guis[name] = newstring(contents);
    }
    else guis[newstring(name)] = newstring(contents);
};
Esempio n. 11
0
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);
}
Esempio n. 12
0
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;
}  
Esempio n. 13
0
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;
}
Esempio n. 14
0
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);
}
Esempio n. 15
0
 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;
 };
Esempio n. 16
0
bool setfont(const char *name)
{
    font *f = fonts.access(name);
    if(!f) return false;
    int v = -1;
    if(strcmp(name, "default")==0)
        v = 0;
    else if(strcmp(name, "serif")==0)
        v = 1;
    else if(strcmp(name, "mono")==0)
        v = 2;
    if(v!=-1) __fontsetting = v;
    curfont = f;
    return true;
}
Esempio n. 17
0
void board::clear()
// Clear the entire board and all conflict tables
{
    matrix<ValueType> grid = getMatrix();
    int rows = grid.rows();
    int cols = grid.cols();
    
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            setCell(i, j, 0);
        }
    }
    //clear conflicts hash table
    conflictsTable.clear();
    knownConflicts.clear();
}
Esempio n. 18
0
void addauth(char *name, char *flags, char *pubkey, char *email)
{
    string authname;
    if(filterstring(authname, name, true, true, true, true, 100)) name = authname;
    if(authusers.access(name))
    {
        conoutf("auth handle '%s' already exists, skipping (%s)", name, email);
        return;
    }
    name = newstring(name);
    authuser &u = authusers[name];
    u.name = name;
    u.flags = newstring(flags);
    u.pubkey = parsepubkey(pubkey);
    u.email = newstring(email);
}
Esempio n. 19
0
void showgui(char *name)
{
    int pos = guistack.find(name);
    if(pos<0)
    {
        if(!guis.access(name)) return;
        if(guistack.empty()) menupos = menuinfrontofplayer();
        guistack.add(newstring(name));
    }
    else
    {
        pos = guistack.length()-pos-1;
        loopi(pos) delete[] guistack.pop();
    };
    menutab = 1;
    menustart = lastmillis;
};
Esempio n. 20
0
void showmenu(const char *name, bool top)
{
    if(!name)
    {
        curmenu = NULL;
        return;
    }
    gmenu *m = menus.access(name);
    if(!m) return;
    if(!top && curmenu)
    {
        if(curmenu==m) return;
        loopv(menustack) if(menustack[i]==m) return;
        menustack.insert(0, m);
        return;
    }
    menuset(m);
}
Esempio n. 21
0
void newfont(char *name, char *tex, int *defaultw, int *defaulth, int *offsetx, int *offsety, int *offsetw, int *offseth)
{
    font *f = fonts.access(name);
    if(!f)
    {
        name = newstring(name);
        f = &fonts[name];
        f->name = name;
    }

    f->tex = textureload(tex);
    f->chars.setsize(0);
    f->defaultw = *defaultw;
    f->defaulth = *defaulth;
    f->offsetx = *offsetx;
    f->offsety = *offsety;
    f->offsetw = *offsetw;
    f->offseth = *offseth;

    fontdef = f;
}
Esempio n. 22
0
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;
}
Esempio n. 23
0
font *getfont(const char *name)
{
    return fonts.access(name);
}
Esempio n. 24
0
void menuselection(char *menu, int *line)
{
    if(!menu || !menus.access(menu)) return;
    gmenu &m = menus[menu];
    menuselect(&m, *line);
}
Esempio n. 25
0
void print(hashtable& mytable) {
	for(hashtable::iterator i=mytable.begin(); i!=mytable.end(); i++)
	{
		std::cout<< i->key << ","<<i->data <<std::endl;
	}
}
Esempio n. 26
0
void hashtable_insert (hashtable ht, void *key, void *value)
{
  hashtable_inserthash (ht, key, value, ht->hashfn (key));
}
Esempio n. 27
0
void preloadmodel(const char *name)
{
    if(mdllookup.access(name)) return;
    preloadmodels.add(newstring(name));
}
Esempio n. 28
0
int hashtable_haskey (hashtable ht, void *key, void **key_found)
{
  return hashtable_haskeyhash (ht, key, key_found, ht->hashfn (key));
}
Esempio n. 29
0
void ht_free_entry(hashtable ht, const void *keyval) {
  if(ht->free_keyval!= NULL)
    ht->free_keyval((void *)keyval);
}
Esempio n. 30
0
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;
    //****************//
}