KSquare Utilities
SVM289_BFS::Cache Class Reference

Public Member Functions

 Cache (kkint32 l, kkint32 size)
 Kernel Cache. More...
 
 ~Cache ()
 
kkint32 get_data (const kkint32 index, Qfloat **data, kkint32 len)
 Request data [0,len) More...
 
void swap_index (kkint32 i, kkint32 j)
 

Detailed Description

Definition at line 649 of file svm289_BFS.cpp.

Constructor & Destructor Documentation

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

Kernel Cache.

Parameters
[in]lThe number of total data items.
[in]sizeThe cache size limit in bytes

Definition at line 698 of file svm289_BFS.cpp.

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

700  :
701  l (l_),
702  size (size_)
703 {
704  head = (head_t *)calloc (l, sizeof (head_t)); // initialized to 0
705  size /= sizeof (Qfloat);
706  size -= l * sizeof (head_t) / sizeof (Qfloat);
707  size = Max (size, 2 * (kkint32) l); // cache must be large enough for two columns
708  lru_head.next = lru_head.prev = &lru_head;
709 }
__int32 kkint32
Definition: KKBaseTypes.h:88
float Qfloat
Definition: svm289_BFS.h:269
T Max(T a, T b)
generic Max function, Both parameters must be of the same type.
Definition: KKBaseTypes.h:181
SVM289_BFS::Cache::~Cache ( )

Definition at line 713 of file svm289_BFS.cpp.

714 {
715  for (head_t* h = lru_head.next; h != &lru_head; h = h->next)
716  {delete (h->data); h->data = NULL;}
717  delete head; head = NULL;
718 }

Member Function Documentation

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

Request data [0,len)

Return some position p where [p,len) need to be filled (p >= len if nothing needs to be filled)

Definition at line 742 of file svm289_BFS.cpp.

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

746 {
747  head_t* h = &head[index];
748  if (h->len)
749  lru_delete (h);
750 
751  kkint32 more = len - h->len;
752 
753  if (more > 0)
754  {
755  // free old space
756  while (size < more)
757  {
758  head_t* old = lru_head.next;
759  lru_delete (old);
760  delete old->data; old->data = NULL;
761  size += old->len;
762  old->data = 0;
763  old->len = 0;
764  }
765 
766  // allocate new space
767  h->data = (Qfloat *)realloc(h->data, sizeof (Qfloat) * len);
768  size -= more;
769  SVM289_BFS::swap (h->len, len);
770  }
771 
772  lru_insert (h);
773  *data = h->data;
774  return len;
775 }
__int32 kkint32
Definition: KKBaseTypes.h:88
float Qfloat
Definition: svm289_BFS.h:269
void swap(T &x, T &y)
Definition: svm289_BFS.h:265
void Cache::swap_index ( kkint32  i,
kkint32  j 
)

Definition at line 779 of file svm289_BFS.cpp.

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

780 {
781  if ( i == j)
782  return;
783 
784  if (head[i].len)
785  lru_delete (&head[i]);
786 
787  if (head[j].len)
788  lru_delete(&head[j]);
789 
790 
791  SVM289_BFS::swap (head[i].data, head[j].data);
792 
793  SVM289_BFS::swap (head[i].len, head[j].len);
794 
795  if (head[i].len)
796  lru_insert(&head[i]);
797 
798  if (head[j].len)
799  lru_insert(&head[j]);
800 
801  if (i > j)
802  SVM289_BFS::swap(i, j);
803 
804 
805  for (head_t* h = lru_head.next; h != &lru_head; h = h->next)
806  {
807  if (h->len > i)
808  {
809  if (h->len > j)
810  {
811  SVM289_BFS::swap (h->data[i], h->data[j]);
812  }
813  else
814  {
815  // give up
816  lru_delete (h);
817  delete h->data; h->data = NULL;
818  size += h->len;
819  h->data = 0;
820  h->len = 0;
821  }
822  }
823  }
824 } /* swap_index */
void swap(T &x, T &y)
Definition: svm289_BFS.h:265

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