9 Commits

Author SHA1 Message Date
joaquintides
7c591a13aa
improved performance of count in ranked indices (#56)
* count for ranked_index uses rank

Normally, count is calculated as the distance between iterators,
which takes linear time when count(x,comp) is comparable with n,
but for ranked indices we can subtract the values or rank,
reducing the complexity from log(n)+count(x,comp) to log(n).

* Added test for new count(x) and count(x,comp) in ranked_index

Both, the existing implementation of count from ordered_index and
the new implementation for ranked_index are compared with the
common sense. Positive results of this test show in particular that
the numbers produced by the new implementation are consistent with
those from the existing implementation and hence correct.

* Benchmark of count(): ordered_index vs ranked_index

A benchmark is added as count_benchmark.cpp in the 'example'
directory.

When the values of an index are unique, both implementations are
comparable (ranked_index is 10-15% faster).

However, for highly non-unique indices (like the age of people),
the new implementation in ranked_index outperforms ordered_index.
For 1 000 people of age in 0..99 ranked_index is ~2x faster,
for 10 000 people it is 12-13x faster, and
for 100 000 people it is 95-100x times faster.

For even more non-unique indices (like sex or the age of pupils)
or coarse comparison predicates (grouping people in age groups
like 0..9, 10..19 etc.) the gap in performance grows further.
For a comparison predicate comparing 'age/10' for age in 0..99,
similar gaps in performance occur already for 10x smaller
containers:
for 100 people count in ranked_index is 2x faster,
for 1 000 people it is ~9x faster,
for 10 000 people it is 95-100x faster,
for 100 000 people it is almost 1000x faster.

* Documentation updated with new complexity of count in ranked_index

* simplified Damian's contribution

* reorganized code

* covered ranked_index::count

* updated docs

Co-authored-by: DamianSawicki <86234282+DamianSawicki@users.noreply.github.com>
2022-02-05 12:59:43 +01:00
joaquintides
5623d2b9e2 added contains (#35) 2021-07-29 12:04:15 +02:00
joaquintides
71fd63ce7a extended lookup efficiency improvement technique to (pointer to) function types 2014-11-02 19:02:34 +01:00
joaquintides
79541fce51 improved lookup efficiency in the event of implicit conversion to key_type 2014-11-01 15:24:31 +01:00
Joaquín M López Muñoz
0f583940c9 merged [82897], [82970] and [82993] from trunk
[SVN r83003]
2013-02-19 14:49:33 +00:00
Joaquín M López Muñoz
bd8ea1bc86 merged up to rev. 47041 from trunk
[SVN r47045]
2008-07-03 16:51:53 +00:00
Joaquín M. López Muñoz
d5835caad6 changes to cover hashed indices
[SVN r27858]
2005-03-28 13:03:52 +00:00
Joaquín M. López Muñoz
eb2a1dbca3 license update
[SVN r22959]
2004-05-28 08:06:41 +00:00
Joaquín M. López Muñoz
b35bef74e4 initial commit
[SVN r22759]
2004-05-07 10:44:23 +00:00