ONE - On-device Neural Engine
Loading...
Searching...
No Matches
kuma::details::IntervalSet Class Reference

#include <IntervalSet.h>

Public Member Functions

 IntervalSet (uint32_t len=0xffffffff)
 
void insert (const IntervalMask &)
 
uint32_t firstfit (uint32_t len) const
 

Detailed Description

Definition at line 44 of file IntervalSet.h.

Constructor & Destructor Documentation

◆ IntervalSet()

kuma::details::IntervalSet::IntervalSet ( uint32_t  len = 0xffffffff)

Definition at line 27 of file IntervalSet.cpp.

28{
29 // Update _content
30 _content[len] = len;
31}

Member Function Documentation

◆ firstfit()

uint32_t kuma::details::IntervalSet::firstfit ( uint32_t  len) const

"firstfit(l)" returns the offset of an interval whose length is larger than "l".

When multiple intervals meet this condition, "firstfit(l)" chooses the interval with the smallest offset as its name suggests.

NOTE This method throws std::runtime_error if fails to find a proper region

Definition at line 77 of file IntervalSet.cpp.

78{
79 for (auto it = _content.begin(); it != _content.end(); ++it)
80 {
81 if (it->second >= len)
82 {
83 // Got it! This interval is larger than "len".
84 return it->first - it->second;
85 }
86 }
87
88 throw std::runtime_error{"infeasible"};
89}

Referenced by kuma::solve().

◆ insert()

void kuma::details::IntervalSet::insert ( const IntervalMask m)

Definition at line 33 of file IntervalSet.cpp.

34{
35 auto s = m.s;
36 auto e = m.e;
37
38 assert(s <= e);
39
40 if (s == e)
41 {
42 // Empty region, nothing to do
43 return;
44 }
45
46 // lower_bound() returns an iterator to the first element not less than the given key
47 auto lb = _content.lower_bound(s);
48
49 // NOTE 1. "lower_bound" ensures "prev_s < s <= curr_e"
50 // NOTE 2. "e" points to somewhere after "s"
51 auto curr_s = lb->first - lb->second;
52 auto curr_e = lb->first;
53
54 if (curr_s < s)
55 {
56 // Split the current interval
57 _content[s] = s - curr_s;
58 // NOTE The invariant over "_content" is temporarily broken here.
59 }
60
61 if (e < curr_e)
62 {
63 // Adjust the current interval
64 _content[curr_e] = curr_e - e;
65 }
66 else
67 {
68 // Remove the current interval
69 _content.erase(curr_e);
70 // Check the next interval (e > curr_e)
71 //
72 // TODO Remove this recursive call (to prevent stack overflow issue)
73 insert(mask(curr_e, e));
74 }
75}
void insert(const IntervalMask &)
IntervalMask mask(uint32_t s, uint32_t e)
Definition IntervalSet.h:34

References insert(), m, and kuma::details::mask().

Referenced by insert(), and kuma::solve().


The documentation for this class was generated from the following files: