[dovecot-cvs] dovecot/src/lib bsearch-insert-pos.c, 1.1, 1.2 bsearch-insert-pos.h, 1.1, 1.2

tss at dovecot.org tss at dovecot.org
Thu Mar 15 19:02:07 EET 2007


Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv17750/lib

Modified Files:
	bsearch-insert-pos.c bsearch-insert-pos.h 
Log Message:
bsearch_insert_pos() API changed. Patch by Max Kellermann



Index: bsearch-insert-pos.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/bsearch-insert-pos.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bsearch-insert-pos.c	21 Dec 2005 17:47:25 -0000	1.1
+++ bsearch-insert-pos.c	15 Mar 2007 17:02:04 -0000	1.2
@@ -3,8 +3,9 @@
 #include "lib.h"
 #include "bsearch-insert-pos.h"
 
-void *bsearch_insert_pos(const void *key, const void *base, unsigned int nmemb,
-			 size_t size, int (*cmp)(const void *, const void *))
+bool bsearch_insert_pos(const void *key, const void *base, unsigned int nmemb,
+			size_t size, int (*cmp)(const void *, const void *),
+			unsigned int *idx_r)
 {
 	const void *p;
 	unsigned int idx, left_idx, right_idx;
@@ -21,13 +22,19 @@
 			left_idx = idx+1;
 		else if (ret < 0)
 			right_idx = idx;
-		else
-			return (void *)p;
+		else {
+			*idx_r = idx;
+			return TRUE;
+		}
 	}
 
-	p = CONST_PTR_OFFSET(base, idx * size);
-	if (idx < nmemb && cmp(key, p) > 0)
-		p = CONST_PTR_OFFSET(p, size);
-	return (void *)p;
+	if (idx < nmemb) {
+		p = CONST_PTR_OFFSET(base, idx * size);
+		if (cmp(key, p) > 0)
+			++idx;
+	}
+
+	*idx_r = idx;
+	return FALSE;
 }
 

Index: bsearch-insert-pos.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/bsearch-insert-pos.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- bsearch-insert-pos.h	21 Dec 2005 17:47:25 -0000	1.1
+++ bsearch-insert-pos.h	15 Mar 2007 17:02:04 -0000	1.2
@@ -1,9 +1,11 @@
 #ifndef __BSEARCH_INSERT_POS
 #define __BSEARCH_INSERT_POS
 
-/* If key is found, returns the pointer to it. If not, returns a pointer to
-   where it should be inserted. */
-void *bsearch_insert_pos(const void *key, const void *base, unsigned int nmemb,
-			 size_t size, int (*cmp)(const void *, const void *));
+/* If key is found, returns TRUE and sets idx_r to the position where the key
+   was found. If key isn't found, returns FALSE and sets idx_r to the position
+   where the key should be inserted. */
+bool bsearch_insert_pos(const void *key, const void *base, unsigned int nmemb,
+			size_t size, int (*cmp)(const void *, const void *),
+			unsigned int *idx_r);
 
 #endif



More information about the dovecot-cvs mailing list