~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/pbxt/src/bsearch_xt.cc

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2005 PrimeBase Technologies GmbH
 
2
 *
 
3
 * PrimeBase XT
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
18
 *
 
19
 * 2004-01-03   Paul McCullagh
 
20
 *
 
21
 * H&G2JCtL
 
22
 */
 
23
 
 
24
#include "xt_config.h"
 
25
 
 
26
#include <stdio.h>
 
27
 
 
28
#include "bsearch_xt.h"
 
29
#include "pthread_xt.h"
 
30
#include "thread_xt.h"
 
31
 
 
32
/**
 
33
 * Binary search a array of 'count' items, with byte size 'size'. This
 
34
 * function returns a pointer to the element and the 'index'
 
35
 * of the element if found.
 
36
 *
 
37
 * If not found the index of the insert point of the item
 
38
 * is returned (0 <= index <= count).
 
39
 *
 
40
 * The comparison routine 'compar' may throw an exception.
 
41
 * In this case the error details will be stored in 'thread'.
 
42
 */
 
43
void *xt_bsearch(XTThreadPtr thread, const void *key, register const void *base, size_t count, size_t size, size_t *idx, const void *thunk, XTCompareFunc compar)
 
44
{
 
45
        register size_t         i;
 
46
        register size_t         guess;
 
47
        register int            r;
 
48
 
 
49
        i = 0;
 
50
        while (i < count) {
 
51
                guess = (i + count - 1) >> 1;
 
52
                r = (compar)(thread, thunk, key, ((char *) base) + guess * size);
 
53
                if (r == 0) {
 
54
                        *idx = guess;
 
55
                        return ((char *) base) + guess * size;
 
56
                }
 
57
                if (r < 0)
 
58
                        count = guess;
 
59
                else
 
60
                        i = guess + 1;
 
61
        }
 
62
 
 
63
        *idx = i;
 
64
        return NULL;
 
65
}
 
66