Leopold Toetsch <[EMAIL PROTECTED]> writes: [...]
> > void * hash_get(Interp * interpreter, HASH *hash, void *key); > > HASHBUCKET * hash_get_bucket(Interp * interpreter, HASH *hash, void *key); > > That's ok for me. For all of the "normal" Hash usage, we don't have NULL > values, so there is no ambuigity for the return value. Attached patch implements this. Furthermore it implement hash_exists. It does not break more tests than previously. Is this ok to commit? bö
Index: classes/perlhash.pmc =================================================================== RCS file: /cvs/public/parrot/classes/perlhash.pmc,v retrieving revision 1.57 diff -u -r1.57 perlhash.pmc --- classes/perlhash.pmc 4 Nov 2003 18:33:04 -0000 1.57 +++ classes/perlhash.pmc 7 Nov 2003 15:09:43 -0000 @@ -1,4 +1,4 @@ - /* perlhash.pmc +/* perlhash.pmc * Copyright: 2001-2003 The Perl Foundation. All Rights Reserved. * CVS Info * $Id: perlhash.pmc,v 1.57 2003/11/04 18:33:04 leo Exp $ @@ -55,7 +55,8 @@ PMC* valpmc; PMC* nextkey; STRING* keystr = make_hash_key(INTERP, key); - HASHBUCKET* b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + HASHBUCKET* b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), + keystr); if (b == NULL) { return enum_hash_undef; } @@ -79,7 +80,8 @@ INTVAL get_integer_keyed (PMC* key) { PMC* valpmc; STRING* keystr = make_hash_key(INTERP, key); - HASHBUCKET *b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + HASHBUCKET *b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), + keystr); PMC* nextkey; if (b == NULL) { /* XXX Warning: use of uninitialized value */ @@ -96,7 +98,8 @@ FLOATVAL get_number_keyed (PMC* key) { PMC* valpmc; STRING* keystr = make_hash_key(INTERP, key); - HASHBUCKET *b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + HASHBUCKET *b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), + keystr); PMC* nextkey; if (b == NULL) { /* XXX Warning: Use of uninitialized value */ @@ -112,7 +115,8 @@ BIGNUM* get_bignum_keyed (PMC* key) { PMC* valpmc; STRING* keystr = make_hash_key(INTERP, key); - HASHBUCKET *b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + HASHBUCKET *b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), + keystr); PMC* nextkey; if (b == NULL) { /* XXX Warning: Use of uninitialized value */ @@ -142,7 +146,7 @@ default: keystr = make_hash_key(INTERP, key); } - b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); if (b == NULL) { /* XXX Warning: use of uninitialized value */ return VTABLE_get_string(INTERP, undef); @@ -164,7 +168,8 @@ PMC* get_pmc_keyed (PMC* key) { STRING* keystr = make_hash_key(INTERP, key); - HASHBUCKET *b = hash_get(INTERP, (HASH*) PMC_ptr1v(SELF), keystr); + HASHBUCKET *b = hash_get_bucket(INTERP, (HASH*) PMC_ptr1v(SELF), + keystr); PMC* nextkey; if (b == NULL) { PMC *new_undef = pmc_new(INTERP, enum_class_PerlUndef); @@ -223,7 +228,7 @@ HASHBUCKET *b; sx = key_string(INTERP, key); key = key_next(INTERP, key); - b = hash_get(INTERP, h, sx); + b = hash_get_bucket(INTERP, h, sx); if (b == NULL) return 0; /* no such key */ if (key == NULL) @@ -237,7 +242,7 @@ HASHBUCKET *b; sx = key_string(INTERP, key); key = key_next(INTERP, key); - b = hash_get(INTERP, h, sx); + b = hash_get_bucket(INTERP, h, sx); if (b == NULL) return 0; /* no such key */ if (key == NULL) @@ -252,7 +257,7 @@ HASHBUCKET *b; sx = key_string(INTERP, key); key = key_next(INTERP, key); - b = hash_get(INTERP, h, sx); + b = hash_get_bucket(INTERP, h, sx); if (b == NULL) return; /* no such key */ else if (key == NULL) Index: include/parrot/hash.h =================================================================== RCS file: /cvs/public/parrot/include/parrot/hash.h,v retrieving revision 1.17 diff -u -r1.17 hash.h --- include/parrot/hash.h 4 Nov 2003 18:33:08 -0000 1.17 +++ include/parrot/hash.h 7 Nov 2003 15:09:44 -0000 @@ -72,7 +72,9 @@ INTVAL hash_size(Interp * interpreter, HASH *hash); void hash_set_size(Interp * interpreter, HASH *hash, UINTVAL size); void hash_destroy(Interp * interpreter, HASH *hash); -HASHBUCKET *hash_get(Interp * interpreter, HASH *hash, void *key); +HASHBUCKET *hash_get_bucket(Interp * interpreter, HASH *hash, void *key); +void *hash_get(Interp * interpreter, HASH *hash, void *key); +INTVAL hash_exists(Interp * interpreter, HASH *hash, void *key); void hash_put(Interp * interpreter, HASH *hash, void *key, void *value); void hash_delete(Interp * interpreter, HASH *hash, void *key); void mark_hash(Interp * interpreter, HASH *hash); Index: src/hash.c =================================================================== RCS file: /cvs/public/parrot/src/hash.c,v retrieving revision 1.50 diff -u -r1.50 hash.c --- src/hash.c 4 Nov 2003 18:33:10 -0000 1.50 +++ src/hash.c 7 Nov 2003 15:09:44 -0000 @@ -429,12 +429,26 @@ HASHBUCKET * -hash_get(Interp *interpreter, HASH *hash, void *key) +hash_get_bucket(Interp *interpreter, HASH *hash, void *key) { UINTVAL hashval = (hash->hash_val)(interpreter, key); HashIndex *table = (HashIndex *)hash->buffer.bufstart; BucketIndex chain = table[hashval & hash->max_chain]; return find_bucket(interpreter, hash, chain, key); +} + +void * +hash_get(Interp *interpreter, HASH *hash, void *key) +{ + HASHBUCKET *bucket = hash_get_bucket(interpreter, hash, key); + return bucket ? bucket->value : NULL; +} + +INTVAL +hash_exists(Interp *interpreter, HASH *hash, void *key) +{ + HASHBUCKET *bucket = hash_get_bucket(interpreter, hash, key); + return bucket ? 1 : 0; } /* The key is *not* copied. */