Public Member Functions | Protected Member Functions | Protected Attributes

CParseBuffer< T > Class Template Reference


Detailed Description

template<class T>
class shogun::CParseBuffer< T >

Class CParseBuffer implements a ring of examples of a defined size. The ring stores objects of the Example type.

The feature vector and label are provided to this class from an external source. CParseBuffer is only responsible for managing how these examples are represented and stored in the memory. It is also responsible for returning stored examples to be used by an external caller, and freeing up the space when the example is used to make room for another example to take its place.

Writing of examples is done into whichever position in the ring is free to be overwritten, or empty.

Definition at line 65 of file ParseBuffer.h.

Inheritance diagram for CParseBuffer< T >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CParseBuffer (int32_t size=1024)
 ~CParseBuffer ()
Example< T > * get_free_example ()
int32_t write_example (Example< T > *ex)
Example< T > * return_example_to_read ()
Example< T > * get_unused_example ()
int32_t copy_example (Example< T > *ex)
void finalize_example (bool free_after_release)
void set_free_vectors_on_destruct (bool destroy)
bool get_free_vectors_on_destruct ()
virtual const char * get_name () const

Protected Member Functions

virtual void inc_read_index ()
virtual void inc_write_index ()

Protected Attributes

int32_t ring_size
 Size of ring as number of examples.
Example< T > * ex_ring
 Ring of examples.
E_IS_EXAMPLE_USEDex_used
 Enum used for representing used/unused/empty state of example.
pthread_mutex_t * ex_in_use_mutex
 Lock on state of example - used or unused.
pthread_cond_t * ex_in_use_cond
 Condition variable triggered when example is being/not being used.
pthread_mutex_t * read_lock
 Lock for reading examples from the ring.
pthread_mutex_t * write_lock
 Lock for writing new examples.
int32_t ex_write_index
 Write position for next example.
int32_t ex_read_index
 Position of next example to be read.
bool free_vectors_on_destruct
 Whether examples on the ring will be freed on destruction.

Constructor & Destructor Documentation

CParseBuffer ( int32_t  size = 1024  ) 

Constructor, taking buffer size as argument.

Parameters:
size Ring size as number of examples

Definition at line 213 of file ParseBuffer.h.

~CParseBuffer (  ) 

Destructor, frees up buffer.

Definition at line 244 of file ParseBuffer.h.


Member Function Documentation

int32_t copy_example ( Example< T > *  ex  ) 

Copies an example into the buffer, waiting for the destination example to be used if necessary.

Parameters:
ex Example to copy into buffer
Returns:
1 on success, 0 on memory errors

Definition at line 306 of file ParseBuffer.h.

void finalize_example ( bool  free_after_release  ) 

Mark the example in 'read' position as 'used'.

It will then be free to be overwritten.

Parameters:
free_after_release whether to SG_FREE() the vector or not

Definition at line 327 of file ParseBuffer.h.

Example<T>* get_free_example (  ) 

Return the next position to write the example into the ring.

Returns:
pointer to example

Definition at line 87 of file ParseBuffer.h.

bool get_free_vectors_on_destruct (  ) 

Return whether all example objects will be freed on destruction.

Definition at line 158 of file ParseBuffer.h.

virtual const char* get_name ( void   )  const [virtual]

Return the name of the object

Returns:
ParseBuffer

Implements CSGObject.

Definition at line 165 of file ParseBuffer.h.

Example< T > * get_unused_example (  ) 

Returns the next example from the buffer if unused, or NULL.

Returns:
unused example object at next 'read' position or NULL.

Definition at line 284 of file ParseBuffer.h.

virtual void inc_read_index (  )  [protected, virtual]

Increments the 'read' position in the buffer.

Definition at line 172 of file ParseBuffer.h.

virtual void inc_write_index (  )  [protected, virtual]

Increments the 'write' position in the buffer.

Definition at line 181 of file ParseBuffer.h.

Example< T > * return_example_to_read (  ) 

Returns the example that should be read next from the buffer.

Returns:
example object at next 'read' position

Definition at line 275 of file ParseBuffer.h.

void set_free_vectors_on_destruct ( bool  destroy  ) 

Set whether all vectors are to be freed on destruction. This is true by default.

The features object should set this to false if the vectors are freed manually later.

Parameters:
destroy free examples on destruction or not

Definition at line 152 of file ParseBuffer.h.

int32_t write_example ( Example< T > *  ex  ) 

Writes the given example into the appropriate buffer space. Feature vector is copied into a separate block.

Parameters:
ex Example to copy into buffer
Returns:
1 if successful, 0 on failure (if no space available)

Definition at line 263 of file ParseBuffer.h.


Member Data Documentation

pthread_cond_t* ex_in_use_cond [protected]

Condition variable triggered when example is being/not being used.

Definition at line 198 of file ParseBuffer.h.

pthread_mutex_t* ex_in_use_mutex [protected]

Lock on state of example - used or unused.

Definition at line 196 of file ParseBuffer.h.

int32_t ex_read_index [protected]

Position of next example to be read.

Definition at line 207 of file ParseBuffer.h.

Example<T>* ex_ring [protected]

Ring of examples.

Definition at line 191 of file ParseBuffer.h.

E_IS_EXAMPLE_USED* ex_used [protected]

Enum used for representing used/unused/empty state of example.

Definition at line 194 of file ParseBuffer.h.

int32_t ex_write_index [protected]

Write position for next example.

Definition at line 205 of file ParseBuffer.h.

bool free_vectors_on_destruct [protected]

Whether examples on the ring will be freed on destruction.

Definition at line 210 of file ParseBuffer.h.

pthread_mutex_t* read_lock [protected]

Lock for reading examples from the ring.

Definition at line 200 of file ParseBuffer.h.

int32_t ring_size [protected]

Size of ring as number of examples.

Definition at line 189 of file ParseBuffer.h.

pthread_mutex_t* write_lock [protected]

Lock for writing new examples.

Definition at line 202 of file ParseBuffer.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

SHOGUN Machine Learning Toolbox - Documentation