KSquare Utilities
SVM233::Cache Class Reference

Public Member Functions

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

Detailed Description

Definition at line 1361 of file svm.cpp.

Constructor & Destructor Documentation

SVM233::Cache::Cache ( kkint32  l,
kkint32  size 
)

Definition at line 1400 of file svm.cpp.

Referenced by SVM233::ONE_CLASS_Q::ONE_CLASS_Q(), SVM233::SVC_Q::SVC_Q(), and SVM233::SVR_Q::SVR_Q().

1402  :
1403 
1404 l (l_),
1405 size (size_)
1406 
1407 {
1408  head = (head_t *)calloc (l, sizeof (head_t)); // initialized to 0
1409  size /= sizeof (Qfloat);
1410  size -= l * sizeof (head_t) / sizeof (Qfloat);
1411  lru_head.next = lru_head.prev = &lru_head;
1412 }
float Qfloat
Definition: svm2.h:287
SVM233::Cache::~Cache ( )

Definition at line 1416 of file svm.cpp.

1417 {
1418  for (head_t *h = lru_head.next; h != &lru_head; h = h->next)
1419  free(h->data);
1420  free(head);
1421 }

Member Function Documentation

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

Definition at line 1445 of file svm.cpp.

Referenced by SVM233::SVC_Q::get_Q(), SVM233::ONE_CLASS_Q::get_Q(), and SVM233::SVR_Q::get_Q().

1449 {
1450  head_t *h = &head[index];
1451 
1452  if (h->len)
1453  lru_delete(h);
1454 
1455  kkint32 more = len - h->len;
1456 
1457  if (more > 0)
1458  {
1459  // free old space
1460  while(size < more)
1461  {
1462  head_t *old = lru_head.next;
1463  lru_delete(old);
1464  free(old->data);
1465  size += old->len;
1466  old->data = 0;
1467  old->len = 0;
1468  }
1469 
1470  // allocate new space
1471  h->data = (Qfloat *)realloc(h->data,sizeof(Qfloat)*len);
1472  size -= more;
1473  Swap(h->len, len);
1474  }
1475 
1476  lru_insert (h);
1477  *data = h->data;
1478  return len;
1479 }
void Swap(T &x, T &y)
Definition: svm.cpp:687
__int32 kkint32
Definition: KKBaseTypes.h:88
float Qfloat
Definition: svm2.h:287
void SVM233::Cache::swap_index ( kkint32  i,
kkint32  j 
)

Definition at line 1483 of file svm.cpp.

Referenced by SVM233::SVC_Q::swap_index(), and SVM233::ONE_CLASS_Q::swap_index().

1486 {
1487  if(i==j) return;
1488 
1489  if(head[i].len) lru_delete(&head[i]);
1490  if(head[j].len) lru_delete(&head[j]);
1491  Swap(head[i].data,head[j].data);
1492  Swap(head[i].len,head[j].len);
1493  if(head[i].len) lru_insert(&head[i]);
1494  if(head[j].len) lru_insert(&head[j]);
1495 
1496  if(i>j) Swap(i,j);
1497  for(head_t *h = lru_head.next; h!=&lru_head; h=h->next)
1498  {
1499  if(h->len > i)
1500  {
1501  if(h->len > j)
1502  Swap(h->data[i],h->data[j]);
1503  else
1504  {
1505  // give up
1506  lru_delete(h);
1507  free(h->data);
1508  size += h->len;
1509  h->data = 0;
1510  h->len = 0;
1511  }
1512  }
1513  }
1514 }
void Swap(T &x, T &y)
Definition: svm.cpp:687

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