Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F43773805
megatree.c
dougm (Doug Moore)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
dougm
Jun 22 2022, 4:47 AM
2022-06-22 04:47:02 (UTC+0)
Size
2 KB
Referenced Files
None
Subscribers
None
megatree.c
View Options
#include
<assert.h>
#include
<stdio.h>
#include
<stdlib.h>
//#include <sys/tree.h>
#include
<stdbool.h>
//#include <stdint.h>
#include
"freebsd/base/src/sys/sys/tree.h"
struct
item
{
RB_ENTRY
(
item
)
it_entry
;
int
val
;
};
static
int
item_cmp
(
struct
item
*
a
,
struct
item
*
b
)
{
return
a
->
val
<
b
->
val
?
-1
:
a
->
val
>
b
->
val
;
}
#define gen_tree(TREE) \
RB_HEAD(item_##TREE, item) TREE = RB_INITIALIZER(&TREE); \
RB_GENERATE_STATIC(item_##TREE, item, it_entry, item_cmp); \
\
static void \
use_##TREE(int count, int maxsize) \
{ \
struct item *ins; \
ins = malloc(sizeof(*ins)); \
ins->val = 2*count; \
if (RB_INSERT(item_##TREE, &TREE, ins) != NULL) \
free(ins); \
if (count >= maxsize) { \
struct item key; \
key.val = 2*(count - maxsize); \
struct item *found = RB_FIND(item_##TREE, &TREE, &key); \
if (found != NULL) { \
RB_REMOVE(item_##TREE, &TREE, found); \
free(found); \
} \
for (int i = 0; i < 10; ++i) { \
key.val = 2*(count - maxsize + 1 + i); \
found = RB_FIND(item_##TREE, &TREE, &key); \
if (!found) \
printf("uh-oh\n"); \
} \
} \
}
gen_tree
(
tree0
)
gen_tree
(
tree1
)
gen_tree
(
tree2
)
gen_tree
(
tree3
)
gen_tree
(
tree4
)
gen_tree
(
tree5
)
gen_tree
(
tree6
)
gen_tree
(
tree7
)
gen_tree
(
tree8
)
gen_tree
(
tree9
)
gen_tree
(
treeA
)
gen_tree
(
treeB
)
gen_tree
(
treeC
)
gen_tree
(
treeD
)
gen_tree
(
treeE
)
gen_tree
(
treeF
)
gen_tree
(
treeG
)
gen_tree
(
treeH
)
gen_tree
(
treeI
)
gen_tree
(
treeJ
)
gen_tree
(
treeK
)
gen_tree
(
treeL
)
gen_tree
(
treeM
)
gen_tree
(
treeN
)
gen_tree
(
treeO
)
gen_tree
(
treeP
)
gen_tree
(
treeQ
)
gen_tree
(
treeR
)
gen_tree
(
treeS
)
gen_tree
(
treeT
)
gen_tree
(
treeU
)
gen_tree
(
treeV
)
int
main
()
{
int
maxsize
=
100000
;
int
count
;
for
(
count
=
0
;
count
<
1500000
;
++
count
)
{
use_tree0
(
count
,
maxsize
);
use_tree1
(
count
,
maxsize
);
use_tree2
(
count
,
maxsize
);
use_tree3
(
count
,
maxsize
);
use_tree4
(
count
,
maxsize
);
use_tree5
(
count
,
maxsize
);
use_tree6
(
count
,
maxsize
);
use_tree7
(
count
,
maxsize
);
use_tree8
(
count
,
maxsize
);
use_tree9
(
count
,
maxsize
);
use_treeA
(
count
,
maxsize
);
use_treeB
(
count
,
maxsize
);
use_treeC
(
count
,
maxsize
);
use_treeD
(
count
,
maxsize
);
use_treeE
(
count
,
maxsize
);
use_treeF
(
count
,
maxsize
);
use_treeG
(
count
,
maxsize
);
use_treeH
(
count
,
maxsize
);
use_treeI
(
count
,
maxsize
);
use_treeJ
(
count
,
maxsize
);
use_treeK
(
count
,
maxsize
);
use_treeL
(
count
,
maxsize
);
use_treeM
(
count
,
maxsize
);
use_treeN
(
count
,
maxsize
);
use_treeO
(
count
,
maxsize
);
use_treeP
(
count
,
maxsize
);
use_treeQ
(
count
,
maxsize
);
use_treeR
(
count
,
maxsize
);
use_treeS
(
count
,
maxsize
);
use_treeT
(
count
,
maxsize
);
use_treeU
(
count
,
maxsize
);
use_treeV
(
count
,
maxsize
);
}
return
0
;
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4875200
Default Alt Text
megatree.c (2 KB)
Attached To
Mode
D35524: rb_tree: optimize bit twiddle
Attached
Detach File
Event Timeline
Log In to Comment