PostgreSQL Source Code: src/port/bsearch_arg.c Source File (original) (raw)

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36#include "c.h"

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54void *

56 size_t nmemb, size_t size,

57 int (*compar) (const void *, const void *, void *),

58 void *arg)

59{

60 const char *base = (const char *) base0;

61 size_t lim;

63 const void *p;

64

65 for (lim = nmemb; lim != 0; lim >>= 1)

66 {

67 p = base + (lim >> 1) * size;

69 if (cmp == 0)

70 return (void *) p;

71 if (cmp > 0)

72 {

73 base = (const char *) p + size;

74 lim--;

75 }

76 }

77 return (NULL);

78}

void * bsearch_arg(const void *key, const void *base0, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg)

static int cmp(const chr *x, const chr *y, size_t len)