View Source exometer_shallowtree (exometer_core v1.7.1)
Size-constrained leftist tree Inspired by Leftist Trees by Sartaj Sahni.
The purpose of this module is to efficiently store a limited number of values in e.g. a lossy histogram (ex.exometer_slot_slide
). The complexity of insert operations is log(N), but once the tree is full, only values higher than the minimum value already in the tree will be inserted, and the old minimum is deleted - i.e. two O(log N) operations. For other values, the cost will be only two comparisons, since the top node in the tree always contains the minimum.
Summary
Functions
Insert value V
into tree T
.
Returns the maximum number of values for the given tree.
Create an empty tree limited to
Size
.Returns the number of values stored in the given tree.
Extract the smallest value from the tree T
.
Converts a tree to a list.
Types
Functions
Insert value V
into tree T
.
V
is smaller than the minimum, this function will return immediately, leaving the tree unchanged.
-spec limit(tree()) -> non_neg_integer().
-spec new(pos_integer()) -> tree().
Size
.
-spec size(tree()) -> non_neg_integer().
Extract the smallest value from the tree T
.
error
is returned, otherwise {Minimum, NewTree}
.
Converts a tree to a list.
The list will not be ordered, since the aim is to produce the list as quickly as possible. Also,lists:sort(to_list(Tree))
, if to_list/1 uses brute force, seems faster than most approaches for extracting values in order.