[asterisk-commits] dlee: branch dlee/hashtab-skiplist r399771 - in /team/dlee/hashtab-skiplist: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 24 23:29:36 CDT 2013


Author: dlee
Date: Tue Sep 24 23:29:33 2013
New Revision: 399771

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399771
Log:
Hack to see if there's performance to be gained

Modified:
    team/dlee/hashtab-skiplist/main/astobj2.c
    team/dlee/hashtab-skiplist/tests/test_astobj2.c

Modified: team/dlee/hashtab-skiplist/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/hashtab-skiplist/main/astobj2.c?view=diff&rev=399771&r1=399770&r2=399771
==============================================================================
--- team/dlee/hashtab-skiplist/main/astobj2.c (original)
+++ team/dlee/hashtab-skiplist/main/astobj2.c Tue Sep 24 23:29:33 2013
@@ -2248,20 +2248,16 @@
 struct hash_traversal_state {
 	/*! Active sort function in the traversal if not NULL. */
 	ao2_sort_fn *sort_fn;
-	/*! Node returned in the sorted starting hash bucket if OBJ_CONTINUE flag set. (Reffed) */
-	struct hash_bucket_node *first_node;
 	/*! Saved comparison callback arg pointer. */
 	void *arg;
-	/*! Starting hash bucket */
-	int bucket_start;
-	/*! Stopping hash bucket */
-	int bucket_last;
 	/*! Saved search flags to control traversing the container. */
 	enum search_flags flags;
 	/*! TRUE if it is a descending search */
 	unsigned int descending:1;
 	/*! TRUE if the starting bucket needs to be rechecked because of sorting skips. */
 	unsigned int recheck_starting_bucket:1;
+	/*! TRUE to limit searching to a single bucket */
+	unsigned int one_bucket:1;
 };
 
 struct hash_traversal_state_check {
@@ -2288,7 +2284,7 @@
 static struct hash_bucket_node *hash_ao2_find_first(struct ao2_container_hash *self, enum search_flags flags, void *arg, struct hash_traversal_state *state)
 {
 	struct hash_bucket_node *node;
-	int bucket_cur;
+	struct hash_bucket *bucket_cur = NULL;
 	int cmp;
 
 	memset(state, 0, sizeof(*state));
@@ -2314,47 +2310,39 @@
 	switch (flags & OBJ_SEARCH_MASK) {
 	case OBJ_SEARCH_OBJECT:
 	case OBJ_SEARCH_KEY:
+		{
 		/* we know hash can handle this case */
-		bucket_cur = abs(self->hash_fn(arg, flags & OBJ_SEARCH_MASK));
-		bucket_cur %= self->n_buckets;
+		int bucket_idx;
+		bucket_idx = abs(self->hash_fn(arg, flags & OBJ_SEARCH_MASK));
+		bucket_idx %= self->n_buckets;
+		bucket_cur = &self->buckets[bucket_idx];
 		state->sort_fn = self->common.sort_fn;
+		state->one_bucket = 1;
 		break;
+		}
 	case OBJ_SEARCH_PARTIAL_KEY:
 		/* scan all buckets for partial key matches */
-		bucket_cur = -1;
 		state->sort_fn = self->common.sort_fn;
 		break;
 	default:
 		/* don't know, let's scan all buckets */
-		bucket_cur = -1;
 		state->sort_fn = NULL;
 		break;
 	}
 
 	if (state->descending) {
-		/*
-		 * Determine the search boundaries of a descending traversal.
-		 *
-		 * bucket_cur downto state->bucket_last
-		 */
-		if (bucket_cur < 0) {
-			bucket_cur = self->n_buckets - 1;
-			state->bucket_last = 0;
-		} else {
-			state->bucket_last = bucket_cur;
-		}
+		if (bucket_cur == NULL) {
+			bucket_cur = AST_DLLIST_LAST(&self->skip_list);
+		}
+
 		if (flags & OBJ_CONTINUE) {
-			state->bucket_last = 0;
-			if (state->sort_fn) {
-				state->recheck_starting_bucket = 1;
-			}
-		}
-		state->bucket_start = bucket_cur;
+			ast_assert(0); // TODO
+		}
 
 		/* For each bucket */
-		for (; state->bucket_last <= bucket_cur; --bucket_cur) {
+		for (; bucket_cur; bucket_cur = AST_DLLIST_PREV(bucket_cur, skip_links)) {
 			/* For each node in the bucket. */
-			for (node = AST_DLLIST_LAST(&self->buckets[bucket_cur].list);
+			for (node = AST_DLLIST_LAST(&bucket_cur->list);
 				node;
 				node = AST_DLLIST_PREV(node, links)) {
 				if (!node->common.obj) {
@@ -2369,12 +2357,7 @@
 						continue;
 					}
 					if (flags & OBJ_CONTINUE) {
-						/* Remember first node when we wrap around. */
-						__ao2_ref(node, +1);
-						state->first_node = node;
-
-						/* From now on all nodes are matching */
-						state->sort_fn = NULL;
+						ast_assert(0); // TODO
 					} else if (cmp < 0) {
 						/* No more nodes in this bucket are possible to match. */
 						break;
@@ -2387,54 +2370,36 @@
 			}
 
 			/* Was this the starting bucket? */
-			if (bucket_cur == state->bucket_start
+			if (0//bucket_cur == state->bucket_start
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* In case the bucket was empty or none of the nodes matched. */
-				state->sort_fn = NULL;
+				ast_assert(0); // TODO
 			}
 
 			/* Was this the first container bucket? */
 			if (bucket_cur == 0
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* Move to the end to ensure we check every bucket */
-				bucket_cur = self->n_buckets;
-				state->bucket_last = state->bucket_start + 1;
-				if (state->recheck_starting_bucket) {
-					/*
-					 * We have to recheck the first part of the starting bucket
-					 * because of sorting skips.
-					 */
-					state->recheck_starting_bucket = 0;
-					--state->bucket_last;
-				}
+				ast_assert(0); // TODO
+			}
+
+			if (state->one_bucket) {
+				break;
 			}
 		}
 	} else {
-		/*
-		 * Determine the search boundaries of an ascending traversal.
-		 *
-		 * bucket_cur to state->bucket_last-1
-		 */
-		if (bucket_cur < 0) {
-			bucket_cur = 0;
-			state->bucket_last = self->n_buckets;
-		} else {
-			state->bucket_last = bucket_cur + 1;
-		}
+		if (bucket_cur == NULL) {
+			bucket_cur = AST_DLLIST_FIRST(&self->skip_list);
+		}
+
 		if (flags & OBJ_CONTINUE) {
-			state->bucket_last = self->n_buckets;
-			if (state->sort_fn) {
-				state->recheck_starting_bucket = 1;
-			}
-		}
-		state->bucket_start = bucket_cur;
+			ast_assert(0); // TODO
+		}
 
 		/* For each bucket */
-		for (; bucket_cur < state->bucket_last; ++bucket_cur) {
+		for (; bucket_cur; bucket_cur = AST_DLLIST_NEXT(bucket_cur, skip_links)) {
 			/* For each node in the bucket. */
-			for (node = AST_DLLIST_FIRST(&self->buckets[bucket_cur].list);
+			for (node = AST_DLLIST_FIRST(&bucket_cur->list);
 				node;
 				node = AST_DLLIST_NEXT(node, links)) {
 				if (!node->common.obj) {
@@ -2449,12 +2414,7 @@
 						continue;
 					}
 					if (flags & OBJ_CONTINUE) {
-						/* Remember first node when we wrap around. */
-						__ao2_ref(node, +1);
-						state->first_node = node;
-
-						/* From now on all nodes are matching */
-						state->sort_fn = NULL;
+						ast_assert(0); // TODO
 					} else if (cmp > 0) {
 						/* No more nodes in this bucket are possible to match. */
 						break;
@@ -2467,32 +2427,20 @@
 			}
 
 			/* Was this the starting bucket? */
-			if (bucket_cur == state->bucket_start
+			if (0 //bucket_cur == state->bucket_start
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* In case the bucket was empty or none of the nodes matched. */
-				state->sort_fn = NULL;
+				ast_assert(0); // TODO
 			}
 
 			/* Was this the last container bucket? */
-			if (bucket_cur == self->n_buckets - 1
+			if (0 // bucket_cur == self->n_buckets - 1
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* Move to the beginning to ensure we check every bucket */
-				bucket_cur = -1;
-				state->bucket_last = state->bucket_start;
-				if (state->recheck_starting_bucket) {
-					/*
-					 * We have to recheck the first part of the starting bucket
-					 * because of sorting skips.
-					 */
-					state->recheck_starting_bucket = 0;
-					++state->bucket_last;
-				}
-			}
-		}
-	}
-
+				ast_assert(0); // TODO
+			}
+		}
+	}
 	return NULL;
 }
 
@@ -2514,12 +2462,12 @@
 	struct hash_bucket_node *node;
 	void *arg;
 	enum search_flags flags;
-	int bucket_cur;
+	struct hash_bucket *bucket_cur;
 	int cmp;
 
 	arg = state->arg;
 	flags = state->flags;
-	bucket_cur = prev->my_bucket;
+	bucket_cur = &self->buckets[prev->my_bucket];
 	node = prev;
 
 	/*
@@ -2533,12 +2481,12 @@
 		goto hash_descending_resume;
 
 		/* For each bucket */
-		for (; state->bucket_last <= bucket_cur; --bucket_cur) {
+		for (; bucket_cur; bucket_cur = AST_DLLIST_PREV(bucket_cur, skip_links)) {
 			/* For each node in the bucket. */
-			for (node = AST_DLLIST_LAST(&self->buckets[bucket_cur].list);
+			for (node = AST_DLLIST_LAST(&bucket_cur->list);
 				node;
 				node = AST_DLLIST_PREV(node, links)) {
-				if (node == state->first_node) {
+				if (0) { //node == state->first_node) {
 					/* We have wrapped back to the starting point. */
 					__ao2_ref(prev, -1);
 					return NULL;
@@ -2582,29 +2530,19 @@
 			if (bucket_cur == 0
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* Move to the end to ensure we check every bucket */
-				bucket_cur = self->n_buckets;
-				state->bucket_last = state->bucket_start + 1;
-				if (state->recheck_starting_bucket) {
-					/*
-					 * We have to recheck the first part of the starting bucket
-					 * because of sorting skips.
-					 */
-					state->recheck_starting_bucket = 0;
-					--state->bucket_last;
-				}
+				ast_assert(0); // TODO
 			}
 		}
 	} else {
 		goto hash_ascending_resume;
 
 		/* For each bucket */
-		for (; bucket_cur < state->bucket_last; ++bucket_cur) {
+		for (; bucket_cur; bucket_cur = AST_DLLIST_NEXT(bucket_cur, skip_links)) {
 			/* For each node in the bucket. */
-			for (node = AST_DLLIST_FIRST(&self->buckets[bucket_cur].list);
+			for (node = AST_DLLIST_FIRST(&bucket_cur->list);
 				node;
 				node = AST_DLLIST_NEXT(node, links)) {
-				if (node == state->first_node) {
+				if (0) { // node == state->first_node) {
 					/* We have wrapped back to the starting point. */
 					__ao2_ref(prev, -1);
 					return NULL;
@@ -2645,20 +2583,10 @@
 			}
 
 			/* Was this the last container bucket? */
-			if (bucket_cur == self->n_buckets - 1
+			if (0 //bucket_cur == self->n_buckets - 1
 				&& (flags & OBJ_CONTINUE)
 				&& (flags & OBJ_SEARCH_MASK) != OBJ_SEARCH_NONE) {
-				/* Move to the beginning to ensure we check every bucket */
-				bucket_cur = -1;
-				state->bucket_last = state->bucket_start;
-				if (state->recheck_starting_bucket) {
-					/*
-					 * We have to recheck the first part of the starting bucket
-					 * because of sorting skips.
-					 */
-					state->recheck_starting_bucket = 0;
-					++state->bucket_last;
-				}
+				ast_assert(0); // TODO
 			}
 		}
 	}
@@ -2679,9 +2607,6 @@
  */
 static void hash_ao2_find_cleanup(struct hash_traversal_state *state)
 {
-	if (state->first_node) {
-		__ao2_ref(state->first_node, -1);
-	}
 }
 
 /*!

Modified: team/dlee/hashtab-skiplist/tests/test_astobj2.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/hashtab-skiplist/tests/test_astobj2.c?view=diff&rev=399771&r1=399770&r2=399771
==============================================================================
--- team/dlee/hashtab-skiplist/tests/test_astobj2.c (original)
+++ team/dlee/hashtab-skiplist/tests/test_astobj2.c Tue Sep 24 23:29:33 2013
@@ -590,6 +590,7 @@
 				break;
 			}
 
+#if 0
 			/* ao2_find is just a shortcut notation for ao2_callback(). */
 			obj = ao2_callback(c1, OBJ_POINTER | OBJ_UNLINK | OBJ_CONTINUE, cmp_fn, NULL);
 			if (!obj) {
@@ -607,6 +608,7 @@
 				ao2_link(c2, obj);
 				ao2_t_ref(obj, -1, "test");
 			}
+#endif
 		}
 		if (ao2_container_check(c1, 0)) {
 			ast_test_status_update(test, "container integrity check failed\n");




More information about the asterisk-commits mailing list