aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/curl/lib/hash.c
diff options
context:
space:
mode:
authordeshevoy <deshevoy@yandex-team.ru>2022-02-10 16:46:56 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:56 +0300
commite988f30484abe5fdeedcc7a5d3c226c01a21800c (patch)
tree0a217b173aabb57b7e51f8a169989b1a3e0309fe /contrib/libs/curl/lib/hash.c
parent33ee501c05d3f24036ae89766a858930ae66c548 (diff)
downloadydb-e988f30484abe5fdeedcc7a5d3c226c01a21800c.tar.gz
Restoring authorship annotation for <deshevoy@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'contrib/libs/curl/lib/hash.c')
-rw-r--r--contrib/libs/curl/lib/hash.c136
1 files changed, 68 insertions, 68 deletions
diff --git a/contrib/libs/curl/lib/hash.c b/contrib/libs/curl/lib/hash.c
index 051c1762699..6aea82b5254 100644
--- a/contrib/libs/curl/lib/hash.c
+++ b/contrib/libs/curl/lib/hash.c
@@ -22,11 +22,11 @@
#include "curl_setup.h"
-#include <curl/curl.h>
-
+#include <curl/curl.h>
+
#include "hash.h"
#include "llist.h"
-#include "curl_memory.h"
+#include "curl_memory.h"
/* The last #include file should be: */
#include "memdebug.h"
@@ -47,12 +47,12 @@ hash_element_dtor(void *user, void *element)
free(e);
}
-/* Initializes a hash structure.
- * Return 1 on error, 0 is fine.
- *
- * @unittest: 1602
- * @unittest: 1603
- */
+/* Initializes a hash structure.
+ * Return 1 on error, 0 is fine.
+ *
+ * @unittest: 1602
+ * @unittest: 1603
+ */
int
Curl_hash_init(struct Curl_hash *h,
int slots,
@@ -72,38 +72,38 @@ Curl_hash_init(struct Curl_hash *h,
h->table = malloc(slots * sizeof(struct Curl_llist));
if(h->table) {
- int i;
- for(i = 0; i < slots; ++i)
+ int i;
+ for(i = 0; i < slots; ++i)
Curl_llist_init(&h->table[i], (Curl_llist_dtor) hash_element_dtor);
return 0; /* fine */
}
- h->slots = 0;
- return 1; /* failure */
+ h->slots = 0;
+ return 1; /* failure */
}
static struct Curl_hash_element *
mk_hash_element(const void *key, size_t key_len, const void *p)
{
- /* allocate the struct plus memory after it to store the key */
+ /* allocate the struct plus memory after it to store the key */
struct Curl_hash_element *he = malloc(sizeof(struct Curl_hash_element) +
- key_len);
+ key_len);
if(he) {
- /* copy the key */
- memcpy(he->key, key, key_len);
- he->key_len = key_len;
- he->ptr = (void *) p;
+ /* copy the key */
+ memcpy(he->key, key, key_len);
+ he->key_len = key_len;
+ he->ptr = (void *) p;
}
return he;
}
-#define FETCH_LIST(x,y,z) &x->table[x->hash_func(y, z, x->slots)]
+#define FETCH_LIST(x,y,z) &x->table[x->hash_func(y, z, x->slots)]
/* Insert the data in the hash. If there already was a match in the hash,
* that data is replaced.
*
* @unittest: 1305
- * @unittest: 1602
- * @unittest: 1603
+ * @unittest: 1602
+ * @unittest: 1603
*/
void *
Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
@@ -123,19 +123,19 @@ Curl_hash_add(struct Curl_hash *h, void *key, size_t key_len, void *p)
he = mk_hash_element(key, key_len, p);
if(he) {
- Curl_llist_insert_next(l, l->tail, he, &he->list);
- ++h->size;
- return p; /* return the new entry */
+ Curl_llist_insert_next(l, l->tail, he, &he->list);
+ ++h->size;
+ return p; /* return the new entry */
}
return NULL; /* failure */
}
-/* Remove the identified hash entry.
- * Returns non-zero on failure.
- *
- * @unittest: 1603
- */
+/* Remove the identified hash entry.
+ * Returns non-zero on failure.
+ *
+ * @unittest: 1603
+ */
int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len)
{
struct Curl_llist_element *le;
@@ -152,10 +152,10 @@ int Curl_hash_delete(struct Curl_hash *h, void *key, size_t key_len)
return 1;
}
-/* Retrieves a hash element.
- *
- * @unittest: 1603
- */
+/* Retrieves a hash element.
+ *
+ * @unittest: 1603
+ */
void *
Curl_hash_pick(struct Curl_hash *h, void *key, size_t key_len)
{
@@ -194,20 +194,20 @@ Curl_hash_apply(Curl_hash *h, void *user,
}
#endif
-/* Destroys all the entries in the given hash and resets its attributes,
- * prepping the given hash for [static|dynamic] deallocation.
- *
- * @unittest: 1305
- * @unittest: 1602
- * @unittest: 1603
- */
+/* Destroys all the entries in the given hash and resets its attributes,
+ * prepping the given hash for [static|dynamic] deallocation.
+ *
+ * @unittest: 1305
+ * @unittest: 1602
+ * @unittest: 1603
+ */
void
Curl_hash_destroy(struct Curl_hash *h)
{
int i;
for(i = 0; i < h->slots; ++i) {
- Curl_llist_destroy(&h->table[i], (void *) h);
+ Curl_llist_destroy(&h->table[i], (void *) h);
}
Curl_safefree(h->table);
@@ -215,18 +215,18 @@ Curl_hash_destroy(struct Curl_hash *h)
h->slots = 0;
}
-/* Removes all the entries in the given hash.
- *
- * @unittest: 1602
- */
+/* Removes all the entries in the given hash.
+ *
+ * @unittest: 1602
+ */
void
Curl_hash_clean(struct Curl_hash *h)
-{
- Curl_hash_clean_with_criterium(h, NULL, NULL);
-}
-
-/* Cleans all entries that pass the comp function criteria. */
-void
+{
+ Curl_hash_clean_with_criterium(h, NULL, NULL);
+}
+
+/* Cleans all entries that pass the comp function criteria. */
+void
Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
int (*comp)(void *, void *))
{
@@ -239,13 +239,13 @@ Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
return;
for(i = 0; i < h->slots; ++i) {
- list = &h->table[i];
+ list = &h->table[i];
le = list->head; /* get first list entry */
while(le) {
struct Curl_hash_element *he = le->ptr;
lnext = le->next;
/* ask the callback function if we shall remove this entry or not */
- if(comp == NULL || comp(user, he->ptr)) {
+ if(comp == NULL || comp(user, he->ptr)) {
Curl_llist_remove(list, le, (void *) h);
--h->size; /* one less entry in the hash now */
}
@@ -254,24 +254,24 @@ Curl_hash_clean_with_criterium(struct Curl_hash *h, void *user,
}
}
-size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num)
+size_t Curl_hash_str(void *key, size_t key_length, size_t slots_num)
{
- const char *key_str = (const char *) key;
+ const char *key_str = (const char *) key;
const char *end = key_str + key_length;
- size_t h = 5381;
+ size_t h = 5381;
while(key_str < end) {
h += h << 5;
- h ^= *key_str++;
+ h ^= *key_str++;
}
return (h % slots_num);
}
-size_t Curl_str_key_compare(void *k1, size_t key1_len,
- void *k2, size_t key2_len)
+size_t Curl_str_key_compare(void *k1, size_t key1_len,
+ void *k2, size_t key2_len)
{
- if((key1_len == key2_len) && !memcmp(k1, k2, key1_len))
+ if((key1_len == key2_len) && !memcmp(k1, k2, key1_len))
return 1;
return 0;
@@ -296,11 +296,11 @@ Curl_hash_next_element(struct Curl_hash_iterator *iter)
/* If we have reached the end of the list, find the next one */
if(!iter->current_element) {
- int i;
- for(i = iter->slot_index; i < h->slots; i++) {
- if(h->table[i].head) {
- iter->current_element = h->table[i].head;
- iter->slot_index = i + 1;
+ int i;
+ for(i = iter->slot_index; i < h->slots; i++) {
+ if(h->table[i].head) {
+ iter->current_element = h->table[i].head;
+ iter->slot_index = i + 1;
break;
}
}
@@ -310,8 +310,8 @@ Curl_hash_next_element(struct Curl_hash_iterator *iter)
struct Curl_hash_element *he = iter->current_element->ptr;
return he;
}
- iter->current_element = NULL;
- return NULL;
+ iter->current_element = NULL;
+ return NULL;
}
#if 0 /* useful function for debugging hashes and their contents */