diff options
author | Dmitri Pal <dpal@redhat.com> | 2009-09-27 22:18:41 -0400 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-10-05 10:32:07 -0400 |
commit | ea7d823fa584b36e9a34a43c32dc476beede5ea2 (patch) | |
tree | bf3080e4b0b14c26cf4080d6c6d11d6781a0b471 /common/collection/collection.c | |
parent | 26a9c1f22f31a87a83fbb59caea7c7565563f479 (diff) | |
download | sssd-ea7d823fa584b36e9a34a43c32dc476beede5ea2.tar.gz sssd-ea7d823fa584b36e9a34a43c32dc476beede5ea2.tar.xz sssd-ea7d823fa584b36e9a34a43c32dc476beede5ea2.zip |
COLLECTION Enhancing hashing and iteration functions
Diffstat (limited to 'common/collection/collection.c')
-rw-r--r-- | common/collection/collection.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/common/collection/collection.c b/common/collection/collection.c index d0078d9e4..27dee8364 100644 --- a/common/collection/collection.c +++ b/common/collection/collection.c @@ -241,7 +241,7 @@ int col_allocate_item(struct collection_item **ci, const char *property, return ENOMEM; } - item->phash = col_make_hash(property, &(item->property_len)); + item->phash = col_make_hash(property, 0, &(item->property_len)); TRACE_INFO_NUMBER("Item hash", item->phash); TRACE_INFO_NUMBER("Item property length", item->property_len); TRACE_INFO_NUMBER("Item property strlen", strlen(item->property)); @@ -2866,7 +2866,7 @@ int col_modify_item(struct collection_item *item, } /* Update property length and hash if we rename the property */ - item->phash = col_make_hash(property, &(item->property_len)); + item->phash = col_make_hash(property, 0, &(item->property_len)); TRACE_INFO_NUMBER("Item hash", item->phash); TRACE_INFO_NUMBER("Item property length", item->property_len); TRACE_INFO_NUMBER("Item property strlen", strlen(item->property)); @@ -3016,7 +3016,7 @@ uint64_t col_get_item_hash(struct collection_item *ci) * of the string not counting 0. * Length argument can be NULL. */ -uint64_t col_make_hash(const char *string, int *length) +uint64_t col_make_hash(const char *string, int sub_len, int *length) { uint64_t hash = 0; int str_len = 0; @@ -3026,6 +3026,10 @@ uint64_t col_make_hash(const char *string, int *length) if (string) { hash = FNV1a_base; while (string[str_len] != 0) { + + /* Check if we need to stop */ + if ((sub_len > 0) && (str_len == sub_len)) break; + hash = hash ^ toupper(string[str_len]); hash *= FNV1a_prime; str_len++; |