Skip to content
This repository has been archived by the owner on Oct 14, 2023. It is now read-only.

Commit

Permalink
Cleanup whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Aug 28, 2014
1 parent 9b99508 commit 2b9724f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions hash.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
+----------------------------------------------------------------------+
| See COPYING file for further copyright information |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Author: Oleg Grenrus <[email protected]> |
| See CREDITS for contributors |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
*/

#ifndef HASH_H
Expand Down Expand Up @@ -85,7 +85,7 @@ int hash_si_find (struct hash_si *h, const char *key, size_t key_len, uint32_t *
int hash_si_remove (struct hash_si *h, const char *key, size_t key_len, uint32_t * value);

/** Travarses hash_si.
* Calls traverse_function on every item. Traverse function should not modify hash
* Calls traverse_function on every item. Traverse function should not modify hash
* @param h Pointer to hash_si struct.
* @param traverse_function Function to call on every item of hash_si.
*/
Expand Down
60 changes: 30 additions & 30 deletions hash_si.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
+----------------------------------------------------------------------+
| See COPYING file for further copyright information |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Author: Oleg Grenrus <[email protected]> |
| See CREDITS for contributors |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
*/

#ifdef PHP_WIN32
Expand Down Expand Up @@ -46,14 +46,14 @@ int hash_si_init(struct hash_si *h, size_t size) {
}

memset(h->data, 0, sizeof(struct hash_si_pair) * size);

return 0;
}
/* }}} */
/* {{{ hash_si_deinit */
void hash_si_deinit(struct hash_si *h) {
size_t i;

for (i = 0; i < h->size; i++) {
if (h->data[i].key != NULL) {
free(h->data[i].key);
Expand All @@ -76,30 +76,30 @@ void hash_si_deinit(struct hash_si *h) {
inline static size_t _hash_si_find(struct hash_si *h, const char *key, size_t key_len) {
uint32_t hv;
size_t size;

assert(h != NULL);

size = h->size;
hv = zend_inline_hash_func(key, key_len) & (h->size-1);

while (size > 0 &&
h->data[hv].key != NULL &&
(h->data[hv].key_len != key_len || memcmp(h->data[hv].key, key, key_len) != 0)) {
(h->data[hv].key_len != key_len || memcmp(h->data[hv].key, key, key_len) != 0)) {
/* linear prob */
hv = (hv + 1) & (h->size-1);
size--;
}

return hv;
}
/* }}} */
/* {{{ hash_si_remove */
int hash_si_remove(struct hash_si *h, const char *key, size_t key_len, uint32_t *value) {
uint32_t hv;
uint32_t j, k;

assert(h != NULL);

hv = _hash_si_find(h, key, key_len);

/* dont exists */
Expand All @@ -108,26 +108,26 @@ int hash_si_remove(struct hash_si *h, const char *key, size_t key_len, uint32_t
}

h->used--;

free(h->data[hv].key);

if (value != NULL)
if (value != NULL)
*value = h->data[hv].value;

j = (hv + 1) & (h->size-1);
j = (hv + 1) & (h->size-1);
while (h->data[j].key != NULL) {
k = zend_inline_hash_func(h->data[j].key, strlen(h->data[j].key)) & (h->size-1);
if ((j > hv && (k <= hv || k > j)) || (j < hv && (k <= hv && k > j))) {
h->data[hv].key = h->data[j].key;
h->data[hv].key_len = h->data[j].key_len;
h->data[hv].value = h->data[j].value;

hv = j;
}
j = (j + 1) & (h->size-1);
j = (j + 1) & (h->size-1);
}
h->data[hv].key = NULL;


return 0;
/*
Expand All @@ -140,7 +140,7 @@ int hash_si_remove(struct hash_si *h, const char *key, size_t key_len, uint32_t
* (j < i and (k <= i and k > j)) (note 2)
* slot[i] := slot[j]
* i := j
* mark slot[i] as unoccupied
* mark slot[i] as unoccupied
*
* For all records in a cluster, there must be no vacant slots between their natural
* hash position and their current position (else lookups will terminate before finding
Expand All @@ -166,20 +166,20 @@ inline static void hash_si_rehash(struct hash_si *h) {
uint32_t hv;
size_t i;
struct hash_si newh;

assert(h != NULL);

hash_si_init(&newh, h->size * 2);

for (i = 0; i < h->size; i++) {
if (h->data[i].key != NULL) {
hv = _hash_si_find(&newh, h->data[i].key, h->data[i].key_len);
newh.data[hv].key = h->data[i].key;
newh.data[hv].key_len = h->data[i].key_len;
newh.data[hv].value = h->data[i].value;
}
}
}

free(h->data);
h->data = newh.data;
h->size *= 2;
Expand All @@ -192,9 +192,9 @@ int hash_si_insert(struct hash_si *h, const char *key, size_t key_len, uint32_t
if (h->size / 4 * 3 < h->used + 1) {
hash_si_rehash(h);
}

hv = _hash_si_find(h, key, key_len);

if (h->data[hv].key == NULL) {
h->data[hv].key = (char *) malloc(key_len + 1);
if (h->data[hv].key == NULL) {
Expand All @@ -208,9 +208,9 @@ int hash_si_insert(struct hash_si *h, const char *key, size_t key_len, uint32_t
} else {
return 2;
}

h->data[hv].value = value;

return 0;
}
/* }}} */
Expand All @@ -219,9 +219,9 @@ int hash_si_find(struct hash_si *h, const char *key, size_t key_len, uint32_t *v
uint32_t hv;

assert(h != NULL);

hv = _hash_si_find(h, key, key_len);

if (h->data[hv].key == NULL) {
return 1;
} else {
Expand All @@ -235,7 +235,7 @@ void hash_si_traverse(struct hash_si *h, int (*traverse_function) (const char *k
size_t i;

assert(h != NULL && traverse_function != NULL);

for (i = 0; i < h->size; i++) {
if (h->data[i].key != NULL && traverse_function(h->data[i].key, h->data[i].key_len, h->data[i].value) != 1) {
return;
Expand Down
4 changes: 2 additions & 2 deletions igbinary.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
+----------------------------------------------------------------------+
| See COPYING file for further copyright information |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Author: Oleg Grenrus <[email protected]> |
| See CREDITS for contributors |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
*/

#ifndef IGBINARY_H
Expand Down
4 changes: 2 additions & 2 deletions php_igbinary.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/*
+----------------------------------------------------------------------+
| See COPYING file for further copyright information |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
| Author: Oleg Grenrus <[email protected]> |
| See CREDITS for contributors |
+----------------------------------------------------------------------+
+----------------------------------------------------------------------+
*/

#ifndef PHP_IGBINARY_H
Expand Down

0 comments on commit 2b9724f

Please sign in to comment.