55 #define MAX_CHUNK_SIZE 1024
62 Impl(
int minDelay,
int maxDelay) : _currNodeId(0), _spikeBufFront(maxDelay+1),
63 _spikeBufBack(maxDelay+1), _chunkBuf(0), _currFreeChunkId(NULL), _nextFreeNodeId(0), _nextFreeChunkId(0),
66 reset(minDelay, maxDelay);
70 for (
size_t i=0; i<_chunkBuf.size(); i++) {
71 delete[] _chunkBuf[i];
75 void reset(
int minDelay,
int maxDelay) {
76 init(maxDelay + minDelay);
78 for (
size_t i=0; i<_spikeBufFront.size(); i++) {
79 _spikeBufFront[i] = NULL;
80 _spikeBufBack[i] = NULL;
83 _currFreeChunkId = _chunkBuf[0];
88 _recycledNodes = NULL;
107 return _spikeBufFront.size();
111 void schedule(
int neurId,
int grpId,
unsigned short int delay) {
114 int writeIdx = (_currNodeId+delay) % _spikeBufFront.size();
120 if (_spikeBufFront[writeIdx] == NULL) {
121 _spikeBufFront[writeIdx] = n;
122 _spikeBufBack[writeIdx] = n;
124 _spikeBufBack[writeIdx]->next = n;
125 _spikeBufBack[writeIdx] = n;
131 if (_spikeBufFront[_currNodeId] != NULL) {
132 _spikeBufBack[_currNodeId]->next = _recycledNodes;
133 _recycledNodes = _spikeBufFront[_currNodeId];
137 _spikeBufFront[_currNodeId] = NULL;
138 _spikeBufBack[_currNodeId] = NULL;
139 _currNodeId = (_currNodeId + 1) % _spikeBufFront.size();
145 void init(
size_t maxDelaySteps) {
146 if (_spikeBufFront.size() != maxDelaySteps + 1) {
147 _spikeBufFront.resize(maxDelaySteps + 1);
148 _spikeBufBack.resize(maxDelaySteps + 1);
150 if (_chunkBuf.size() < 1) {
151 _chunkBuf.reserve(10);
158 SpikeNode* getFreeNode() {
160 if (_recycledNodes != NULL) {
163 _recycledNodes = _recycledNodes->
next;
166 n = &(_currFreeChunkId[_nextFreeNodeId++]);
167 }
else if (_nextFreeChunkId < _chunkBuf.size()) {
169 _currFreeChunkId = _chunkBuf[_nextFreeChunkId++];
170 n = &(_currFreeChunkId[0]);
175 _chunkBuf.push_back(_currFreeChunkId);
179 n = &(_currFreeChunkId[0]);
188 std::vector<SpikeNode*> _spikeBufFront;
191 std::vector<SpikeNode*> _spikeBufBack;
194 std::vector<SpikeNode*> _chunkBuf;
197 SpikeNode* _currFreeChunkId;
203 size_t _nextFreeChunkId;
206 SpikeNode* _recycledNodes;
216 _impl( new
Impl(minDelay, maxDelay) ) {}