Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions
hash.c File Reference
#include "base.h"

Go to the source code of this file.

Classes

struct  nssHashStr
struct  arg_str

Functions

static PLHashNumber nss_identity_hash (const void *key)
static PLHashNumber nss_item_hash (const void *key)
static int nss_compare_items (const void *v1, const void *v2)
NSS_IMPLEMENT nssHash * nssHash_Create (NSSArena *arenaOpt, PRUint32 numBuckets, PLHashFunction keyHash, PLHashComparator keyCompare, PLHashComparator valueCompare)
NSS_IMPLEMENT nssHash * nssHash_CreatePointer (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_IMPLEMENT nssHash * nssHash_CreateString (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_IMPLEMENT nssHash * nssHash_CreateItem (NSSArena *arenaOpt, PRUint32 numBuckets)
NSS_IMPLEMENT void nssHash_Destroy (nssHash *hash)
NSS_IMPLEMENT PRStatus nssHash_Add (nssHash *hash, const void *key, const void *value)
NSS_IMPLEMENT void nssHash_Remove (nssHash *hash, const void *it)
NSS_IMPLEMENT PRUint32 nssHash_Count (nssHash *hash)
NSS_IMPLEMENT PRBool nssHash_Exists (nssHash *hash, const void *it)
NSS_IMPLEMENT voidnssHash_Lookup (nssHash *hash, const void *it)
static PRIntn nss_hash_enumerator (PLHashEntry *he, PRIntn index, void *arg)
NSS_IMPLEMENT void nssHash_Iterate (nssHash *hash, nssHashIterator fcn, void *closure)

Class Documentation

struct nssHashStr

Definition at line 68 of file hash.c.

Collaboration diagram for nssHashStr:
Class Members
NSSArena * arena
PRUint32 count
PRBool i_alloced_arena
PRLock * mutex
PLHashTable * plHashTable
struct arg_str

Definition at line 365 of file hash.c.

Collaboration diagram for arg_str:
Class Members
void * closure
nssCKFWHashIterator fcn
nssHashIterator fcn

Function Documentation

static int nss_compare_items ( const void v1,
const void v2 
) [static]

Definition at line 109 of file hash.c.

{
  PRStatus ignore;
  return (int)nssItem_Equal((NSSItem *)v1, (NSSItem *)v2, &ignore);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRIntn nss_hash_enumerator ( PLHashEntry he,
PRIntn  index,
void arg 
) [static]

Definition at line 372 of file hash.c.

{
  struct arg_str *as = (struct arg_str *)arg;
  as->fcn(he->key, he->value, as->closure);
  return HT_ENUMERATE_NEXT;
}

Here is the caller graph for this function:

static PLHashNumber nss_identity_hash ( const void key) [static]

Definition at line 84 of file hash.c.

{
  PRUint32 i = (PRUint32)key;
  PR_ASSERT(sizeof(PLHashNumber) == sizeof(PRUint32));
  return (PLHashNumber)i;
}

Here is the caller graph for this function:

static PLHashNumber nss_item_hash ( const void key) [static]

Definition at line 95 of file hash.c.

{
  unsigned int i;
  PLHashNumber h;
  NSSItem *it = (NSSItem *)key;
  h = 0;
  for (i=0; i<it->size; i++)
    h = (h >> 28) ^ (h << 4) ^ ((unsigned char *)it->data)[i];
  return h;
}

Here is the caller graph for this function:

NSS_IMPLEMENT PRStatus nssHash_Add ( nssHash *  hash,
const void key,
const void value 
)

Definition at line 246 of file hash.c.

{
  PRStatus error = PR_FAILURE;
  PLHashEntry *he;

  PZ_Lock(hash->mutex);
  
  he = PL_HashTableAdd(hash->plHashTable, key, (void *)value);
  if( (PLHashEntry *)NULL == he ) {
    nss_SetError(NSS_ERROR_NO_MEMORY);
  } else if (he->value != value) {
    nss_SetError(NSS_ERROR_HASH_COLLISION);
  } else {
    hash->count++;
    error = PR_SUCCESS;
  }

  (void)PZ_Unlock(hash->mutex);

  return error;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRUint32 nssHash_Count ( nssHash *  hash)

Definition at line 302 of file hash.c.

{
  PRUint32 count;

  PZ_Lock(hash->mutex);

  count = hash->count;

  (void)PZ_Unlock(hash->mutex);

  return count;
}

Here is the caller graph for this function:

NSS_IMPLEMENT nssHash* nssHash_Create ( NSSArena *  arenaOpt,
PRUint32  numBuckets,
PLHashFunction  keyHash,
PLHashComparator  keyCompare,
PLHashComparator  valueCompare 
)

Definition at line 121 of file hash.c.

{
  nssHash *rv;
  NSSArena *arena;
  PRBool i_alloced;

#ifdef NSSDEBUG
  if( arenaOpt && PR_SUCCESS != nssArena_verifyPointer(arenaOpt) ) {
    nss_SetError(NSS_ERROR_INVALID_POINTER);
    return (nssHash *)NULL;
  }
#endif /* NSSDEBUG */

  if (arenaOpt) {
    arena = arenaOpt;
    i_alloced = PR_FALSE;
  } else {
    arena = nssArena_Create();
    i_alloced = PR_TRUE;
  }

  rv = nss_ZNEW(arena, nssHash);
  if( (nssHash *)NULL == rv ) {
    goto loser;
  }

  rv->mutex = PZ_NewLock(nssILockOther);
  if( (PZLock *)NULL == rv->mutex ) {
    goto loser;
  }

  rv->plHashTable = PL_NewHashTable(numBuckets, 
                                    keyHash, keyCompare, valueCompare,
                                    &nssArenaHashAllocOps, arena);
  if( (PLHashTable *)NULL == rv->plHashTable ) {
    (void)PZ_DestroyLock(rv->mutex);
    goto loser;
  }

  rv->count = 0;
  rv->arena = arena;
  rv->i_alloced_arena = i_alloced;

  return rv;
loser:
  (void)nss_ZFreeIf(rv);
  return (nssHash *)NULL;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT nssHash* nssHash_CreateItem ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 212 of file hash.c.

{
  return nssHash_Create(arenaOpt, numBuckets, 
                        nss_item_hash, nss_compare_items, PL_CompareValues);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT nssHash* nssHash_CreatePointer ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 182 of file hash.c.

Here is the call graph for this function:

NSS_IMPLEMENT nssHash* nssHash_CreateString ( NSSArena *  arenaOpt,
PRUint32  numBuckets 
)

Definition at line 197 of file hash.c.

{
  return nssHash_Create(arenaOpt, numBuckets, 
                        PL_HashString, PL_CompareStrings, PL_CompareStrings);
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT void nssHash_Destroy ( nssHash *  hash)

Definition at line 227 of file hash.c.

{
  (void)PZ_DestroyLock(hash->mutex);
  PL_HashTableDestroy(hash->plHashTable);
  if (hash->i_alloced_arena) {
    nssArena_Destroy(hash->arena);
  } else {
    nss_ZFreeIf(hash);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT PRBool nssHash_Exists ( nssHash *  hash,
const void it 
)

Definition at line 323 of file hash.c.

{
  void *value;

  PZ_Lock(hash->mutex);

  value = PL_HashTableLookup(hash->plHashTable, it);

  (void)PZ_Unlock(hash->mutex);

  if( (void *)NULL == value ) {
    return PR_FALSE;
  } else {
    return PR_TRUE;
  }
}

Here is the call graph for this function:

NSS_IMPLEMENT void nssHash_Iterate ( nssHash *  hash,
nssHashIterator  fcn,
void closure 
)

Definition at line 390 of file hash.c.

{
  struct arg_str as;
  as.fcn = fcn;
  as.closure = closure;

  PZ_Lock(hash->mutex);

  PL_HashTableEnumerateEntries(hash->plHashTable, nss_hash_enumerator, &as);

  (void)PZ_Unlock(hash->mutex);

  return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT void* nssHash_Lookup ( nssHash *  hash,
const void it 
)

Definition at line 349 of file hash.c.

{
  void *rv;

  PZ_Lock(hash->mutex);

  rv = PL_HashTableLookup(hash->plHashTable, it);

  (void)PZ_Unlock(hash->mutex);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

NSS_IMPLEMENT void nssHash_Remove ( nssHash *  hash,
const void it 
)

Definition at line 278 of file hash.c.

{
  PRBool found;

  PZ_Lock(hash->mutex);

  found = PL_HashTableRemove(hash->plHashTable, it);
  if( found ) {
    hash->count--;
  }

  (void)PZ_Unlock(hash->mutex);
  return;
}

Here is the call graph for this function:

Here is the caller graph for this function: