Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F45714482
rb_time.c
dougm (Doug Moore)
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
dougm
Jul 28 2022, 4:38 AM
2022-07-28 04:38:34 (UTC+0)
Size
962 B
Referenced Files
None
Subscribers
None
rb_time.c
View Options
#include
<stdio.h>
#include
<stdlib.h>
struct
map_entry
;
#include
"../../../sys/sys/tree.h"
RB_HEAD
(
entries_tree
,
map_entry
);
RB_PROTOTYPE
(
entries_tree
,
map_entry
,
rb_entry
,
cmp_entries
);
struct
map_entry
{
RB_ENTRY
(
map_entry
)
rb_entry
;
unsigned
key
;
};
struct
entries_tree
rb_root
;
static
int
cmp_entries
(
struct
map_entry
*
a
,
struct
map_entry
*
b
)
{
return
(
b
->
key
<
a
->
key
)
-
(
a
->
key
<
b
->
key
);
}
RB_GENERATE
(
entries_tree
,
map_entry
,
rb_entry
,
cmp_entries
);
int
main
()
{
struct
map_entry
*
element
;
const
unsigned
maxval
=
65536
;
int
count
;
for
(
count
=
0
;
count
<
1000000000
;
++
count
)
{
unsigned
val
;
struct
map_entry
key
;
val
=
random
()
%
maxval
;
key
.
key
=
val
;
element
=
RB_FIND
(
entries_tree
,
&
rb_root
,
&
key
);
if
(
element
)
{
RB_REMOVE
(
entries_tree
,
&
rb_root
,
element
);
free
(
element
);
}
else
{
element
=
malloc
(
sizeof
(
*
element
));
element
->
key
=
val
;
RB_INSERT
(
entries_tree
,
&
rb_root
,
element
);
}
}
return
(
0
);
}
File Metadata
Details
Attached
Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
4999480
Default Alt Text
rb_time.c (962 B)
Attached To
Mode
D35963: rb_tree: balance interior node removal
Attached
Detach File
Event Timeline
Log In to Comment