|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Policy: range mode (most frequent element). More...
#include <tpl_mo_algorithm.H>
Public Types | |
| using | answer_type = std::pair< size_t, T > |
Public Member Functions | |
| void | init (const Array< T > &, size_t) |
| void | add (const Array< T > &data, size_t idx) |
| void | remove (const Array< T > &data, size_t idx) |
| answer_type | answer () const |
Public Attributes | |
| MapOLhash< T, size_t > | freq |
| MapOLhash< size_t, size_t > | cnt_of_cnt |
| size_t | max_freq = 0 |
| T | mode_val = T() |
Policy: range mode (most frequent element).
Tracks frequencies and uses a "count of counts" trick for O(1) mode maintenance. Returns {frequency, value} of the mode. Ties are broken arbitrarily.
max_freq decreases after a removal, this implementation linearly scans current distinct values to pick any valid mode representative. Aggregate Mo complexity is preserved, but a single remove may cost O(number of distinct values).| T | Element type (must be hashable). |
Definition at line 498 of file tpl_mo_algorithm.H.
Definition at line 500 of file tpl_mo_algorithm.H.
Definition at line 517 of file tpl_mo_algorithm.H.
References Aleph::Range_Mode_Policy< T >::cnt_of_cnt, Aleph::divide_and_conquer_partition_dp(), Aleph::Range_Mode_Policy< T >::freq, Aleph::Range_Mode_Policy< T >::max_freq, and Aleph::Range_Mode_Policy< T >::mode_val.
|
inline |
Definition at line 570 of file tpl_mo_algorithm.H.
References Aleph::Range_Mode_Policy< T >::max_freq, and Aleph::Range_Mode_Policy< T >::mode_val.
Definition at line 507 of file tpl_mo_algorithm.H.
References Aleph::Range_Mode_Policy< T >::cnt_of_cnt, Aleph::divide_and_conquer_partition_dp(), Aleph::Range_Mode_Policy< T >::freq, Aleph::Range_Mode_Policy< T >::max_freq, and Aleph::Range_Mode_Policy< T >::mode_val.
| MapOLhash<size_t, size_t> Aleph::Range_Mode_Policy< T >::cnt_of_cnt |
Definition at line 503 of file tpl_mo_algorithm.H.
Referenced by Aleph::Range_Mode_Policy< T >::add(), Aleph::Range_Mode_Policy< T >::init(), and Aleph::Range_Mode_Policy< T >::remove().
Definition at line 502 of file tpl_mo_algorithm.H.
Referenced by Aleph::Range_Mode_Policy< T >::add(), Aleph::Range_Mode_Policy< T >::init(), and Aleph::Range_Mode_Policy< T >::remove().
| size_t Aleph::Range_Mode_Policy< T >::max_freq = 0 |
Definition at line 504 of file tpl_mo_algorithm.H.
Referenced by Aleph::Range_Mode_Policy< T >::add(), Aleph::Range_Mode_Policy< T >::answer(), Aleph::Range_Mode_Policy< T >::init(), and Aleph::Range_Mode_Policy< T >::remove().
Definition at line 505 of file tpl_mo_algorithm.H.
Referenced by Aleph::Range_Mode_Policy< T >::add(), Aleph::Range_Mode_Policy< T >::answer(), Aleph::Range_Mode_Policy< T >::init(), and Aleph::Range_Mode_Policy< T >::remove().