diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-16 22:57:56 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2006-10-16 22:57:56 (GMT) |
commit | 16a95636a32fd3f5f16ec37370060222673085a5 (patch) | |
tree | 92a43f36d4b10489b100b541e7c76a2fb875791c | |
parent | 84bf19bec42e2c53114727df2e239aa3fecb1071 (diff) | |
download | hdf5-16a95636a32fd3f5f16ec37370060222673085a5.zip hdf5-16a95636a32fd3f5f16ec37370060222673085a5.tar.gz hdf5-16a95636a32fd3f5f16ec37370060222673085a5.tar.bz2 |
[svn-r12768] Description:
Add 'initval' parameter to "lookup3" checksum routine (and implicitly to
the metadata checksum routine), to allow chaining several checksums together
easily (which isn't used by these modules, but will be used in my next checkin)
Tested on:
Linux/32 2.6 (chicago)
Linux/64 2.6 (chicago2)
-rw-r--r-- | src/H5B2cache.c | 12 | ||||
-rw-r--r-- | src/H5FScache.c | 8 | ||||
-rw-r--r-- | src/H5Gdense.c | 6 | ||||
-rw-r--r-- | src/H5HFcache.c | 12 | ||||
-rw-r--r-- | src/H5checksum.c | 10 | ||||
-rw-r--r-- | src/H5private.h | 4 | ||||
-rw-r--r-- | test/tchecksum.c | 20 |
7 files changed, 36 insertions, 36 deletions
diff --git a/src/H5B2cache.c b/src/H5B2cache.c index 62ce32e..9019765 100644 --- a/src/H5B2cache.c +++ b/src/H5B2cache.c @@ -215,7 +215,7 @@ H5B2_cache_hdr_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_type, vo HDassert((size_t)(p - buf) == size); /* Compute checksum on entire header */ - computed_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM)); + computed_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM), 0); /* Verify checksum */ if(stored_chksum != computed_chksum) @@ -312,7 +312,7 @@ H5B2_cache_hdr_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5B H5F_ENCODE_LENGTH(f, p, bt2->root.all_nrec); /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM)); + metadata_chksum = H5_checksum_metadata(buf, (size - H5B2_SIZEOF_CHKSUM), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); @@ -547,7 +547,7 @@ H5B2_cache_internal_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_uda } /* end for */ /* Compute checksum on internal node */ - computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page)); + computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -644,7 +644,7 @@ H5B2_cache_internal_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr } /* end for */ /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page)); + metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); @@ -876,7 +876,7 @@ H5B2_cache_leaf_load(H5F_t *f, hid_t dxpl_id, haddr_t addr, const void *_nrec, v } /* end for */ /* Compute checksum on internal node */ - computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page)); + computed_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -959,7 +959,7 @@ H5B2_cache_leaf_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, H5 } /* end for */ /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page)); + metadata_chksum = H5_checksum_metadata(shared->page, (size_t)(p - shared->page), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); diff --git a/src/H5FScache.c b/src/H5FScache.c index 646cf3e..fdf54e8 100644 --- a/src/H5FScache.c +++ b/src/H5FScache.c @@ -236,7 +236,7 @@ HDfprintf(stderr, "%s: Load free space header, addr = %a\n", FUNC, addr); H5F_DECODE_LENGTH(f, p, fspace->alloc_sect_size); /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -350,7 +350,7 @@ HDfprintf(stderr, "%s: Flushing free space header, addr = %a, destroy = %u\n", F H5F_ENCODE_LENGTH(f, p, fspace->alloc_sect_size); /* Compute checksum */ - metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); @@ -671,7 +671,7 @@ HDfprintf(stderr, "%s: fspace->sect_cls[%u].serial_size = %Zu\n", FUNC, sect_typ } /* end if */ /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -892,7 +892,7 @@ HDfprintf(stderr, "%s: Serializing section bins\n", FUNC); } /* end for */ /* Compute checksum */ - metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); diff --git a/src/H5Gdense.c b/src/H5Gdense.c index 4c31adc..3019d4f 100644 --- a/src/H5Gdense.c +++ b/src/H5Gdense.c @@ -387,7 +387,7 @@ HDfprintf(stderr, "%s: HDstrlen(lnk->name) = %Zu, link_size = %Zu\n", FUNC, HDst udata.common.dxpl_id = dxpl_id; udata.common.fheap = fheap; udata.common.name = lnk->name; - udata.common.name_hash = H5_checksum_lookup3(lnk->name, HDstrlen(lnk->name)); + udata.common.name_hash = H5_checksum_lookup3(lnk->name, HDstrlen(lnk->name), 0); udata.common.found_op = NULL; udata.common.found_op_data = NULL; /* udata.id already set in H5HF_insert() call */ @@ -491,7 +491,7 @@ H5G_dense_lookup(H5F_t *f, hid_t dxpl_id, const H5O_linfo_t *linfo, udata.dxpl_id = dxpl_id; udata.fheap = fheap; udata.name = name; - udata.name_hash = H5_checksum_lookup3(name, HDstrlen(name)); + udata.name_hash = H5_checksum_lookup3(name, HDstrlen(name), 0); udata.found_op = H5G_dense_lookup_cb; /* v2 B-tree comparison callback */ udata.found_op_data = lnk; @@ -1275,7 +1275,7 @@ H5G_dense_remove(H5F_t *f, hid_t dxpl_id, const H5O_linfo_t *linfo, udata.common.dxpl_id = dxpl_id; udata.common.fheap = fheap; udata.common.name = name; - udata.common.name_hash = H5_checksum_lookup3(name, HDstrlen(name)); + udata.common.name_hash = H5_checksum_lookup3(name, HDstrlen(name), 0); udata.common.found_op = NULL; udata.common.found_op_data = NULL; udata.adj_link = TRUE; diff --git a/src/H5HFcache.c b/src/H5HFcache.c index 916c2e1..c1df3c7 100644 --- a/src/H5HFcache.c +++ b/src/H5HFcache.c @@ -390,7 +390,7 @@ HDfprintf(stderr, "%s: Load heap header, addr = %a\n", FUNC, addr); /* Compute checksum on entire header */ /* (including the filter information, if present) */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -528,7 +528,7 @@ HDfprintf(stderr, "%s: Flushing heap header, addr = %a, destroy = %u\n", FUNC, a } /* end if */ /* Compute metadata checksum */ - metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); @@ -826,7 +826,7 @@ HDfprintf(stderr, "%s: iblock->ents[%Zu] = {%a}\n", FUNC, u, iblock->ents[u].add HDassert(iblock->nchildren); /* indirect blocks w/no children should have been deleted */ /* Compute checksum on indirect block */ - computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + computed_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32DECODE(p, stored_chksum); @@ -982,7 +982,7 @@ HDfprintf(stderr, "%s: iblock->filt_ents[%Zu] = {%Zu, %x}\n", FUNC, u, iblock->f } /* end for */ /* Compute checksum */ - metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf)); + metadata_chksum = H5_checksum_metadata(buf, (size_t)(p - buf), 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); @@ -1250,7 +1250,7 @@ HGOTO_ERROR(H5E_HEAP, H5E_UNSUPPORTED, NULL, "I/O filters not supported yet") HDmemset((uint8_t *)p - H5HF_SIZEOF_CHKSUM, 0, (size_t)H5HF_SIZEOF_CHKSUM); /* Compute checksum on entire direct block */ - computed_chksum = H5_checksum_metadata(dblock->blk, dblock->size); + computed_chksum = H5_checksum_metadata(dblock->blk, dblock->size, 0); /* Verify checksum */ if(stored_chksum != computed_chksum) @@ -1332,7 +1332,7 @@ H5HF_cache_dblock_flush(H5F_t *f, hid_t dxpl_id, hbool_t destroy, haddr_t addr, HDmemset(p, 0, (size_t)H5HF_SIZEOF_CHKSUM); /* Compute checksum on entire direct block */ - metadata_chksum = H5_checksum_metadata(dblock->blk, dblock->size); + metadata_chksum = H5_checksum_metadata(dblock->blk, dblock->size, 0); /* Metadata checksum */ UINT32ENCODE(p, metadata_chksum); diff --git a/src/H5checksum.c b/src/H5checksum.c index 98260ef..39ff065 100644 --- a/src/H5checksum.c +++ b/src/H5checksum.c @@ -359,7 +359,7 @@ use a bitmask. For example, if you need only 10 bits, do In which case, the hash table should have hashsize(10) elements. If you are hashing n strings (uint8_t **)k, do it like this: - for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h); + for (i=0, h=0; i<n; ++i) h = H5_checksum_lookup( k[i], len[i], h); By Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. You may use this code any way you wish, private, educational, or commercial. It's free. @@ -370,7 +370,7 @@ acceptable. Do NOT use for cryptographic purposes. */ uint32_t -H5_checksum_lookup3(const void *key, size_t length /*, uint32_t initval */) +H5_checksum_lookup3(const void *key, size_t length, uint32_t initval) { const uint8_t *k = (const uint8_t *)key; uint32_t a, b, c; /* internal state */ @@ -382,7 +382,7 @@ H5_checksum_lookup3(const void *key, size_t length /*, uint32_t initval */) HDassert(length > 0); /* Set up the internal state */ - a = b = c = 0xdeadbeef + ((uint32_t)length) /* + initval */; + a = b = c = 0xdeadbeef + ((uint32_t)length) + initval; /*--------------- all but the last block: affect some 32 bits of (a,b,c) */ while (length > 12) @@ -445,7 +445,7 @@ done: *------------------------------------------------------------------------- */ uint32_t -H5_checksum_metadata(const void *data, size_t len) +H5_checksum_metadata(const void *data, size_t len, uint32_t initval) { FUNC_ENTER_NOAPI_NOINIT_NOFUNC(H5_checksum_metadata) @@ -455,6 +455,6 @@ H5_checksum_metadata(const void *data, size_t len) /* Choose the appropriate checksum routine */ /* (use Bob Jenkin's "lookup3" algorithm for all buffer sizes) */ - FUNC_LEAVE_NOAPI(H5_checksum_lookup3(data, len)) + FUNC_LEAVE_NOAPI(H5_checksum_lookup3(data, len, initval)) } /* end H5_checksum_metadata() */ diff --git a/src/H5private.h b/src/H5private.h index 3f523e1..a43661b 100644 --- a/src/H5private.h +++ b/src/H5private.h @@ -1434,8 +1434,8 @@ H5_DLL int H5Z_term_interface(void); /* Checksum functions */ H5_DLL uint32_t H5_checksum_fletcher32(const void *data, size_t len); H5_DLL uint32_t H5_checksum_crc(const void *data, size_t len); -H5_DLL uint32_t H5_checksum_lookup3(const void *data, size_t len); -H5_DLL uint32_t H5_checksum_metadata(const void *data, size_t len); +H5_DLL uint32_t H5_checksum_lookup3(const void *data, size_t len, uint32_t initval); +H5_DLL uint32_t H5_checksum_metadata(const void *data, size_t len, uint32_t initval); /* Functions for debugging */ H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, uint8_t *buf, diff --git a/test/tchecksum.c b/test/tchecksum.c index 4c860b7..05ca71b 100644 --- a/test/tchecksum.c +++ b/test/tchecksum.c @@ -57,7 +57,7 @@ test_chksum_size_one(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xfa2568b7, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0xa209c931, "H5_checksum_lookup3"); /* Buffer w/zero(s) for data */ @@ -68,7 +68,7 @@ test_chksum_size_one(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xfa60fb57, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x8ba9414b, "H5_checksum_lookup3"); } /* test_chksum_size_one() */ @@ -91,7 +91,7 @@ test_chksum_size_two(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xfc856608, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x8ba7a6c9, "H5_checksum_lookup3"); /* Buffer w/zero(s) for data */ @@ -102,7 +102,7 @@ test_chksum_size_two(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xfc7e9b20, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x62cd61b3, "H5_checksum_lookup3"); } /* test_chksum_size_two() */ @@ -125,7 +125,7 @@ test_chksum_size_three(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xfebc5d70, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0xcebdf4f0, "H5_checksum_lookup3"); /* Buffer w/zero(s) for data */ @@ -136,7 +136,7 @@ test_chksum_size_three(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xf9cc4c7a, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x6bd0060f, "H5_checksum_lookup3"); } /* test_chksum_size_three() */ @@ -159,7 +159,7 @@ test_chksum_size_four(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xff398a46, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x2c88bb51, "H5_checksum_lookup3"); /* Buffer w/zero(s) for data */ @@ -170,7 +170,7 @@ test_chksum_size_four(void) chksum = H5_checksum_crc(buf, sizeof(buf)); VERIFY(chksum, 0xff117081, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(buf, sizeof(buf)); + chksum = H5_checksum_lookup3(buf, sizeof(buf), 0); VERIFY(chksum, 0x049396b8, "H5_checksum_lookup3"); } /* test_chksum_size_four() */ @@ -197,7 +197,7 @@ test_chksum_large(void) chksum = H5_checksum_crc(large_buf, sizeof(large_buf)); VERIFY(chksum, 0xfbd0f7c0, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(large_buf, sizeof(large_buf)); + chksum = H5_checksum_lookup3(large_buf, sizeof(large_buf), 0); VERIFY(chksum, 0x1bd2ee7b, "H5_checksum_lookup3"); /* Buffer w/zero(s) for data */ @@ -208,7 +208,7 @@ test_chksum_large(void) chksum = H5_checksum_crc(large_buf, sizeof(large_buf)); VERIFY(chksum, 0xfac8b4c4, "H5_checksum_crc"); - chksum = H5_checksum_lookup3(large_buf, sizeof(large_buf)); + chksum = H5_checksum_lookup3(large_buf, sizeof(large_buf), 0); VERIFY(chksum, 0x930c7afc, "H5_checksum_lookup3"); } /* test_chksum_large() */ |