chunkedseq
container library for large in-memory data sets
|
The chunkedseq
containers can easily generalize to weighted containers. A weighted container is a container that assigns to each item in the container an integral weight value. The weight value is typically expressed as a weight function that is defined by the client and passed to the container via template argument.
The purpose of the weight is to enable the client to use the weighted-split operation, which divides the container into two pieces by a specified weight. The split operation takes only logarithmic time.
The following example program demonstrates how one can use weighted split to split a sequence of string values based on the number of even-length strings. In this case, our split divides the sequence into two pieces so that the first piece goes into d
and the second to f
. The split function specifies that d
is to receive the first half of the original sequence of strings that together contain half of the total number of even-length strings in the original sequence; f
is to receive the remaining strings. Because the lengths of the strings are cached internally by the weighted container, the split operation takes logarithmic time in the number of strings.
The program prints the following:
nb even strings: 6 d = Let's divide this f = sequence of strings into two pieces