]>
git.saurik.com Git - apt.git/blob - triehash/tests/test-basic
2 .
$(dirname $(readlink -f $0))/framework.sh
4 # Check for non-existing files
5 testfailure triehash
-C /does
/not
/exist1
-H /does
/not
/exist1
/does
/not
/exist
/input
7 # Check that we can specify - for -C and -H
8 testsuccessequal
"#ifndef TRIE_HASH_PerfectHash
9 #define TRIE_HASH_PerfectHash
15 static enum PerfectKey PerfectHash(const char *string, size_t length);
16 static enum PerfectKey PerfectHash(const char *string, size_t length)
23 #endif /* TRIE_HASH_PerfectHash */" triehash
--multi-byte=0 -C - -H -
25 # Check that split files work
26 testsuccess triehash
-C test.c
-H test.h
--multi-byte=0
27 testfileequal
"#include \"test.h\"
28 enum PerfectKey PerfectHash(const char *string, size_t length)
35 testfileequal
"#ifndef TRIE_HASH_PerfectHash
36 #define TRIE_HASH_PerfectHash
42 enum PerfectKey PerfectHash(const char *string, size_t length);
43 #endif /* TRIE_HASH_PerfectHash */" test.h
46 # Check the C code generator
47 testsuccess triehash
-C test.c
-H test.c
/dev
/stdin
48 testfileequal
"#ifndef TRIE_HASH_PerfectHash
49 #define TRIE_HASH_PerfectHash
59 static enum PerfectKey PerfectHash(const char *string, size_t length);
61 typedef uint16_t __attribute__((aligned (1))) triehash_uu16;
62 typedef char static_assert16[__alignof__(triehash_uu16) == 1 ? 1 : -1];
63 typedef uint32_t __attribute__((aligned (1))) triehash_uu32;
64 typedef char static_assert32[__alignof__(triehash_uu32) == 1 ? 1 : -1];
65 typedef uint64_t __attribute__((aligned (1))) triehash_uu64;
66 typedef char static_assert64[__alignof__(triehash_uu64) == 1 ? 1 : -1];
67 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
68 #define onechar(c, s, l) (((uint64_t)(c)) << (s))
70 #define onechar(c, s, l) (((uint64_t)(c)) << (l-8-s))
72 #if (!defined(__ARM_ARCH) || defined(__ARM_FEATURE_UNALIGNED)) && !defined(TRIE_HASH_NO_MULTI_BYTE)
73 #define TRIE_HASH_MULTI_BYTE
76 #ifdef TRIE_HASH_MULTI_BYTE
77 static enum PerfectKey PerfectHash4(const char *string)
79 switch(*((triehash_uu32*) &string[0])) {
80 case 0| onechar('W', 0, 32)| onechar('o', 8, 32)| onechar('r', 16, 32)| onechar('d', 24, 32):
85 static enum PerfectKey PerfectHash5(const char *string)
87 switch(*((triehash_uu32*) &string[0])) {
88 case 0| onechar('W', 0, 32)| onechar('o', 8, 32)| onechar('r', 16, 32)| onechar('d', 24, 32):
90 case 0| onechar('2', 0, 8):
96 static enum PerfectKey PerfectHash7(const char *string)
98 switch(*((triehash_uu32*) &string[0])) {
99 case 0| onechar('W', 0, 32)| onechar('o', 8, 32)| onechar('r', 16, 32)| onechar('d', 24, 32):
101 case 0| onechar('-', 0, 8):
103 case 0| onechar('_', 0, 8):
105 case 0| onechar('0', 0, 8):
113 static enum PerfectKey PerfectHash12(const char *string)
115 switch(*((triehash_uu64*) &string[0])) {
116 case 0| onechar('V', 0, 64)| onechar('e', 8, 64)| onechar('r', 16, 64)| onechar('y', 24, 64)| onechar('L', 32, 64)| onechar('o', 40, 64)| onechar('n', 48, 64)| onechar('g', 56, 64):
117 switch(*((triehash_uu32*) &string[8])) {
118 case 0| onechar('W', 0, 32)| onechar('o', 8, 32)| onechar('r', 16, 32)| onechar('d', 24, 32):
125 static enum PerfectKey PerfectHash4(const char *string)
142 static enum PerfectKey PerfectHash5(const char *string)
162 static enum PerfectKey PerfectHash7(const char *string)
188 static enum PerfectKey PerfectHash12(const char *string)
229 #endif /* TRIE_HASH_MULTI_BYTE */
230 static enum PerfectKey PerfectHash(const char *string, size_t length)
234 return PerfectHash4(string);
236 return PerfectHash5(string);
238 return PerfectHash7(string);
240 return PerfectHash12(string);
245 #endif /* TRIE_HASH_PerfectHash */" test.c