Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::Range_Mode_Policy< T > Struct Template Reference

Policy: range mode (most frequent element). More...

#include <tpl_mo_algorithm.H>

Collaboration diagram for Aleph::Range_Mode_Policy< T >:
[legend]

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()
 

Detailed Description

template<typename T>
struct Aleph::Range_Mode_Policy< 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.

Note
When 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).
Template Parameters
TElement type (must be hashable).

Definition at line 498 of file tpl_mo_algorithm.H.

Member Typedef Documentation

◆ answer_type

template<typename T >
using Aleph::Range_Mode_Policy< T >::answer_type = std::pair<size_t, T>

Definition at line 500 of file tpl_mo_algorithm.H.

Member Function Documentation

◆ add()

◆ answer()

◆ init()

◆ remove()

Member Data Documentation

◆ cnt_of_cnt

◆ freq

◆ max_freq

◆ mode_val


The documentation for this struct was generated from the following file: