} while ( 0 );
#endif /* ! timermul */
-LDAP_LUTIL_F (int)
-lutil_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp );
-LDAP_LUTIL_F (int)
-lutil_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
-LDAP_LUTIL_F (int)
-lutil_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
-
LDAP_END_DECL
#endif /* _LUTIL_H */
/* use bisection */
i = 0;
if ( ld->ld_nabandoned == 0 ||
- lutil_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, &i ) == 0 )
+ ldap_int_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, &i ) == 0 )
{
- lutil_bisect_insert( &ld->ld_abandoned, &ld->ld_nabandoned, msgid, i );
+ ldap_int_bisect_insert( &ld->ld_abandoned, &ld->ld_nabandoned, msgid, i );
}
if ( err != -1 ) {
#endif
return( ld->ld_errno );
}
+
+/*
+ * ldap_int_bisect_find
+ *
+ * args:
+ * v: array of length n (in)
+ * n: length of array v (in)
+ * id: value to look for (in)
+ * idxp: pointer to location of value/insert point
+ *
+ * return:
+ * 0: not found
+ * 1: found
+ * -1: error
+ */
+int
+ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
+{
+ int begin,
+ end,
+ i,
+ rc = 0;
+
+ assert( n >= 0 );
+ assert( id >= 0 );
+
+ begin = 0;
+ end = n - 1;
+
+ if ( n > 0 ) {
+ if ( id < v[ begin ] ) {
+ *idxp = 0;
+
+ } else if ( id > v[ end ] ) {
+ *idxp = n;
+
+ } else {
+ int pos;
+ ber_int_t curid;
+
+ while ( end >= begin ) {
+ pos = (begin + end)/2;
+ curid = v[ pos ];
+
+ if ( id < curid ) {
+ end = pos - 1;
+
+ } else if ( id > curid ) {
+ begin = pos + 1;
+
+ } else {
+ /* already abandoned? */
+ *idxp = pos;
+ rc = 1;
+ break;
+ }
+ }
+
+ if ( rc == 0 ) {
+ *idxp = pos + ( id > curid ? 1 : 0 );
+ }
+ }
+
+ } else {
+ *idxp = 0;
+ }
+
+ return rc;
+}
+
+/*
+ * ldap_int_bisect_insert
+ *
+ * args:
+ * vp: pointer to array of length *np (in/out)
+ * np: pointer to length of array *vp (in/out)
+ * id: value to insert (in)
+ * idx: location of insert point (as computed by ldap_int_bisect_find())
+ *
+ * return:
+ * 0: inserted
+ * -1: error
+ */
+int
+ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
+{
+ ber_int_t *v;
+ ber_len_t n;
+ int i;
+
+ assert( vp != NULL );
+ assert( np != NULL );
+ assert( *np >= 0 );
+ assert( idx >= 0 );
+ assert( idx <= *np );
+
+ n = *np;
+
+ v = ber_memrealloc( *vp, sizeof( ber_int_t ) * ( n + 1 ) );
+ if ( v == NULL ) {
+ return -1;
+ }
+ *vp = v;
+
+ for ( i = n; i > idx; i-- ) {
+ v[ i ] = v[ i - 1 ];
+ }
+ v[ idx ] = id;
+ ++(*np);
+
+ return 0;
+}
+
+/*
+ * ldap_int_bisect_delete
+ *
+ * args:
+ * vp: pointer to array of length *np (in/out)
+ * np: pointer to length of array *vp (in/out)
+ * id: value to delete (in)
+ * idx: location of value to delete (as computed by ldap_int_bisect_find())
+ *
+ * return:
+ * 0: deleted
+ */
+int
+ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
+{
+ ber_int_t *v;
+ ber_len_t n;
+ int i;
+
+ assert( vp != NULL );
+ assert( np != NULL );
+ assert( *np >= 0 );
+ assert( idx >= 0 );
+ assert( idx < *np );
+
+ v = *vp;
+
+ assert( v[ idx ] == id );
+
+ --(*np);
+ n = *np;
+
+ for ( i = idx; i < n; i++ ) {
+ v[ i ] = v[ i + 1 ];
+ }
+
+ return 0;
+}
+
#define LDAP_NEXT_MSGID(ld, id) id = ++(ld)->ld_msgid
#endif
+/*
+ * in abandon.c
+ */
+
+LDAP_F (int)
+ldap_int_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp );
+LDAP_F (int)
+ldap_int_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx );
+LDAP_F (int)
+ldap_int_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx );
+
/*
* in init.c
*/
assert( msgid >= 0 );
assert( ld->ld_nabandoned >= 0 );
- return lutil_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, idxp );
+ return ldap_int_bisect_find( ld->ld_abandoned, ld->ld_nabandoned, msgid, idxp );
}
/*
LDAP_PVT_THREAD_ASSERT_MUTEX_OWNER( &ld->ld_res_mutex );
#endif
- /* NOTE: those assertions are repeated in lutil_bisect_delete() */
+ /* NOTE: those assertions are repeated in ldap_int_bisect_delete() */
assert( idx >= 0 );
assert( idx < ld->ld_nabandoned );
assert( ld->ld_abandoned[ idx ] == msgid );
- return lutil_bisect_delete( &ld->ld_abandoned, &ld->ld_nabandoned,
+ return ldap_int_bisect_delete( &ld->ld_abandoned, &ld->ld_nabandoned,
msgid, idx );
}
return 0;
}
-/*
- * lutil_bisect_find
- *
- * args:
- * v: array of length n (in)
- * n: length of array v (in)
- * id: value to look for (in)
- * idxp: pointer to location of value/insert point
- *
- * return:
- * 0: not found
- * 1: found
- * -1: error
- */
-int
-lutil_bisect_find( ber_int_t *v, ber_len_t n, ber_int_t id, int *idxp )
-{
- int begin,
- end,
- i,
- rc = 0;
-
- assert( n >= 0 );
- assert( id >= 0 );
-
- begin = 0;
- end = n - 1;
-
- if ( n > 0 ) {
- if ( id < v[ begin ] ) {
- *idxp = 0;
-
- } else if ( id > v[ end ] ) {
- *idxp = n;
-
- } else {
- int pos;
- ber_int_t curid;
-
- while ( end >= begin ) {
- pos = (begin + end)/2;
- curid = v[ pos ];
-
- if ( id < curid ) {
- end = pos - 1;
-
- } else if ( id > curid ) {
- begin = pos + 1;
-
- } else {
- /* already abandoned? */
- *idxp = pos;
- rc = 1;
- break;
- }
- }
-
- if ( rc == 0 ) {
- *idxp = pos + ( id > curid ? 1 : 0 );
- }
- }
-
- } else {
- *idxp = 0;
- }
-
- return rc;
-}
-
-/*
- * lutil_bisect_insert
- *
- * args:
- * vp: pointer to array of length *np (in/out)
- * np: pointer to length of array *vp (in/out)
- * id: value to insert (in)
- * idx: location of insert point (as computed by lutil_bosect_find())
- *
- * return:
- * 0: inserted
- * -1: error
- */
-int
-lutil_bisect_insert( ber_int_t **vp, ber_len_t *np, int id, int idx )
-{
- ber_int_t *v;
- ber_len_t n;
- int i;
-
- assert( vp != NULL );
- assert( np != NULL );
- assert( *np >= 0 );
- assert( idx >= 0 );
- assert( idx <= *np );
-
- n = *np;
-
- v = ber_memrealloc( *vp, sizeof( ber_int_t ) * ( n + 1 ) );
- if ( v == NULL ) {
- return -1;
- }
- *vp = v;
-
- for ( i = n; i > idx; i-- ) {
- v[ i ] = v[ i - 1 ];
- }
- v[ idx ] = id;
- ++(*np);
-
- return 0;
-}
-
-/*
- * lutil_bisect_delete
- *
- * args:
- * vp: pointer to array of length *np (in/out)
- * np: pointer to length of array *vp (in/out)
- * id: value to delete (in)
- * idx: location of value to delete (as computed by lutil_bosect_find())
- *
- * return:
- * 0: deleted
- */
-int
-lutil_bisect_delete( ber_int_t **vp, ber_len_t *np, int id, int idx )
-{
- ber_int_t *v;
- ber_len_t n;
- int i;
-
- assert( vp != NULL );
- assert( np != NULL );
- assert( *np >= 0 );
- assert( idx >= 0 );
- assert( idx < *np );
-
- v = *vp;
-
- assert( v[ idx ] == id );
-
- --(*np);
- n = *np;
-
- for ( i = idx; i < n; i++ ) {
- v[ i ] = v[ i + 1 ];
- }
-
- return 0;
-}
-