56 #define MAX_CHUNK_SIZE 1024 63 Impl(
int minDelay,
int maxDelay) : _currNodeId(0), _spikeBufFront(maxDelay+1),
64 _spikeBufBack(maxDelay+1), _chunkBuf(0), _currFreeChunkId(NULL), _nextFreeNodeId(0), _nextFreeChunkId(0),
67 reset(minDelay, maxDelay);
71 for (
size_t i=0; i<_chunkBuf.size(); i++) {
72 delete[] _chunkBuf[i];
76 void reset(
int minDelay,
int maxDelay) {
77 init(maxDelay + minDelay);
79 for (
size_t i=0; i<_spikeBufFront.size(); i++) {
80 _spikeBufFront[i] = NULL;
81 _spikeBufBack[i] = NULL;
84 _currFreeChunkId = _chunkBuf[0];
89 _recycledNodes = NULL;
108 return _spikeBufFront.size();
112 void schedule(
int neurId,
int grpId,
unsigned short int delay) {
115 int writeIdx = (_currNodeId+delay) % _spikeBufFront.size();
121 if (_spikeBufFront[writeIdx] == NULL) {
122 _spikeBufFront[writeIdx] = n;
123 _spikeBufBack[writeIdx] = n;
125 _spikeBufBack[writeIdx]->next = n;
126 _spikeBufBack[writeIdx] = n;
132 if (_spikeBufFront[_currNodeId] != NULL) {
133 _spikeBufBack[_currNodeId]->next = _recycledNodes;
134 _recycledNodes = _spikeBufFront[_currNodeId];
138 _spikeBufFront[_currNodeId] = NULL;
139 _spikeBufBack[_currNodeId] = NULL;
140 _currNodeId = (_currNodeId + 1) % _spikeBufFront.size();
146 void init(
size_t maxDelaySteps) {
147 if (_spikeBufFront.size() != maxDelaySteps + 1) {
148 _spikeBufFront.resize(maxDelaySteps + 1);
149 _spikeBufBack.resize(maxDelaySteps + 1);
151 if (_chunkBuf.size() < 1) {
152 _chunkBuf.reserve(10);
161 if (_recycledNodes != NULL) {
164 _recycledNodes = _recycledNodes->
next;
167 n = &(_currFreeChunkId[_nextFreeNodeId++]);
168 }
else if (_nextFreeChunkId < _chunkBuf.size()) {
170 _currFreeChunkId = _chunkBuf[_nextFreeChunkId++];
171 n = &(_currFreeChunkId[0]);
176 _chunkBuf.push_back(_currFreeChunkId);
180 n = &(_currFreeChunkId[0]);
189 std::vector<SpikeNode*> _spikeBufFront;
192 std::vector<SpikeNode*> _spikeBufBack;
195 std::vector<SpikeNode*> _chunkBuf;
204 size_t _nextFreeChunkId;
217 _impl( new
Impl(minDelay, maxDelay) ) {}
int grpId
corresponding global group Id
void schedule(int neurId, int grpId, unsigned short int delay)
Schedule a spike.
Iterator to loop over the scheduled spikes at a certain delay.
Impl(int minDelay, int maxDelay)
size_t length()
retrieve actual length of the buffer
unsigned short int delay
scheduling delay (in number of time steps)
SpikeIterator back()
pointer to the back of the spike buffer
linked list to hold the corresponding neuron Id and delivery delay for each spike ...
SpikeNode * next
pointer to the next element in the list
void reset(int minDelay, int maxDelay)
Reset buffer data.
void schedule(int neurId, int grpId, unsigned short int delay)
int neurId
corresponding global neuron Id
SpikeIterator front(int stepOffset=0)
SpikeBuffer(int minDelay, int maxDelay)
SpikeBuffer Constructor.
void step()
advance to next time step
~SpikeBuffer()
SpikeBuffer Destructor.
SpikeIterator front(int stepOffset=0)
pointer to the front of the spike buffer
void reset(int minDelay, int maxDelay)