whistlepig 0.9.1 → 0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README +40 -12
- data/ext/whistlepig/extconf.rb +1 -1
- data/ext/whistlepig/index.c +201 -62
- data/ext/whistlepig/index.h +11 -2
- data/ext/whistlepig/lock.c +153 -0
- data/ext/whistlepig/lock.h +18 -0
- data/ext/whistlepig/mmap-obj.c +36 -20
- data/ext/whistlepig/mmap-obj.h +12 -7
- data/ext/whistlepig/search.c +7 -6
- data/ext/whistlepig/segment.c +97 -47
- data/ext/whistlepig/segment.h +19 -3
- data/ext/whistlepig/stringmap.c +61 -56
- data/ext/whistlepig/stringmap.h +7 -14
- data/ext/whistlepig/termhash.c +60 -62
- data/ext/whistlepig/termhash.h +4 -6
- data/ext/whistlepig/whistlepig.c +5 -1
- data/ext/whistlepig/whistlepig.h +1 -0
- metadata +29 -38
- data/ext/whistlepig/dump.c +0 -65
- data/ext/whistlepig/extconf.h +0 -3
- data/ext/whistlepig/test-segment.c +0 -404
- data/ext/whistlepig/test-stringmap.c +0 -82
- data/ext/whistlepig/test-stringpool.c +0 -67
- data/ext/whistlepig/test-termhash.c +0 -95
- data/ext/whistlepig/test-tokenizer.c +0 -55
- data/ext/whistlepig/test.h +0 -38
- data/ext/whistlepig/timer.h +0 -28
@@ -1,67 +0,0 @@
|
|
1
|
-
#include <string.h>
|
2
|
-
#include "stringpool.h"
|
3
|
-
#include "error.h"
|
4
|
-
#include "test.h"
|
5
|
-
|
6
|
-
TEST(stringpool_initial_state) {
|
7
|
-
stringpool* p = malloc(stringpool_initial_size());
|
8
|
-
stringpool_init(p);
|
9
|
-
|
10
|
-
ASSERT(!stringpool_needs_bump(p));
|
11
|
-
|
12
|
-
free(p);
|
13
|
-
return NO_ERROR;
|
14
|
-
}
|
15
|
-
|
16
|
-
TEST(stringpool_add_gives_unique_ids) {
|
17
|
-
stringpool* p = malloc(stringpool_initial_size());
|
18
|
-
stringpool_init(p);
|
19
|
-
|
20
|
-
uint32_t ret1 = stringpool_add(p, "potato");
|
21
|
-
ASSERT(ret1 > 0);
|
22
|
-
|
23
|
-
uint32_t ret2 = stringpool_add(p, "monkey");
|
24
|
-
ASSERT(ret2 > 0);
|
25
|
-
|
26
|
-
ASSERT(ret1 != ret2);
|
27
|
-
|
28
|
-
free(p);
|
29
|
-
return NO_ERROR;
|
30
|
-
}
|
31
|
-
|
32
|
-
TEST(stringpool_add_gives_ids_that_lookup_returns) {
|
33
|
-
stringpool* p = malloc(stringpool_initial_size());
|
34
|
-
stringpool_init(p);
|
35
|
-
|
36
|
-
uint32_t ret;
|
37
|
-
char* s;
|
38
|
-
|
39
|
-
ret = stringpool_add(p, "potato");
|
40
|
-
s = stringpool_lookup(p, ret);
|
41
|
-
ASSERT(!strcmp(s, "potato"));
|
42
|
-
|
43
|
-
ret = stringpool_add(p, "monkey");
|
44
|
-
s = stringpool_lookup(p, ret);
|
45
|
-
ASSERT(!strcmp(s, "monkey"));
|
46
|
-
|
47
|
-
free(p);
|
48
|
-
return NO_ERROR;
|
49
|
-
}
|
50
|
-
|
51
|
-
TEST(stringpool_detects_out_of_room) {
|
52
|
-
stringpool* p = malloc(stringpool_initial_size());
|
53
|
-
stringpool_init(p);
|
54
|
-
|
55
|
-
uint32_t ret;
|
56
|
-
int times = stringpool_initial_size() / 6;
|
57
|
-
for(int i = 0; i < times - 1; i++) {
|
58
|
-
ret = stringpool_add(p, "12345");
|
59
|
-
ASSERT(ret != (uint32_t)-1);
|
60
|
-
}
|
61
|
-
|
62
|
-
ret = stringpool_add(p, "12345");
|
63
|
-
ASSERT(ret == (uint32_t)-1);
|
64
|
-
|
65
|
-
return NO_ERROR;
|
66
|
-
}
|
67
|
-
|
@@ -1,95 +0,0 @@
|
|
1
|
-
#include "termhash.h"
|
2
|
-
#include "test.h"
|
3
|
-
#include "error.h"
|
4
|
-
|
5
|
-
TEST(termhash_initial_state) {
|
6
|
-
termhash* h = malloc(termhash_initial_size());
|
7
|
-
termhash_init(h);
|
8
|
-
|
9
|
-
ASSERT(h->n_occupied == 0);
|
10
|
-
//ASSERT(!termhash_getting_full(h));
|
11
|
-
|
12
|
-
free(h);
|
13
|
-
return NO_ERROR;
|
14
|
-
}
|
15
|
-
|
16
|
-
TEST(termhash_lookups_on_empty) {
|
17
|
-
termhash* h = malloc(termhash_initial_size());
|
18
|
-
termhash_init(h);
|
19
|
-
|
20
|
-
term t1 = {0, 0};
|
21
|
-
term t2 = {10, 20};
|
22
|
-
term t3 = {123, 345};
|
23
|
-
|
24
|
-
ASSERT(termhash_get_val(h, t1) == (uint32_t)-1);
|
25
|
-
ASSERT(termhash_get_val(h, t2) == (uint32_t)-1);
|
26
|
-
ASSERT(termhash_get_val(h, t3) == (uint32_t)-1);
|
27
|
-
|
28
|
-
free(h);
|
29
|
-
return NO_ERROR;
|
30
|
-
}
|
31
|
-
|
32
|
-
TEST(termhash_overwriting) {
|
33
|
-
termhash* h = malloc(termhash_initial_size());
|
34
|
-
termhash_init(h);
|
35
|
-
|
36
|
-
term t1 = {5, 11};
|
37
|
-
|
38
|
-
ASSERT(termhash_get_val(h, t1) == (uint32_t)-1);
|
39
|
-
RELAY_ERROR(termhash_put_val(h, t1, 1234));
|
40
|
-
ASSERT(termhash_get_val(h, t1) == 1234);
|
41
|
-
|
42
|
-
RELAY_ERROR(termhash_put_val(h, t1, 2345));
|
43
|
-
ASSERT(termhash_get_val(h, t1) == 2345);
|
44
|
-
|
45
|
-
RELAY_ERROR(termhash_put_val(h, t1, 1));
|
46
|
-
ASSERT(termhash_get_val(h, t1) == 1);
|
47
|
-
|
48
|
-
free(h);
|
49
|
-
return NO_ERROR;
|
50
|
-
}
|
51
|
-
|
52
|
-
TEST(termhash_many_puts) { // try and force a resize
|
53
|
-
termhash* h = malloc(termhash_initial_size());
|
54
|
-
termhash_init(h);
|
55
|
-
|
56
|
-
term t1 = {1, 0};
|
57
|
-
|
58
|
-
for(int i = 1; i < 100; i++) {
|
59
|
-
t1.word_s = i;
|
60
|
-
RELAY_ERROR(termhash_put_val(h, t1, 1000 + i));
|
61
|
-
if(termhash_needs_bump(h)) {
|
62
|
-
h = realloc(h, termhash_next_size(h));
|
63
|
-
if(h == NULL) RAISE_SYSERROR("realloc");
|
64
|
-
termhash_setup(h);
|
65
|
-
RELAY_ERROR(termhash_bump_size(h));
|
66
|
-
}
|
67
|
-
}
|
68
|
-
|
69
|
-
t1.word_s = 55;
|
70
|
-
uint32_t v = termhash_get_val(h, t1);
|
71
|
-
ASSERT(v == 1055);
|
72
|
-
|
73
|
-
free(h);
|
74
|
-
return NO_ERROR;
|
75
|
-
}
|
76
|
-
|
77
|
-
TEST(termhash_detects_out_of_room) {
|
78
|
-
termhash* h = malloc(termhash_initial_size());
|
79
|
-
termhash_init(h);
|
80
|
-
|
81
|
-
term t = {1, 0};
|
82
|
-
|
83
|
-
for(int i = 0; i < 3; i++) {
|
84
|
-
t.word_s = i;
|
85
|
-
RELAY_ERROR(termhash_put_val(h, t, 100 + i));
|
86
|
-
}
|
87
|
-
|
88
|
-
t.word_s = 999;
|
89
|
-
wp_error* e = termhash_put_val(h, t, 999);
|
90
|
-
ASSERT(e != NULL);
|
91
|
-
wp_error_free(e);
|
92
|
-
|
93
|
-
free(h);
|
94
|
-
return NO_ERROR;
|
95
|
-
}
|
@@ -1,55 +0,0 @@
|
|
1
|
-
#include "test.h"
|
2
|
-
#include "tokenizer.lex.h"
|
3
|
-
|
4
|
-
#define ASSERT_NEXT_WORD(word) { \
|
5
|
-
int token_type = yylex(scanner); \
|
6
|
-
ASSERT(token_type == TOK_WORD); \
|
7
|
-
ASSERT(!strcmp(word, yyget_text(scanner))); \
|
8
|
-
}
|
9
|
-
|
10
|
-
#define ASSERT_DONE { \
|
11
|
-
int token_type = yylex(scanner); \
|
12
|
-
ASSERT(token_type == TOK_DONE); \
|
13
|
-
}
|
14
|
-
|
15
|
-
TEST(tokenizes_easy_words) {
|
16
|
-
yyscan_t scanner;
|
17
|
-
lexinfo charpos = {0, 0};
|
18
|
-
|
19
|
-
yylex_init_extra(&charpos, &scanner);
|
20
|
-
|
21
|
-
const char* string = "i love mice";
|
22
|
-
YY_BUFFER_STATE state = yy_scan_string(string, scanner);
|
23
|
-
|
24
|
-
ASSERT_NEXT_WORD("i");
|
25
|
-
ASSERT_NEXT_WORD("love");
|
26
|
-
ASSERT_NEXT_WORD("mice");
|
27
|
-
ASSERT_DONE;
|
28
|
-
|
29
|
-
yy_delete_buffer(state, scanner);
|
30
|
-
yylex_destroy(scanner);
|
31
|
-
|
32
|
-
return NO_ERROR;
|
33
|
-
}
|
34
|
-
|
35
|
-
TEST(strips_trailing_punctuation) {
|
36
|
-
yyscan_t scanner;
|
37
|
-
lexinfo charpos = {0, 0};
|
38
|
-
|
39
|
-
yylex_init_extra(&charpos, &scanner);
|
40
|
-
|
41
|
-
const char* string = "hey! this: you're <cool>";
|
42
|
-
YY_BUFFER_STATE state = yy_scan_string(string, scanner);
|
43
|
-
|
44
|
-
ASSERT_NEXT_WORD("hey");
|
45
|
-
ASSERT_NEXT_WORD("this");
|
46
|
-
ASSERT_NEXT_WORD("you're");
|
47
|
-
ASSERT_NEXT_WORD("cool");
|
48
|
-
ASSERT_DONE;
|
49
|
-
|
50
|
-
yy_delete_buffer(state, scanner);
|
51
|
-
yylex_destroy(scanner);
|
52
|
-
|
53
|
-
return NO_ERROR;
|
54
|
-
}
|
55
|
-
|
data/ext/whistlepig/test.h
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
#ifndef WP_TEST_H_
|
2
|
-
#define WP_TEST_H_
|
3
|
-
|
4
|
-
// whistlepig test header file
|
5
|
-
// (c) 2011 William Morgan. See COPYING for license terms.
|
6
|
-
//
|
7
|
-
// macros for the c unit tests
|
8
|
-
|
9
|
-
#define ASSERT(x) do { \
|
10
|
-
(*asserts)++; \
|
11
|
-
if(!(x)) { \
|
12
|
-
printf("-- test failure: (" #x ") is FALSE in %s (%s:%d)\n\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); \
|
13
|
-
*fail = 1; \
|
14
|
-
return NO_ERROR; \
|
15
|
-
} \
|
16
|
-
} while(0)
|
17
|
-
|
18
|
-
#define TEST(x) wp_error* test_##x(int* fail, int* asserts)
|
19
|
-
|
20
|
-
#define RUNTEST(x) do { \
|
21
|
-
int fail = 0; \
|
22
|
-
int this_asserts = 0; \
|
23
|
-
tests++; \
|
24
|
-
wp_error* err = test_##x(&fail, &this_asserts); \
|
25
|
-
asserts += this_asserts; \
|
26
|
-
if(fail) { \
|
27
|
-
printf("FAIL " #x "\n"); \
|
28
|
-
failures++; \
|
29
|
-
} \
|
30
|
-
else if(err) { \
|
31
|
-
errors++; \
|
32
|
-
printf(" ERR " #x "\n"); \
|
33
|
-
PRINT_ERROR(err, stdout); \
|
34
|
-
} \
|
35
|
-
else printf("PASS %d/%d " #x "\n", this_asserts, this_asserts); \
|
36
|
-
} while(0)
|
37
|
-
|
38
|
-
#endif
|
data/ext/whistlepig/timer.h
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
#ifndef WP_TIMER_H_
|
2
|
-
#define WP_TIMER_H_
|
3
|
-
|
4
|
-
// whistlepig main header file
|
5
|
-
// (c) 2011 William Morgan. See COPYING for license terms.
|
6
|
-
//
|
7
|
-
// just some timer macros
|
8
|
-
|
9
|
-
#include <sys/time.h>
|
10
|
-
|
11
|
-
#define TIMER(name) \
|
12
|
-
struct timeval name##_startt, name##_endt; \
|
13
|
-
long name##_elapsed;
|
14
|
-
|
15
|
-
#define START_TIMER(name) \
|
16
|
-
TIMER(name) \
|
17
|
-
gettimeofday(&name##_startt, NULL);
|
18
|
-
|
19
|
-
#define RESET_TIMER(name) gettimeofday(&name##_startt, NULL);
|
20
|
-
|
21
|
-
#define MARK_TIMER(name) \
|
22
|
-
gettimeofday(&name##_endt, NULL); \
|
23
|
-
name##_elapsed = ((name##_endt.tv_sec - name##_startt.tv_sec) * 1000) + ((name##_endt.tv_usec - name##_startt.tv_usec) / 1000);
|
24
|
-
|
25
|
-
#define TIMER_MS(name) name##_elapsed
|
26
|
-
#define TIMER_MS(name) name##_elapsed
|
27
|
-
|
28
|
-
#endif
|