PostgreSQL Source Code: src/test/modules/test_binaryheap/test_binaryheap.c Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

15

20

22

23

24

25

26static int

28{

30}

31

32

33

34

35static int

37{

38 int max = -1;

39

42

43 return max;

44}

45

46

47

48

49static int *

51{

52 int *permutation = (int *) palloc(size * sizeof(int));

53

54 permutation[0] = 0;

55

56

57

58

59

60

61

62

63 for (int i = 1; i < size; i++)

64 {

66

67 if (j < i)

68 permutation[i] = permutation[j];

69 permutation[j] = i;

70 }

71

72 return permutation;

73}

74

75

76

77

78

79static void

81{

83 {

84 int left = 2 * i + 1;

85 int right = 2 * i + 2;

87

90 elog(ERROR, "parent node less than left child");

91

94 elog(ERROR, "parent node less than right child");

95 }

96}

97

98

99

100

101static void

103{

106

108 elog(ERROR, "new heap not empty");

110 elog(ERROR, "wrong size for new heap");

111

112 for (int i = 0; i < size; i++)

113 {

116 }

117

119 elog(ERROR, "heap empty after adding values");

121 elog(ERROR, "wrong size for heap after adding values");

122

124 elog(ERROR, "incorrect root node after adding values");

125

126 for (int i = 0; i < size; i++)

127 {

130

131 if (actual != expected)

132 elog(ERROR, "incorrect root node after removing root");

134 }

135

137 elog(ERROR, "heap not empty after removing all nodes");

138}

139

140

141

142

143static void

145{

148

149 for (int i = 0; i < size; i++)

151

153 elog(ERROR, "wrong size for heap after unordered additions");

154

157}

158

159

160

161

162static void

164{

168 0, size - 1);

169

170 for (int i = 0; i < size; i++)

172

173 for (int i = 0; i < remove_count; i++)

174 {

177

180 }

181

183 elog(ERROR, "wrong size after removing nodes");

184}

185

186

187

188

189static void

191{

193

194 for (int i = 0; i < size; i++)

196

197

198

199

202

203

204

205

208

209

210

211

214}

215

216

217

218

219static void

221{

224

225 for (int i = 0; i < size; i++)

227

228 for (int i = 0; i < size; i++)

229 {

231 elog(ERROR, "unexpected value in heap with duplicates");

232 }

233}

234

235

236

237

238static void

240{

242

243 for (int i = 0; i < size; i++)

245

247

249 elog(ERROR, "heap not empty after resetting");

250}

251

252

253

254

256

259{

260 static const int test_sizes[] = {1, 2, 3, 10, 100, 1000};

261

262 for (int i = 0; i < sizeof(test_sizes) / sizeof(int); i++)

263 {

264 int size = test_sizes[i];

265

272 }

273

275}

Datum idx(PG_FUNCTION_ARGS)

void binaryheap_remove_node(binaryheap *heap, int n)

void binaryheap_build(binaryheap *heap)

void binaryheap_replace_first(binaryheap *heap, bh_node_type d)

void binaryheap_reset(binaryheap *heap)

bh_node_type binaryheap_first(binaryheap *heap)

void binaryheap_add(binaryheap *heap, bh_node_type d)

bh_node_type binaryheap_remove_first(binaryheap *heap)

void binaryheap_add_unordered(binaryheap *heap, bh_node_type d)

binaryheap * binaryheap_allocate(int capacity, binaryheap_comparator compare, void *arg)

#define binaryheap_size(h)

#define binaryheap_empty(h)

#define binaryheap_get_node(h, n)

static int pg_cmp_s32(int32 a, int32 b)

uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)

pg_prng_state pg_global_prng_state

static Datum Int32GetDatum(int32 X)

static int32 DatumGetInt32(Datum X)

static int int_cmp(Datum a, Datum b, void *arg)

Datum test_binaryheap(PG_FUNCTION_ARGS)

static int * get_permutation(int size)

static void test_reset(int size)

static int get_max_from_heap(binaryheap *heap)

static void verify_heap_property(binaryheap *heap)

static void test_remove_node(int size)

static void test_build(int size)

static void test_duplicates(int size)

static void test_basic(int size)

static void test_replace_first(int size)

PG_FUNCTION_INFO_V1(test_binaryheap)