Kstars

HtmRange.cpp
1 #include <HtmRange.h>
2 
3 #include <stdio.h>
4 #include <string.h>
5 
6 #define INSIDE 1
7 #define OUTSIDE -1
8 #define INTERSECT 0
9 #define GAP_HISTO_SIZE 10000
10 
11 extern "C" {
12 int cc_ID2name(char *name, uint64 id);
13 }
14 
15 HtmRange::HtmRange()
16 {
17  my_los = new SkipList;
18  my_his = new SkipList;
19 }
20 
21 HtmRange::~HtmRange()
22 {
23  my_los->freeRange(-1, KEY_MAX);
24  my_his->freeRange(-1, KEY_MAX);
25  delete my_los;
26  delete my_his;
27 }
28 
29 InclusionType HtmRange::tinside(const Key mid) const
30 {
31  // clearly out, inside, share a boundary, off by one to some boundary
32  InclusionType t1, t2;
33 
34  Key GH = my_his->findMAX(mid);
35  Key GL = my_los->findMAX(mid);
36 
37  if (GH < GL)
38  t1 = InclInside;
39  else
40  t1 = InclOutside;
41 
42  Key SH = my_his->findMIN(mid);
43  Key SL = my_los->findMIN(mid);
44  if (SH < SL)
45  t2 = InclInside;
46  else
47  t2 = InclOutside;
48 
49  if (t1 == t2)
50  return t1;
51  if (t1 == InclInside)
52  return InclHi;
53  else
54  return InclLo;
55 }
56 
57 void HtmRange::mergeRange(const Key lo, const Key hi)
58 {
59  int lo_flag = tinside(lo);
60  int hi_flag = tinside(hi);
61 
62  // delete all nodes (key) in his and los where lo < key < hi
63  my_his->freeRange(lo, hi);
64  my_los->freeRange(lo, hi);
65 
66  // add if not inside a pre-existing interval
67  if (lo_flag == InclHi)
68  {
69  }
70  else if (lo_flag == InclLo || (lo_flag == InclOutside))
71  {
72  my_los->insert(lo, 33);
73  }
74 
75  if (hi_flag == InclLo)
76  {
77  }
78  else if (hi_flag == InclOutside || hi_flag == InclHi)
79  {
80  my_his->insert(hi, 33);
81  }
82 }
83 
84 void HtmRange::reset()
85 {
86  my_los->reset();
87  my_his->reset();
88 }
89 
90 int HtmRange::getNext(Key *lo, Key *hi)
91 {
92  *lo = my_los->getkey();
93  if (*lo <= (Key)0)
94  {
95  *hi = *lo = (Key)0;
96  return 0;
97  }
98  *hi = my_his->getkey();
99  my_his->step();
100  my_los->step();
101  return 1;
102 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Fri Aug 19 2022 03:57:51 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.