Commit Graph

10 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
b8fe6bf0f5 Add a MapCursor::value_mut() method.
It's ok to alter a value stored in a map, but not the keys.
2017-12-05 15:07:28 -08:00
Jakob Stoklund Olesen
c64428b698 Add a Map::get_or_less() method.
Find the largest (k,v) pair with k <= key.
2017-12-05 15:07:28 -08:00
Jakob Stoklund Olesen
a960730add Add retain() methods to bforest::{Set,Map}.
These work just like their counterparts in HashMap and HashSet.
2017-11-22 13:43:41 -08:00
Jakob Stoklund Olesen
2e0b931590 Provide an fmt::Debug impl for entity references.
Instead of deriving a Debug impl: Ebb(45), use the Display version for
Debug too: ebb45.

This is more readable, and no information is lost.
2017-11-21 10:01:55 -08:00
Jakob Stoklund Olesen
2d7b54373f Implement Clone and Default for bforest::{Set,Map}.
The default container is empty. We need a manual implementation of
Default because deriving it seems to imply that K and V generic
parameter types must also implement Default.

Cloning can be used to clone an empty container or for cloning the whole
forest. We can derive this trait because we already require Copy for K
and V.
2017-11-20 15:06:00 -08:00
Jakob Stoklund Olesen
8eaf7d3904 Add iterators for bforest::{Set,Map}.
The iter() methods return an iterator that traverses all set elements /
map key-value pairs. The iterator doesn't require a mutable container
and forest reference, unlike the cursor types.
2017-11-20 14:20:19 -08:00
Jakob Stoklund Olesen
a2ff2a6836 Add goto_first() methods to SetCursor and MapCursor. 2017-11-20 14:16:39 -08:00
Jakob Stoklund Olesen
3389eaef29 Add a clear() method to bforest::{Set,Map}.
This is a lot more efficient that removing entries one by one.
2017-11-20 14:16:19 -08:00
Jakob Stoklund Olesen
d3778e56bb Remove the "BPlus" prefix from bforest::* types.
We'll just use the bforest:: namespace for these types, avoiding the
confusing mix of prefixed and non-prefixed names.

No functional change intended.
2017-11-20 14:15:56 -08:00
Jakob Stoklund Olesen
aa6f5c0db3 Forests of B+ trees.
Add new ordered set and map data structures based on B+-trees. These are
not general-purpose data structures like the BTreeSet and BTreeMap types
in the standard library. They are specialized for:

- Keys and values are small `Copy` types, optimized for 32-bit entities.
- Each set or map has a very small footprint, using only 32 bits of
  memory when empty.
- Keys are compared using a borrowed comparator object which can provide
  context for comparing tiny types that don't contain enough information
  to implement `Ord`.
- A whole forest of B-trees can be cleared in constant time without
  having to traverse the whole data structure.
2017-11-17 07:21:19 -08:00