本文整理汇总了C++中HASH函数的典型用法代码示例。如果您正苦于以下问题:C++ HASH函数的具体用法?C++ HASH怎么用?C++ HASH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了HASH函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hash_delete
/*******************************************************************
*
* Description: Delete a key in the hash table.
*
* Modified args: None
*
* Return value: 0 if deleted, negative if not found.
*
*******************************************************************/
int
hash_delete(HASH_TABLE *ptbl, char *key)
{
HASH_DATUM key_datum;
struct hash_table_datum *entry;
struct hash_table_datum *prev_entry = NULL;
int index;
key_datum.size = strlen(key) + 1;
key_datum.data = key;
index = HASH(&key_datum);
entry = ((struct hash_table_datum **)ptbl)[index];
while (entry != NULL && (key_datum.size != entry->key.size || (memcmp(key_datum.data, entry->key.data, key_datum.size) != 0)))
{
prev_entry = entry; /* Keep the previous entry, we need it when unlinking */
entry = entry->next;
}
if (entry != NULL)
{
/* Unlink the old entry, and free memory */
if (prev_entry != NULL)
{
prev_entry->next = entry->next;
}
else
{
/* Old entry was the first in the list */
((struct hash_table_datum **)ptbl)[index] = entry->next;
}
HASH_FREE(entry);
return 0;
}
return -1; /* Not found */
}
示例2: free
/* allocate the object, creating the object */
struct Data *data_alloc( void ) {
struct Data *data;
int index;
if ( (data = malloc( sizeof( struct Data ) )) != NULL ) {
data->count = 1;
if ( pthread_mutex_init( &data->lock, NULL ) != 0 ) {
free( data );
return NULL;
}
index = HASH( data );
pthread_mutex_lock( &tablelock );
data->next = table[ index ];
/* I think it should be = data; */
table[ index ] = data->next;
pthread_mutex_lock( &data->lock );
pthread_mutex_unlock( &tablelock );
data->number = -9999;
pthread_mutex_unlock( data->lock );
}
return data;
}
示例3: HTChannel_new
/*
** A channel is uniquely identified by a socket.
** Note that we don't create the input and output stream - they are
** created later.
**
** We only keep a hash on sockfd's as we don't have to look for channels
** for ANSI file descriptors.
*/
PUBLIC HTChannel * HTChannel_new (SOCKET sockfd, FILE * fp, BOOL active)
{
HTList * list = NULL;
HTChannel * ch = NULL;
int hash = sockfd < 0 ? 0 : HASH(sockfd);
HTTRACE(PROT_TRACE, "Channel..... Hash value is %d\n" _ hash);
if (!channels) {
if (!(channels = (HTList **) HT_CALLOC(HT_M_HASH_SIZE,sizeof(HTList*))))
HT_OUTOFMEM("HTChannel_new");
}
if (!channels[hash]) channels[hash] = HTList_new();
list = channels[hash];
if ((ch = (HTChannel *) HT_CALLOC(1, sizeof(HTChannel))) == NULL)
HT_OUTOFMEM("HTChannel_new");
ch->sockfd = sockfd;
ch->fp = fp;
ch->active = active;
ch->semaphore = 1;
ch->channelIStream.isa = &ChannelIStreamIsa;
ch->channelOStream.isa = &ChannelOStreamIsa;
ch->channelIStream.channel = ch;
ch->channelOStream.channel = ch;
HTList_addObject(list, (void *) ch);
#ifdef HT_MUX
/*
** Create a MUX channel and do a connect on this channel with a
** new session.
*/
{
HTProtocol * protocol = HTNet_protocol(net);
HTMuxChannel * muxch = HTMuxChannel_new(me);
net->session = HTMuxSession_connect(muxch, net, HTProtocol_id(protocol));
}
#endif /* HT_MUX */
HTTRACE(PROT_TRACE, "Channel..... Added %p to list %p\n" _ ch _ list);
return ch;
}
示例4: PREFIXED
/* Note that even the slow path doesn't lock. */
void * PREFIXED(slow_getspecific) (tsd * key, unsigned long qtid,
tse * volatile * cache_ptr) {
pthread_t self = pthread_self();
unsigned hash_val = HASH(self);
tse *entry = key -> hash[hash_val];
GC_ASSERT(qtid != INVALID_QTID);
while (entry != NULL && entry -> thread != self) {
entry = entry -> next;
}
if (entry == NULL) return NULL;
/* Set cache_entry. */
entry -> qtid = qtid;
/* It's safe to do this asynchronously. Either value */
/* is safe, though may produce spurious misses. */
/* We're replacing one qtid with another one for the */
/* same thread. */
*cache_ptr = entry;
/* Again this is safe since pointer assignments are */
/* presumed atomic, and either pointer is valid. */
return entry -> value;
}
示例5: HASH_UNCHECKED
// ------------------------------------------------------------------
size_t __checked_pointer_table::getSize(const void* address)
{
int index = HASH_UNCHECKED(address);
__node* node = uncheckedTable[index];
while((node != 0) && (node->address != address))
node = node->next;
if(node != 0)
return node->size;
index = HASH(address);
node = table[index];
while((node != 0) && (node->address != address))
node = node->next;
if(node != 0)
return node->size;
return (size_t)-1;
}
示例6: initialize
/*
- initialize - hand-craft a cache entry for startup, otherwise get ready
^ static struct sset *initialize(struct vars *, struct dfa *, chr *);
*/
static struct sset *
initialize(
struct vars *v, /* used only for debug flags */
struct dfa *d,
chr *start)
{
struct sset *ss;
int i;
/*
* Is previous one still there?
*/
if (d->nssused > 0 && (d->ssets[0].flags&STARTER)) {
ss = &d->ssets[0];
} else { /* no, must (re)build it */
ss = getvacant(v, d, start, start);
for (i = 0; i < d->wordsper; i++) {
ss->states[i] = 0;
}
BSET(ss->states, d->cnfa->pre);
ss->hash = HASH(ss->states, d->wordsper);
assert(d->cnfa->pre != d->cnfa->post);
ss->flags = STARTER|LOCKED|NOPROGRESS;
/*
* lastseen dealt with below
*/
}
for (i = 0; i < d->nssused; i++) {
d->ssets[i].lastseen = NULL;
}
ss->lastseen = start; /* maybe untrue, but harmless */
d->lastpost = NULL;
d->lastnopr = NULL;
return ss;
}
示例7: foo_alloc
struct foo *
foo_alloc(void) /* allocate the object */
{
struct foo *fp;
int idx;
if ((fp = malloc(sizeof(struct foo))) != NULL) {
fp->f_count = 1;
if (pthread_mutex_init(&fp->f_lock, NULL) != 0) {
free(fp);
return(NULL);
}
idx = HASH(fp);
pthread_mutex_lock(&hashlock);
fp->f_next = fh[idx];
fh[idx] = fp->f_next;
pthread_mutex_lock(&fp->f_lock);
pthread_mutex_unlock(&hashlock);
/* ... continue initialization ... */
pthread_mutex_unlock(&fp->f_lock);
}
return(fp);
}
示例8: fooRele
void fooRele(struct Foo *fp){
struct Foo *tfp;
int idx;
pthread_mutex_lock(&hashLock);
if(-- fp -> fCount == 0){
idx = HASH(fp -> fId);
tfp = fh[idx];
if(tfp == fp){
fh[idx] = fp -> fNext;
}else{
while(tfp -> fNext != fp){
tfp = tfp -> fNext;
}
tfp -> fNext = fp -> fNext;
}
pthread_mutex_unlock(&hashLock);
pthread_mutex_destroy(&fp -> fLock);
free(fp);
}else{
pthread_mutex_unlock(&hashLock);
}
}
示例9: __pspgl_hash_insert
void __pspgl_hash_insert (struct hashtable *h, unsigned long key, void *value)
{
unsigned long b = HASH(key);
struct hashentry *ent;
if (key <= h->maxkey) {
for (ent=h->buckets[b]; ent!=NULL; ent=ent->next) {
if (ent->key == key) {
ent->data = value;
return;
}
}
}
if ((ent = malloc(sizeof(*ent)))) {
ent->key = key;
ent->data = value;
ent->next = h->buckets[b];
h->buckets[b] = ent;
if (key > h->maxkey)
h->maxkey = key;
}
}
示例10: kvs_get
/*
* returned value is not dup-ed
*/
extern char *
kvs_get(char *key)
{
kvs_bucket_t *bucket;
char *val = NULL;
int i;
debug3("mpi/pmi2: in kvs_get, key=%s", key);
bucket = &kvs_hash[HASH(key)];
if (bucket->count > 0) {
for(i = 0; i < bucket->count; i ++) {
if (! xstrcmp(key, bucket->pairs[KEY_INDEX(i)])) {
val = bucket->pairs[VAL_INDEX(i)];
break;
}
}
}
debug3("mpi/pmi2: out kvs_get, val=%s", val);
return val;
}
示例11: hash_insert
int
hash_insert (
void *el,
hashtab *htab)
{
int i;
hashnode *hnode;
++htab->cardinal;
if (htab->cardinal > htab->size * 10)
{
restructure (htab);
}
hnode = new hashnode[sizeof (*hnode)];
if (hnode == NULL)
return 1;
i = HASH (htab, el);
hnode->next = htab->vec[i];
hnode->el = el;
htab->vec[i] = hnode;
return 0;
}
示例12: SearchStructure
//-----------------------------------------------------------------
//
// Function: SearchStructure
//
// Purpose: Searches the profiler data struture for the function
// name.
//
// Input: Profile - pointer to profiler data structure
// Symbol - pointer to name to search for
//
// Output: SProfileRecord - pointer to the entry that contains
// the name, Symbol, if found. Otherwise
// NULL is returned.
//
//------------------------------------------------------------------
SProfileRecord * SearchStructure (SProfile *Profile, UCHAR *Symbol)
{
unsigned long cHashNumber;
unsigned long iBucket;
SProfileRecord *pProfileRecord;
// Hash on the first + last letters of the symbol
cHashNumber = (unsigned long)Symbol[0] + (unsigned long)Symbol[strlen(Symbol)-1];
iBucket = HASH(cHashNumber);
// Search the bucket for the corresponding entry
pProfileRecord = Profile->Buckets[iBucket];
while (pProfileRecord != NULL)
{
if (!strcmp(pProfileRecord->Symbol, Symbol))
break;
else
pProfileRecord = pProfileRecord->pNext;
}
return (pProfileRecord);
}
示例13: pxdns_request_find
/**
* Find request by the id we used when relaying it and remove it from
* id hash and timeout list. Called from pxdns_pmgr_pump() when reply
* comes.
*/
static struct request *
pxdns_request_find(struct pxdns *pxdns, u16_t id)
{
struct request *req = NULL;
sys_mutex_lock(&pxdns->lock);
/* find request in the id->req hash */
for (req = pxdns->request_hash[HASH(id)]; req != NULL; req = req->next_hash) {
if (req->id == id) {
break;
}
}
if (req != NULL) {
pxdns_hash_del(pxdns, req);
pxdns_timeout_del(pxdns, req);
--pxdns->active_queries;
}
sys_mutex_unlock(&pxdns->lock);
return req;
}
示例14: free
struct Foo *fooAlloc(int id){
struct Foo *fp;
int idx;
if((fp = (Foo *)malloc(sizeof(struct Foo))) != NULL){
fp -> fCount = 1;
fp -> fId = id;
if(pthread_mutex_init(&fp -> fLock, NULL) != 0){
free(fp);
return NULL;
}
idx = HASH(id);
pthread_mutex_lock(&hashLock);
fp -> fNext = fh[idx];
fh[idx] = fp;
pthread_mutex_lock(&fp -> fLock);
pthread_mutex_unlock(&hashLock);
pthread_mutex_unlock(&fp -> fLock);
}
return fp;
}
示例15: update
///----------------------------------------------------------------------------//
///--------------------- UPDATE SECTION ---------------------------------------//
///----------------------------------------------------------------------------//
Scene::Enum update(float dt) override {
Entity animLogo = e(HASH("logo/logo_anim", 0xed78c546));
if (timeAccum > 0.8 + 0.05 + 0.25 + 0.05) {
RENDERING(animLogo)->show = false;
return Scene::Menu;
} else if (timeAccum > 0.8 + 0.05 + 0.25) {
RENDERING(animLogo)->texture = theRenderingSystem.loadTextureFile("soupe_logo2_365_331");
}
else if (timeAccum > 0.8 + 0.05) {
if (!soundPlayed) {
SOUND(animLogo)->sound = theSoundSystem.loadSoundFile("sounds/logo_blink.ogg");
soundPlayed = true;
}
RENDERING(animLogo)->texture = theRenderingSystem.loadTextureFile("soupe_logo3_365_331");
}
else if (timeAccum > 0.8) {
RENDERING(animLogo)->show = true;
}
timeAccum += dt;
return Scene::Logo;
}