aboutsummaryrefslogtreecommitdiff
path: root/src/tests/itoheap.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2008-02-19 21:51:48 +0000
committerMike Buland <eichlan@xagasoft.com>2008-02-19 21:51:48 +0000
commita4c22303b1044eee5ccbf0766895a879a8f4810e (patch)
treebe6563dfca81f57e4883a55c4517f5878c40dd4e /src/tests/itoheap.cpp
parent62287ea894a1587553f017d0f6a09d4c87ad3b1f (diff)
downloadlibbu++-a4c22303b1044eee5ccbf0766895a879a8f4810e.tar.gz
libbu++-a4c22303b1044eee5ccbf0766895a879a8f4810e.tar.bz2
libbu++-a4c22303b1044eee5ccbf0766895a879a8f4810e.tar.xz
libbu++-a4c22303b1044eee5ccbf0766895a879a8f4810e.zip
Oops. I made the Bu::Heap API look like a stack, not a queue, that's been
fixed, and the Bu::ItoHeap is working and tested. Note that when multiple items have the same sort order, they will come out in random order.
Diffstat (limited to 'src/tests/itoheap.cpp')
-rw-r--r--src/tests/itoheap.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp
new file mode 100644
index 0000000..67169e7
--- /dev/null
+++ b/src/tests/itoheap.cpp
@@ -0,0 +1,64 @@
1#include <stdio.h>
2#include <stdlib.h>
3
4#include "bu/itoheap.h"
5#include "bu/ito.h"
6
7class Consumer : public Bu::Ito
8{
9public:
10 Consumer()
11 {
12 }
13
14 virtual ~Consumer()
15 {
16 }
17
18 void *run()
19 {
20 for( int j = 0; j < 10; j++ )
21 {
22 printf("Trying to read [%d].\n", j );
23
24 try
25 {
26 int iNum = hInt.dequeue( 0, 500000 );
27 printf("Read %d\n", iNum );
28 }
29 catch( Bu::HeapException &e )
30 {
31 printf("Nothing yet...\n");
32 }
33 }
34
35 return NULL;
36 }
37
38 Bu::ItoHeap<int> hInt;
39};
40
41
42int main()
43{
44 Consumer c;
45
46 for( int j = 0; j < 3; j++ )
47 {
48 int iNum = rand()%10;
49 printf("Enqueuing %d.\n", iNum );
50 c.hInt.enqueue( iNum );
51 }
52
53 printf("Sarting consumer.\n");
54 c.start();
55
56 for( int j = 0; j < 5; j++ )
57 {
58 sleep( 1 );
59 int iNum = rand()%10;
60 printf("Enqueuing %d.\n", iNum );
61 c.hInt.enqueue( iNum );
62 }
63}
64