Migrated hashtable_t to INIT/METHOD macros.

This commit is contained in:
Tobias Brunner
2010-06-07 15:53:36 +02:00
parent 03ffa88531
commit 88b6f14143
+44 -58
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2008 Tobias Brunner * Copyright (C) 2008-2010 Tobias Brunner
* Hochschule fuer Technik Rapperswil * Hochschule fuer Technik Rapperswil
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
@@ -47,11 +47,13 @@ struct pair_t {
*/ */
pair_t *pair_create(void *key, void *value, u_int hash) pair_t *pair_create(void *key, void *value, u_int hash)
{ {
pair_t *this = malloc_thing(pair_t); pair_t *this;
this->key = key; INIT(this,
this->value = value; .key = key,
this->hash = hash; .value = value,
.hash = hash,
);
return this; return this;
} }
@@ -219,10 +221,8 @@ static void rehash(private_hashtable_t *this)
free(old_table); free(old_table);
} }
/** METHOD(hashtable_t, put, void*,
* Implementation of hashtable_t.put private_hashtable_t *this, void *key, void *value)
*/
static void *put(private_hashtable_t *this, void *key, void *value)
{ {
void *old_value = NULL; void *old_value = NULL;
linked_list_t *list; linked_list_t *list;
@@ -265,10 +265,8 @@ static void *put(private_hashtable_t *this, void *key, void *value)
return old_value; return old_value;
} }
/** METHOD(hashtable_t, get, void*,
* Implementation of hashtable_t.get private_hashtable_t *this, void *key)
*/
static void *get(private_hashtable_t *this, void *key)
{ {
void *value = NULL; void *value = NULL;
linked_list_t *list; linked_list_t *list;
@@ -286,10 +284,8 @@ static void *get(private_hashtable_t *this, void *key)
return value; return value;
} }
/** METHOD(hashtable_t, remove_, void*,
* Implementation of hashtable_t.remove private_hashtable_t *this, void *key)
*/
static void *remove_(private_hashtable_t *this, void *key)
{ {
void *value = NULL; void *value = NULL;
linked_list_t *list; linked_list_t *list;
@@ -317,18 +313,14 @@ static void *remove_(private_hashtable_t *this, void *key)
return value; return value;
} }
/** METHOD(hashtable_t, get_count, u_int,
* Implementation of hashtable_t.get_count private_hashtable_t *this)
*/
static u_int get_count(private_hashtable_t *this)
{ {
return this->count; return this->count;
} }
/** METHOD(enumerator_t, enumerate, bool,
* Implementation of private_enumerator_t.enumerator.enumerate. private_enumerator_t *this, void **key, void **value)
*/
static bool enumerate(private_enumerator_t *this, void **key, void **value)
{ {
while (this->row < this->table->capacity) while (this->row < this->table->capacity)
{ {
@@ -367,10 +359,8 @@ static bool enumerate(private_enumerator_t *this, void **key, void **value)
return FALSE; return FALSE;
} }
/** METHOD(enumerator_t, enumerator_destroy, void,
* Implementation of private_enumerator_t.enumerator.destroy. private_enumerator_t *this)
*/
static void enumerator_destroy(private_enumerator_t *this)
{ {
if (this->current) if (this->current)
{ {
@@ -379,26 +369,24 @@ static void enumerator_destroy(private_enumerator_t *this)
free(this); free(this);
} }
/** METHOD(hashtable_t, create_enumerator, enumerator_t*,
* Implementation of hashtable_t.create_enumerator. private_hashtable_t *this)
*/
static enumerator_t* create_enumerator(private_hashtable_t *this)
{ {
private_enumerator_t *enumerator = malloc_thing(private_enumerator_t); private_enumerator_t *enumerator;
enumerator->enumerator.enumerate = (void*)enumerate; INIT(enumerator,
enumerator->enumerator.destroy = (void*)enumerator_destroy; .enumerator = {
enumerator->table = this; .enumerate = (void*)_enumerate,
enumerator->row = 0; .destroy = (void*)_enumerator_destroy,
enumerator->current = NULL; },
.table = this,
);
return &enumerator->enumerator; return &enumerator->enumerator;
} }
/** METHOD(hashtable_t, destroy, void,
* Implementation of hashtable_t.destroy private_hashtable_t *this)
*/
static void destroy(private_hashtable_t *this)
{ {
linked_list_t *list; linked_list_t *list;
u_int row; u_int row;
@@ -421,22 +409,20 @@ static void destroy(private_hashtable_t *this)
hashtable_t *hashtable_create(hashtable_hash_t hash, hashtable_equals_t equals, hashtable_t *hashtable_create(hashtable_hash_t hash, hashtable_equals_t equals,
u_int capacity) u_int capacity)
{ {
private_hashtable_t *this = malloc_thing(private_hashtable_t); private_hashtable_t *this;
this->public.put = (void*(*)(hashtable_t*,void*,void*))put; INIT(this,
this->public.get = (void*(*)(hashtable_t*,void*))get; .public = {
this->public.remove = (void*(*)(hashtable_t*,void*))remove_; .put = _put,
this->public.get_count = (u_int(*)(hashtable_t*))get_count; .get = _get,
this->public.create_enumerator = (enumerator_t*(*)(hashtable_t*))create_enumerator; .remove = _remove_,
this->public.destroy = (void(*)(hashtable_t*))destroy; .get_count = _get_count,
.create_enumerator = _create_enumerator,
this->count = 0; .destroy = _destroy,
this->capacity = 0; },
this->mask = 0; .hash = hash,
this->load_factor = 0; .equals = equals,
this->table = NULL; );
this->hash = hash;
this->equals = equals;
init_hashtable(this, capacity); init_hashtable(this, capacity);