Xmipp  v3.23.11-Nereus
Classes | Public Member Functions | List of all members
Cache Class Reference

Public Member Functions

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

Detailed Description

Definition at line 73 of file svm.cpp.

Constructor & Destructor Documentation

◆ Cache()

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

Definition at line 100 of file svm.cpp.

100  :l(l_),size(size_)
101 {
102  head = (head_t *)calloc(l,sizeof(head_t)); // initialized to 0
103  size /= sizeof(Qfloat);
104  size -= l * sizeof(head_t) / sizeof(Qfloat);
105  size = max(size, 2 * (long int) l); // cache must be large enough for two columns
106  lru_head.next = lru_head.prev = &lru_head;
107 }
void max(Image< double > &op1, const Image< double > &op2)
float Qfloat
Definition: svm.cpp:18

◆ ~Cache()

Cache::~Cache ( )

Definition at line 109 of file svm.cpp.

110 {
111  for(head_t *h = lru_head.next; h != &lru_head; h=h->next)
112  free(h->data);
113  free(head);
114 }
free((char *) ob)

Member Function Documentation

◆ get_data()

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

Definition at line 132 of file svm.cpp.

133 {
134  head_t *h = &head[index];
135  if(h->len) lru_delete(h);
136  int more = len - h->len;
137 
138  if(more > 0)
139  {
140  // free old space
141  while(size < more)
142  {
143  head_t *old = lru_head.next;
144  lru_delete(old);
145  free(old->data);
146  size += old->len;
147  old->data = 0;
148  old->len = 0;
149  }
150 
151  // allocate new space
152  h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
153  size -= more;
154  swap(h->len,len);
155  }
156 
157  lru_insert(h);
158  *data = h->data;
159  return len;
160 }
viol index
float Qfloat
Definition: svm.cpp:18
free((char *) ob)
#define len

◆ swap_index()

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

Definition at line 162 of file svm.cpp.

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

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