* ========== Copyright Header Begin ==========================================
* Hypervisor Software File: ashash.c
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* - Do no alter or remove copyright notices
* - Redistribution and use of this software in source and binary forms, with
* or without modification, are permitted provided that the following
* - Redistribution of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistribution in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of Sun Microsystems, Inc. or the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* This software is provided "AS IS," without a warranty of any kind.
* ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
* MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
* OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
* FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
* DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
* SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* You acknowledge that this software is not designed, licensed or
* intended for use in the design, construction, operation or maintenance of
* ========== Copyright Header End ============================================
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
#pragma ident "@(#)ashash.c 1.2 07/06/07 SMI"
static symbol_t
*sym_listp
, *sym_list_endp
;
#define INVALID_HASH_KEY ((uint64_t)-1)
#define HASH_SIZE_BITS 10
#define HASH_SIZE (1<<HASH_SIZE_BITS)
#define HASH_SIZE_MASK (HASH_SIZE -1)
static hash_bucket_t
*hashp
;
static symbol_t
*hash_find_key(int idx
, uint64_t key
, char *namep
);
static void hash_key(char *nampep
, uint64_t *keyp
, int *idxp
);
hashp
= calloc(HASH_SIZE
, sizeof (hash_bucket_t
));
fprintf(stderr
, "Failed allocating hash space : %s\n",
new_sym(sym_flags_t flags
, char *namep
, int offset
, int size
)
symp
= malloc(sizeof (symbol_t
));
fprintf(stderr
, "Failed allocating symbol space : %s\n",
namecopyp
= strdup(namep
);
fprintf(stderr
, "Failed allocating symbol space : %s\n",
symp
->name_key
= INVALID_HASH_KEY
;
symp
->nextp
= sym_list_endp
;
if (sym_list_endp
== NULL
)
* Returns false if failed to insert because
sym_hash_insert(symbol_t
*symp
)
hash_key(symp
->namep
, &key
, &idx
);
otherp
= hash_find_key(idx
, key
, symp
->namep
);
symp
->hash_nextp
= hashp
[idx
].firstp
;
hashp
[idx
].firstp
= symp
;
hash_key(namep
, &key
, &idx
);
return (hash_find_key(idx
, key
, namep
));
hash_find_key(int idx
, uint64_t key
, char *namep
)
for (p
= hashp
[idx
].firstp
; p
!= NULL
; p
= p
->hash_nextp
) {
if (p
->name_key
== key
&& strcmp(p
->namep
, namep
) == 0)
* can use any old hash ... this is not a particualrly good one,
hash_key(char *namep
, uint64_t *keyp
, int *idxp
)
for (sp
= namep
; (ch
= *sp
) != '\0'; sp
++) {
key
= (key
>> (64 - KEY_SHIFT
)) ^ (key
<< KEY_SHIFT
) ^ ch
;
*idxp
= key
& HASH_SIZE_MASK
;