Skip to content

Commit 0274d21

Browse files
committed
WIP add btree_set
with node size of 256, as in abseil. also using similar tricks as abseil, using much less memory per node.
1 parent 81b0e17 commit 0274d21

File tree

7 files changed

+1507
-40
lines changed

7 files changed

+1507
-40
lines changed

GNUmakefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ TESTS = \
144144

145145
ifneq ($(DEBUG),)
146146
TESTS += \
147-
tests/func/test_map \
147+
tests/func/test_btree_set \
148+
tests/func/test_btree_map \
149+
tests/func/test_map \
148150
tests/func/test_unordered_map
149151
endif
150152

@@ -186,6 +188,7 @@ perf: $(PERFS_C) $(PERFS_CC) tests/perf/arr/perf_arr_generate
186188

187189
$(wildcard tests/perf/lst/perf*.cc?) : $(COMMON_H) ctl/list.h
188190
$(wildcard tests/perf/set/perf*.cc?) : $(COMMON_H) ctl/set.h
191+
$(wildcard tests/perf/btset/perf*.cc?) : $(COMMON_H) ctl/btree_set.h
189192
$(wildcard tests/perf/deq/perf*.cc?) : $(COMMON_H) ctl/deque.h
190193
$(wildcard tests/perf/pqu/perf*.cc?) : $(COMMON_H) ctl/priority_queue.h
191194
$(wildcard tests/perf/vec/perf*.cc?) : $(COMMON_H) ctl/vector.h
@@ -288,6 +291,8 @@ ctl/string.i:
288291
$(call expand,$(subst .i,,$@))
289292
ctl/map.i:
290293
$(call expand,$(subst .i,,$@),-DT=strint -DPOD)
294+
ctl/btree_map.i:
295+
$(call expand,$(subst .i,,$@),-DT=strint -DPOD)
291296
ctl/unordered_map.i:
292297
$(call expand,$(subst .i,,$@),-DT=strint -DPOD)
293298
ctl/array.i:
@@ -324,7 +329,11 @@ tests/func/test_queue: .cflags $(COMMON_H) tests/test.h tests/func/digi.hh ct
324329
tests/func/test_set: .cflags $(COMMON_H) tests/test.h tests/func/digi.hh ctl/set.h \
325330
tests/func/test_set.cc
326331
$(CXX) $(CXXFLAGS) -o $@ $@.cc
327-
tests/func/test_map: .cflags $(H) tests/test.h tests/func/strint.hh ctl/set.h ctl/map.h tests/func/test_map.cc
332+
tests/func/test_btree_set: .cflags $(COMMON_H) tests/test.h tests/func/digi.hh ctl/btree_set.h \
333+
tests/func/test_btree_set.cc
334+
$(CXX) $(CXXFLAGS) -o $@ $@.cc
335+
tests/func/test_map: .cflags $(H) tests/test.h tests/func/strint.hh \
336+
tests/func/test_map.cc
328337
$(CXX) $(CXXFLAGS) -o $@ $@.cc
329338
tests/func/test_unordered_set: .cflags $(COMMON_H) ctl/unordered_set.h \
330339
tests/func/test_unordered_set.cc

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ all containers in ISO C99/C11:
6161
| [ctl/map.h](docs/map.md) | std::map | map |
6262
| [ctl/unordered_map.h](docs/unordered_map.md) | std::unordered_map | umap |
6363
| [ctl/unordered_set.h](docs/unordered_set.md) | std::unordered_set | uset |
64+
| [ctl/btree_set.h](docs/btree_set.md) | absl::btree_set | btset |
65+
| [ctl/btree_map.h](docs/btree_map.md) | absl::btree_map | btmap |
6466
|------------------------------------------------|----------------------|
6567
| [ctl/algorithm.h](docs/algorithm.md) | `<algorithm>` |
6668
| [ctl/numeric.h](docs/numeric.md) | `<numeric>` |
@@ -359,7 +361,6 @@ And in its grandiosity (esp. not header-only):
359361

360362
## Base Implementation Details
361363

362-
363364
array.h: stack/heap allocated
364365
vector.h: realloc
365366
string.h: vector.h
@@ -371,6 +372,8 @@ And in its grandiosity (esp. not header-only):
371372
forward_list.h: single linked list
372373
set.h: red black tree
373374
map.h: set.h
375+
btree_set.h: b-tree
376+
btree_map.h: - " -
374377
unordered_set.h: hashed forward linked lists
375378
unordered_map.h: unordered_set.h (pair in work)
376379
hashmap.h: stanford hash for integer keys, intel only.

0 commit comments

Comments
 (0)