54 #define MAX_CHUNK_SIZE 1024
61 Impl(
int minDelay,
int maxDelay) : _currNodeId(0), _spikeBufFront(maxDelay+1),
62 _spikeBufBack(maxDelay+1), _chunkBuf(0), _currFreeChunkId(NULL), _nextFreeNodeId(0), _nextFreeChunkId(0),
65 reset(minDelay, maxDelay);
69 for (
size_t i=0; i<_chunkBuf.size(); i++) {
70 delete[] _chunkBuf[i];
74 void reset(
int minDelay,
int maxDelay) {
75 init(maxDelay + minDelay);
77 for (
size_t i=0; i<_spikeBufFront.size(); i++) {
78 _spikeBufFront[i] = NULL;
79 _spikeBufBack[i] = NULL;
82 _currFreeChunkId = _chunkBuf[0];
87 _recycledNodes = NULL;
106 return _spikeBufFront.size();
110 void schedule(
int neurId,
int grpId,
unsigned short int delay) {
113 int writeIdx = (_currNodeId+delay) % _spikeBufFront.size();
119 if (_spikeBufFront[writeIdx] == NULL) {
120 _spikeBufFront[writeIdx] = n;
121 _spikeBufBack[writeIdx] = n;
123 _spikeBufBack[writeIdx]->next = n;
124 _spikeBufBack[writeIdx] = n;
130 if (_spikeBufFront[_currNodeId] != NULL) {
131 _spikeBufBack[_currNodeId]->next = _recycledNodes;
132 _recycledNodes = _spikeBufFront[_currNodeId];
136 _spikeBufFront[_currNodeId] = NULL;
137 _spikeBufBack[_currNodeId] = NULL;
138 _currNodeId = (_currNodeId + 1) % _spikeBufFront.size();
144 void init(
size_t maxDelaySteps) {
145 if (_spikeBufFront.size() != maxDelaySteps + 1) {
146 _spikeBufFront.resize(maxDelaySteps + 1);
147 _spikeBufBack.resize(maxDelaySteps + 1);
149 if (_chunkBuf.size() < 1) {
150 _chunkBuf.reserve(10);
157 SpikeNode* getFreeNode() {
159 if (_recycledNodes != NULL) {
162 _recycledNodes = _recycledNodes->
next;
165 n = &(_currFreeChunkId[_nextFreeNodeId++]);
166 }
else if (_nextFreeChunkId < _chunkBuf.size()) {
168 _currFreeChunkId = _chunkBuf[_nextFreeChunkId++];
169 n = &(_currFreeChunkId[0]);
174 _chunkBuf.push_back(_currFreeChunkId);
178 n = &(_currFreeChunkId[0]);
187 std::vector<SpikeNode*> _spikeBufFront;
190 std::vector<SpikeNode*> _spikeBufBack;
193 std::vector<SpikeNode*> _chunkBuf;
196 SpikeNode* _currFreeChunkId;
202 size_t _nextFreeChunkId;
205 SpikeNode* _recycledNodes;
215 _impl( new
Impl(minDelay, maxDelay) ) {}