6 #include "PropagatedSpikeBuffer.h"
15 ringBufferFront(maxDelay+1),
16 ringBufferBack(maxDelay+1),
18 currentFreeChunk(NULL),
19 nextFreeSrgNodeIdx(0),
29 cout <<
"Ringbuffer size is: " << ringBufferFront.size() << endl;
31 reset( minDelay, maxDelay );
46 for(
size_t i=0; i<chunkBuffer.size(); i++) {
47 delete[] chunkBuffer[i];
51 void PropagatedSpikeBuffer::init(
size_t maxDelaySteps)
56 if( ringBufferFront.size() != maxDelaySteps + 1 ) {
57 ringBufferFront.resize( maxDelaySteps + 1 );
58 ringBufferBack.resize( maxDelaySteps + 1 );
60 if( chunkBuffer.size() < 1 ) {
61 chunkBuffer.reserve( 10 );
62 chunkBuffer.resize( 0 );
63 chunkBuffer.push_back(
new StgNode[ chunkSize ] );
73 init( maxDelay + minDelay );
75 for(
size_t i=0; i<ringBufferFront.size(); i++) {
76 ringBufferFront[i] = ringBufferBack[i] = NULL;
79 currentFreeChunk = chunkBuffer[0];
82 nextFreeSrgNodeIdx = 0;
92 if (recycledNodes != NULL) {
95 recycledNodes = recycledNodes->next;
96 }
else if ( nextFreeSrgNodeIdx < chunkSize ) {
98 n = &(currentFreeChunk[nextFreeSrgNodeIdx++]);
99 }
else if (nextFreeChunkIdx < chunkBuffer.size() ) {
101 currentFreeChunk = chunkBuffer[nextFreeChunkIdx++];
102 n = &(currentFreeChunk[0]);
103 nextFreeSrgNodeIdx = 1;
106 currentFreeChunk =
new StgNode[chunkSize];
107 chunkBuffer.push_back( currentFreeChunk );
109 n = &(currentFreeChunk[0]);
110 nextFreeSrgNodeIdx = 1;
122 int writeIdx = ( currIdx + delay ) % ringBufferFront.size();
127 if( ringBufferFront[writeIdx] == NULL ) {
128 ringBufferBack[writeIdx] = ringBufferFront[writeIdx] = n;
130 ringBufferBack[writeIdx]->next = n;
131 ringBufferBack[writeIdx] = n;
139 if( ringBufferFront[ currIdx ] != NULL ) {
140 ringBufferBack[ currIdx ]->next = recycledNodes;
141 recycledNodes = ringBufferFront[ currIdx ];
145 ringBufferBack[ currIdx ] = ringBufferFront[ currIdx ] = NULL;
146 currIdx = ( currIdx + 1 ) % ringBufferFront.size();
void nextTimeStep()
Must be called to tell the buffer that it should move on to the next time step.
void reset(int minDelay, int maxDelay)
Must be called at the begin (reset) of a simulation.
Structure which stores the index of the spike target group and a pointer to the next element in vario...
void scheduleSpikeTargetGroup(spikegroupid_t stg, delaystep_t delay)
Schedule a group of spike targets to get a spike at time t + delay.
PropagatedSpikeBuffer(int minDelay, int maxDelay, int chunkSize=PROPAGATED_SPIKE_BUFFER_CHUNK_SIZE)
New spike buffer.
virtual ~PropagatedSpikeBuffer()
Destructor: Deletes all scheduled spikes.