pktools 2.6.7
Processing Kernel for geospatial data
Classes | Public Member Functions | List of all members
Cache Class Reference

Public Member Functions

 Cache (int l, long int size)
 
int get_data (const int index, Qfloat **data, int len)
 
void swap_index (int i, int j)
 

Detailed Description

Definition at line 69 of file svm.cpp.

Constructor & Destructor Documentation

◆ Cache()

Cache::Cache ( int  l,
long int  size 
)

Definition at line 96 of file svm.cpp.

96 :l(l_),size(size_)
97{
98 head = (head_t *)calloc(l,sizeof(head_t)); // initialized to 0
99 size /= sizeof(Qfloat);
100 size -= l * sizeof(head_t) / sizeof(Qfloat);
101 size = max(size, 2 * (long int) l); // cache must be large enough for two columns
102 lru_head.next = lru_head.prev = &lru_head;
103}

◆ ~Cache()

Cache::~Cache ( )

Definition at line 105 of file svm.cpp.

106{
107 for(head_t *h = lru_head.next; h != &lru_head; h=h->next)
108 free(h->data);
109 free(head);
110}

Member Function Documentation

◆ get_data()

int Cache::get_data ( const int  index,
Qfloat **  data,
int  len 
)

Definition at line 128 of file svm.cpp.

129{
130 head_t *h = &head[index];
131 if(h->len) lru_delete(h);
132 int more = len - h->len;
133
134 if(more > 0)
135 {
136 // free old space
137 while(size < more)
138 {
139 head_t *old = lru_head.next;
140 lru_delete(old);
141 free(old->data);
142 size += old->len;
143 old->data = 0;
144 old->len = 0;
145 }
146
147 // allocate new space
148 h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
149 size -= more;
150 swap(h->len,len);
151 }
152
153 lru_insert(h);
154 *data = h->data;
155 return len;
156}

◆ swap_index()

void Cache::swap_index ( int  i,
int  j 
)

Definition at line 158 of file svm.cpp.

159{
160 if(i==j) return;
161
162 if(head[i].len) lru_delete(&head[i]);
163 if(head[j].len) lru_delete(&head[j]);
164 swap(head[i].data,head[j].data);
165 swap(head[i].len,head[j].len);
166 if(head[i].len) lru_insert(&head[i]);
167 if(head[j].len) lru_insert(&head[j]);
168
169 if(i>j) swap(i,j);
170 for(head_t *h = lru_head.next; h!=&lru_head; h=h->next)
171 {
172 if(h->len > i)
173 {
174 if(h->len > j)
175 swap(h->data[i],h->data[j]);
176 else
177 {
178 // give up
179 lru_delete(h);
180 free(h->data);
181 size += h->len;
182 h->data = 0;
183 h->len = 0;
184 }
185 }
186 }
187}

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