path: root/t/
diff options
authorJason Evans <>2010-08-09 22:17:34 (GMT)
committerJunio C Hamano <>2010-08-15 02:35:37 (GMT)
commit951f316470acc7c785c460a4e40735b22822349f (patch)
tree8cc846b9eead64502e00fc4064d5decfa1897320 /t/
parent4709455db3891f6cad9a96a574296b4926f70cbe (diff)
Add treap implementation
Provide macros to generate a type-specific treap implementation and various functions to operate on it. It uses obj_pool.h to store memory nodes in a treap. Previously committed nodes are never removed from the pool; after any *_commit operation, it is assumed (correctly, in the case of svn-fast-export) that someone else must care about them. Treaps provide a memory-efficient binary search tree structure. Insertion/deletion/search are about as about as fast in the average case as red-black trees and the chances of worst-case behavior are vanishingly small, thanks to (pseudo-)randomness. The bad worst-case behavior is a small price to pay, given that treaps are much simpler to implement. >From [db: Altered to reference nodes by offset from a common base pointer] [db: Bob Jenkins' hashing implementation dropped for Knuth's] [db: Methods unnecessary for search and insert dropped] [rr: Squelched compiler warnings] [db: Added support for immutable treap nodes] [jn: Reintroduced treap_nsearch(); with tests] Signed-off-by: David Barr <> Signed-off-by: Ramkumar Ramachandra <> Signed-off-by: Jonathan Nieder <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 't/')
1 files changed, 22 insertions, 0 deletions
diff --git a/t/ b/t/
index 3f29496..ce02c58 100755
--- a/t/
+++ b/t/
@@ -76,4 +76,26 @@ test_expect_success 'obj pool: high-water mark' '
test_cmp expected actual
+test_expect_success 'treap sort' '
+ cat <<-\EOF >unsorted &&
+ 68
+ 12
+ 13
+ 13
+ 68
+ 13
+ 13
+ 21
+ 10
+ 11
+ 12
+ 13
+ 13
+ sort unsorted >expected &&
+ test-treap <unsorted >actual &&
+ test_cmp expected actual