本文整理汇总了C++中HashTable::calcIndx方法的典型用法代码示例。如果您正苦于以下问题:C++ HashTable::calcIndx方法的具体用法?C++ HashTable::calcIndx怎么用?C++ HashTable::calcIndx使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HashTable
的用法示例。
在下文中一共展示了HashTable::calcIndx方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HashDelete
int HashDelete(HashTable ht, void *data)
/* Removes the record containing 'data' from ht. If no such record exists,
hashDelete returns 0. On success it returns 1. DOES NOT DESTROY DATA */
{
int retval=0;
HashInfoPtr tmp;
unsigned int hashval = ht->calcIndx(data)%ht->size;
ErrPushFunc("HashDelete");
if(ht->infoArray[hashval]!=NULL) {
if(!(ht->compData(ht->infoArray[hashval]->data, data))) {
HashInfoPtr toTrash; /*First record matched -- remove it! */
toTrash=ht->infoArray[hashval];
ht->infoArray[hashval]=toTrash->next;
#if defined (_POSIX_SEMAPHORES) && defined (_POSIX_THREADS)
{
int error = sem_destroy(&(toTrash->cursorListSemaphore));
if (error != 0)
perror("hash.c HashDelete sem_destroy");
}
#endif
free(toTrash);
ht->elementCount--;
assert( ht->elementCount >= 0 );
retval=1;
}
else {
for( tmp = ht->infoArray[hashval]; /* Continue search for match */
(tmp->next!=NULL) && (ht->compData(tmp->next->data, data));
tmp = tmp->next)
;
if(tmp->next!=NULL) { /* If found, remove the matching record. */
HashInfoPtr toTrash;
toTrash = tmp->next;
tmp->next = toTrash->next;
#if defined (_POSIX_SEMAPHORES) && defined (_POSIX_THREADS)
{
int error = sem_destroy(&(toTrash->cursorListSemaphore));
if (error != 0)
perror("hash.c HashDelete sem_destroy");
}
#endif
free(toTrash);
ht->elementCount--;
assert( ht->elementCount >= 0 );
retval=1;
}
}
}
ErrPopFunc();
return(retval);
}
示例2: HashAdd
int HashAdd(HashTable ht, void *data)
/* Adds data to the specified hashtable. If an equivalent record (according to
ht->compData() ) exists, no adding is done. Returns 1 on success, 0 on
failure. */
{
int retval = 1;
unsigned int hashval = ht->calcIndx(data)%ht->size;
HashInfoPtr newInfo;
ErrPushFunc("HashAdd");
if(FindInfo(ht, data, hashval))
retval=0;
else {
if( (newInfo = (HashInfoPtr)malloc(sizeof(struct HiPtr))) != NULL ) {
int error;
newInfo->data = data;
newInfo->next = ht->infoArray[hashval];
newInfo->firstCursor = NULL;
#if defined (_POSIX_SEMAPHORES) && defined (_POSIX_THREADS)
error = sem_init( &(newInfo->cursorListSemaphore), 0, 1 );
if (error != 0) {
retval = 0;
goto ERR_RETURN;
}
#endif
/* I believe this is an atomic action and therefore needs not be
protected by a semaphore to be thread-safe.
Can this be guaranteed? What does the pthreads package say about
atomicity? Anyway, the elementCount needs to be semaphored methinks.
/Erl 981015
*/
ht->infoArray[hashval] = newInfo;
ht->elementCount++;
}
else {
retval = 0;
goto ERR_RETURN;
}
}
ERR_RETURN:
ErrPopFunc();
return(retval);
}
示例3: HashDestroy
int HashDestroy(HashTable ht, void *data)
/* Removes the record containing 'data' from ht and DESTROYS data.
If no such record exists, it returns 0. On success 1 is returned. */
{
int retval=0;
HashInfoPtr tmp;
unsigned int hashval = ht->calcIndx(data)%ht->size;
ErrPushFunc("HashDestroy");
if(ht->infoArray[hashval]!=NULL) {
if(!(ht->compData(ht->infoArray[hashval]->data, data))) {
HashInfoPtr toTrash; /*First record matched -- remove it! */
toTrash=ht->infoArray[hashval];
ht->infoArray[hashval]=toTrash->next;
DestroyInfo(ht, toTrash);
ht->elementCount--;
assert( ht->elementCount >= 0 );
retval=1;
}
else {
for( tmp = ht->infoArray[hashval]; /* Continue search for match */
(tmp->next!=NULL) && (ht->compData(tmp->next->data, data));
tmp = tmp->next )
;
if(tmp->next!=NULL) { /* If found, remove the matching record. */
HashInfoPtr toTrash;
toTrash = tmp->next;
tmp->next = toTrash->next;
DestroyInfo(ht, toTrash);
ht->elementCount--;
assert( ht->elementCount >= 0 );
retval=1;
}
}
}
ErrPopFunc();
return(retval);
}