indent pass MODAPP-202

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11335 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2009-01-21 19:31:45 +00:00
1 parent d88a0fbefc
commit af82478311
20 files changed
+2029 -1979

No files matched your search

+48 -39
View File
@@ -31,7 +31,7 @@ void lh_abort(const char *msg, ...)
uint32_t lh_ptr_hash(void *k)
{
/* CAW: refactored to be 64bit nice */
return (uint32_t)((((ptrdiff_t)k * LH_PRIME) >> 4) & ULONG_MAX);
return (uint32_t) ((((ptrdiff_t) k * LH_PRIME) >> 4) & ULONG_MAX);
}
int lh_ptr_equal(void *k1, void *k2)
@@ -42,48 +42,47 @@ int lh_ptr_equal(void *k1, void *k2)
uint32_t lh_char_hash(void *k)
{
unsigned int h = 0;
const char* data = k;
while( *data!=0 ) h = h*129 + (unsigned int)(*data++) + LH_PRIME;
const char *data = k;
while (*data != 0)
h = h * 129 + (unsigned int) (*data++) + LH_PRIME;
return h;
}
int lh_char_equal(void *k1, void *k2)
{
return (strcmp((char*)k1, (char*)k2) == 0);
return (strcmp((char *) k1, (char *) k2) == 0);
}
struct lh_table* lh_table_new(int size, char *name,
lh_entry_free_fn *free_fn,
lh_hash_fn *hash_fn,
lh_equal_fn *equal_fn)
struct lh_table *lh_table_new(int size, char *name, lh_entry_free_fn * free_fn, lh_hash_fn * hash_fn, lh_equal_fn * equal_fn)
{
int i;
struct lh_table *t;
t = calloc(1, sizeof(struct lh_table));
if(!t) lh_abort("lh_table_new: calloc failed\n");
if (!t)
lh_abort("lh_table_new: calloc failed\n");
t->count = 0;
t->size = size;
t->name = name;
t->table = calloc(size, sizeof(struct lh_entry));
if(!t->table) lh_abort("lh_table_new: calloc failed\n");
if (!t->table)
lh_abort("lh_table_new: calloc failed\n");
t->free_fn = free_fn;
t->hash_fn = hash_fn;
t->equal_fn = equal_fn;
for(i = 0; i < size; i++) t->table[i].k = LH_EMPTY;
for (i = 0; i < size; i++)
t->table[i].k = LH_EMPTY;
return t;
}
struct lh_table* lh_kchar_table_new(int size, char *name,
lh_entry_free_fn *free_fn)
struct lh_table *lh_kchar_table_new(int size, char *name, lh_entry_free_fn * free_fn)
{
return lh_table_new(size, name, free_fn, lh_char_hash, lh_char_equal);
}
struct lh_table* lh_kptr_table_new(int size, char *name,
lh_entry_free_fn *free_fn)
struct lh_table *lh_kptr_table_new(int size, char *name, lh_entry_free_fn * free_fn)
{
return lh_table_new(size, name, free_fn, lh_ptr_hash, lh_ptr_equal);
}
@@ -95,7 +94,7 @@ void lh_table_resize(struct lh_table *t, int new_size)
new_t = lh_table_new(new_size, t->name, NULL, t->hash_fn, t->equal_fn);
ent = t->head;
while(ent) {
while (ent) {
lh_table_insert(new_t, ent->k, ent->v);
ent = ent->next;
}
@@ -111,8 +110,8 @@ void lh_table_resize(struct lh_table *t, int new_size)
void lh_table_free(struct lh_table *t)
{
struct lh_entry *c;
for(c = t->head; c != NULL; c = c->next) {
if(t->free_fn) {
for (c = t->head; c != NULL; c = c->next) {
if (t->free_fn) {
t->free_fn(c);
}
}
@@ -126,22 +125,25 @@ int lh_table_insert(struct lh_table *t, void *k, void *v)
uint32_t h, n;
t->inserts++;
if(t->count > t->size * 0.66) lh_table_resize(t, t->size * 2);
if (t->count > t->size * 0.66)
lh_table_resize(t, t->size * 2);
h = t->hash_fn(k);
n = h % t->size;
while( 1 ) {
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) break;
while (1) {
if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
break;
t->collisions++;
if(++n == t->size) n = 0;
if (++n == t->size)
n = 0;
}
t->table[n].k = k;
t->table[n].v = v;
t->count++;
if(t->head == NULL) {
if (t->head == NULL) {
t->head = t->tail = &t->table[n];
t->table[n].next = t->table[n].prev = NULL;
} else {
@@ -155,43 +157,50 @@ int lh_table_insert(struct lh_table *t, void *k, void *v)
}
struct lh_entry* lh_table_lookup_entry(struct lh_table *t, void *k)
struct lh_entry *lh_table_lookup_entry(struct lh_table *t, void *k)
{
uint32_t h = t->hash_fn(k);
uint32_t n = h % t->size;
t->lookups++;
while( 1 ) {
if(t->table[n].k == LH_EMPTY) return NULL;
if(t->table[n].k != LH_FREED &&
t->equal_fn(t->table[n].k, k)) return &t->table[n];
if(++n == t->size) n = 0;
while (1) {
if (t->table[n].k == LH_EMPTY)
return NULL;
if (t->table[n].k != LH_FREED && t->equal_fn(t->table[n].k, k))
return &t->table[n];
if (++n == t->size)
n = 0;
}
return NULL;
}
void* lh_table_lookup(struct lh_table *t, void *k)
void *lh_table_lookup(struct lh_table *t, void *k)
{
struct lh_entry *e = lh_table_lookup_entry(t, k);
if(e) return e->v;
if (e)
return e->v;
return NULL;
}
int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
{
ptrdiff_t n = (ptrdiff_t)(e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */
ptrdiff_t n = (ptrdiff_t) (e - t->table); /* CAW: fixed to be 64bit nice, still need the crazy negative case... */
/* CAW: this is bad, really bad, maybe stack goes other direction on this machine... */
if(n < 0) { return -2; }
if (n < 0) {
return -2;
}
if(t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED) return -1;
if (t->table[n].k == LH_EMPTY || t->table[n].k == LH_FREED)
return -1;
t->count--;
if(t->free_fn) t->free_fn(e);
if (t->free_fn)
t->free_fn(e);
t->table[n].v = NULL;
t->table[n].k = LH_FREED;
if(t->tail == &t->table[n] && t->head == &t->table[n]) {
if (t->tail == &t->table[n] && t->head == &t->table[n]) {
t->head = t->tail = NULL;
} else if (t->head == &t->table[n]) {
t->head->next->prev = NULL;
@@ -211,7 +220,7 @@ int lh_table_delete_entry(struct lh_table *t, struct lh_entry *e)
int lh_table_delete(struct lh_table *t, void *k)
{
struct lh_entry *e = lh_table_lookup_entry(t, k);
if(!e) return -1;
if (!e)
return -1;
return lh_table_delete_entry(t, e);
}