本文整理汇总了C++中hash_map::comp方法的典型用法代码示例。如果您正苦于以下问题:C++ hash_map::comp方法的具体用法?C++ hash_map::comp怎么用?C++ hash_map::comp使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类hash_map
的用法示例。
在下文中一共展示了hash_map::comp方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Moca_AddToMap
/*
* Insert key in map
* Returns A pointer to the hash_entry corresponding to key
* Null in case of error
* status is set to:
* The position of hash_entry in case of success
* One of the following in case of errors:
* MOCA_HASHMAP_ALREADY_IN_MAP
* MOCA_HASHMAP_FULL
* MOCA_HASHMAP_ERROR
*/
hash_entry Moca_AddToMap(hash_map map, hash_entry e, int *status)
{
unsigned long h;
int ind=0;
unsigned int nextPos;
if(!map)
{
*status=MOCA_HASHMAP_ERROR;
return NULL;
}
if(map->nbentry==map->tableSize)
{
*status=MOCA_HASHMAP_FULL;
return NULL;
}
//Do the insertion
nextPos=Moca_FindNextAvailPosMap(map);
MOCA_DEBUG_PRINT("Moca inserting %p ind %d/%lu total %d\n",
e->key,nextPos,map->tableSize, map->nbentry);
if(nextPos >= map->tableSize)
{
*status=MOCA_HASHMAP_ERROR;
Moca_Panic("Moca hashmap BUG in AddToMap");
return NULL;
}
//Update the link
h=hash_ptr(e->key, map->hash_bits);
ind=map->hashs[h];
//TODO refactor here
if(ind<0)
{
memcpy(tableElt(map,nextPos),e,map->elt_size);
tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
map->hashs[h]=nextPos;
}
else
{
while(map->comp(tableElt(map,ind),e)!=0 &&
tableElt(map,ind)->next>=0)
ind=tableElt(map,ind)->next;
if(map->comp(tableElt(map,ind),e)==0)
{
MOCA_DEBUG_PRINT("Moca %p already in map %p\n", e->key, map);
*status=MOCA_HASHMAP_ALREADY_IN_MAP;
//This seems useless
tableElt(map,nextPos)->key=NULL;
return tableElt(map,ind);
}
MOCA_DEBUG_PRINT("Moca collision in map %p key %p\n", map, e->key);
//TODO: Use Memcpy
memcpy(tableElt(map,nextPos),e,map->elt_size);
tableElt(map,nextPos)->next=MOCA_HASHMAP_END;
tableElt(map,ind)->next=nextPos;
}
++map->nbentry;
MOCA_DEBUG_PRINT("Moca Inserted %p in map %p\n", e->key, map);
*status=nextPos;
return tableElt(map,nextPos);
}
示例2: Moca_RemoveFromMap
hash_entry Moca_RemoveFromMap(hash_map map,hash_entry e)
{
unsigned long h;
int ind, ind_prev=MOCA_HASHMAP_END;
if(!map)
return NULL;
MOCA_DEBUG_PRINT("Moca removing %p from %p\n", e->key, map);
h=hash_ptr(e->key, map->hash_bits);
ind=map->hashs[h];
while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
{
ind_prev=ind;
ind=tableElt(map,ind)->next;
}
MOCA_DEBUG_PRINT("Moca removing %p from %p ind %d prev %d\n", e->key, map,
ind, ind_prev);
//key wasn't in map
if(ind<0 )
return NULL;
//Remove from list
if(ind_prev>=0)
{
tableElt(map,ind_prev)->next=tableElt(map,ind)->next;
}
else
{
map->hashs[h]=tableElt(map,ind)->next;
}
tableElt(map,ind)->next=MOCA_HASHMAP_UNUSED;
--map->nbentry;
MOCA_DEBUG_PRINT("Moca removing %p from %p ind %d ok\n", e->key, map, ind);
return tableElt(map,ind);
}
示例3: Moca_PosInMap
/*
* Returns -1 if key is not in map
* the position of key in the map if it is present
*/
int Moca_PosInMap(hash_map map,hash_entry e)
{
unsigned long h;
int ind=0;
if(!map)
return -1;
h=hash_ptr(e->key, map->hash_bits);
ind=map->hashs[h];
while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
ind=tableElt(map,ind)->next;
return ind;
}
示例4: Moca_EntryFromKey
/*
* Return the hash entry corresponding to key,
* NULL if key is not in the map
*/
hash_entry Moca_EntryFromKey(hash_map map, hash_entry e)
{
unsigned long h;
int ind=0;
if(!map || !e)
return NULL;
h=hash_ptr(e->key, map->hash_bits);
ind=map->hashs[h];
while(ind>=0 && map->comp(tableElt(map,ind),e)!=0 )
ind=tableElt(map,ind)->next;
if(ind >=0)
return tableElt(map,ind);
return NULL;
}