tesseract  5.0.0-alpha-619-ge9db
MinK< Key, Value > Class Template Reference

Classes

struct  Element
 

Public Member Functions

 MinK (Key max_key, int k)
 
 ~MinK ()
 
bool insert (Key k, Value v)
 
const Key & max_insertable_key ()
 
int elements_count ()
 
const Elementelements ()
 

Detailed Description

template<typename Key, typename Value>
class MinK< Key, Value >

Store the k smallest-keyed key-value pairs.

Definition at line 50 of file kdtree.cpp.

Constructor & Destructor Documentation

◆ MinK()

template<typename Key, typename Value >
MinK< Key, Value >::MinK ( Key  max_key,
int  k 
)

Definition at line 78 of file kdtree.cpp.

79  :
80  max_key_(max_key), elements_count_(0), k_(k < 1 ? 1 : k), max_index_(0) {
81  elements_ = new Element[k_];

◆ ~MinK()

template<typename Key , typename Value >
MinK< Key, Value >::~MinK ( )

Definition at line 84 of file kdtree.cpp.

85  {
86  delete []elements_;

Member Function Documentation

◆ elements()

template<typename Key, typename Value>
const Element* MinK< Key, Value >::elements ( )
inline

Definition at line 67 of file kdtree.cpp.

67 { return elements_count_; }

◆ elements_count()

template<typename Key, typename Value>
int MinK< Key, Value >::elements_count ( )
inline

Definition at line 66 of file kdtree.cpp.

67 { return elements_count_; }

◆ insert()

template<typename Key, typename Value>
bool MinK< Key, Value >::insert ( Key  k,
Value  v 
)

Definition at line 96 of file kdtree.cpp.

97  {
98  if (elements_count_ < k_) {
99  elements_[elements_count_++] = Element(key, value);
100  if (key > elements_[max_index_].key)
101  max_index_ = elements_count_ - 1;
102  return true;
103  } else if (key < elements_[max_index_].key) {
104  // evict the largest element.
105  elements_[max_index_] = Element(key, value);
106  // recompute max_index_
107  for (int i = 0; i < elements_count_; i++) {
108  if (elements_[i].key > elements_[max_index_].key)
109  max_index_ = i;
110  }
111  return true;
112  }
113  return false;

◆ max_insertable_key()

template<typename Key , typename Value >
const Key & MinK< Key, Value >::max_insertable_key ( )

Definition at line 89 of file kdtree.cpp.

90  {
91  if (elements_count_ < k_)
92  return max_key_;
93  return elements_[max_index_].key;

The documentation for this class was generated from the following file:
MinK::Element::key
Key key
Definition: kdtree.cpp:59