NEST main@caf0ae8
 
Loading...
Searching...
No Matches
source_table_position.h
Go to the documentation of this file.
1/*
2 * source_table_position.h
3 *
4 * This file is part of NEST.
5 *
6 * Copyright (C) 2004 The NEST Initiative
7 *
8 * NEST is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * NEST is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with NEST. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#ifndef SOURCE_TABLE_POSITION_H
24#define SOURCE_TABLE_POSITION_H
25
26// C++ includes:
27#include <cassert>
28#include <iostream>
29#include <vector>
30
31#include "block_vector.h"
32
33namespace nest
34{
35
40{
41 long tid;
42 long syn_id;
43 long lcid;
44
46 SourceTablePosition( const long tid, const long syn_id, const long lcid );
49
53 void seek_to_next_valid_index( const std::vector< std::vector< BlockVector< Source > > >& sources );
54
58 void decrease();
59
64 bool is_invalid() const;
65};
66
68 : tid( -1 )
69 , syn_id( -1 )
70 , lcid( -1 )
71{
72}
73
74inline SourceTablePosition::SourceTablePosition( const long tid, const long syn_id, const long lcid )
75 : tid( tid )
76 , syn_id( syn_id )
77 , lcid( lcid )
78{
79}
80
81inline void
82SourceTablePosition::seek_to_next_valid_index( const std::vector< std::vector< BlockVector< Source > > >& sources )
83{
84 if ( lcid >= 0 )
85 {
86 return; // nothing to do if we are at a valid index
87 }
88
89 // we stay in this loop either until we can return a valid position,
90 // i.e., lcid >= 0, or we have reached the end of the
91 // multidimensional vector
92 while ( lcid < 0 )
93 {
94 // first try finding a valid lcid by only decreasing synapse index
95 --syn_id;
96 if ( syn_id >= 0 )
97 {
98 lcid = sources[ tid ][ syn_id ].size() - 1;
99 continue;
100 }
101
102 // if we can not find a valid lcid by decreasing synapse indices,
103 // try decreasing thread index
104 --tid;
105 if ( tid >= 0 )
106 {
107 syn_id = sources[ tid ].size() - 1;
108 if ( syn_id >= 0 )
109 {
110 lcid = sources[ tid ][ syn_id ].size() - 1;
111 }
112 continue;
113 }
114
115 // if we can not find a valid lcid by decreasing synapse or thread
116 // indices, we have read all entries
117 assert( tid == -1 );
118 assert( syn_id == -1 );
119 assert( lcid == -1 );
120 return; // reached the end without finding a valid entry
121 }
122
123 return; // found a valid entry
124}
125
126inline bool
128{
129 return ( tid == -1 and syn_id == -1 and lcid == -1 );
130}
131
132inline void
134{
135 --lcid;
136 assert( lcid >= -1 );
137}
138
139inline bool
141{
142 return ( lhs.tid == rhs.tid and lhs.syn_id == rhs.syn_id and lhs.lcid == rhs.lcid );
143}
144
145inline bool
147{
148 return not operator==( lhs, rhs );
149}
150
151inline bool
152operator<( const SourceTablePosition& lhs, const SourceTablePosition& rhs )
153{
154 if ( lhs.tid == rhs.tid )
155 {
156 if ( lhs.syn_id == rhs.syn_id )
157 {
158 return lhs.lcid < rhs.lcid;
159 }
160 else
161 {
162 return lhs.syn_id < rhs.syn_id;
163 }
164 }
165 else
166 {
167 return lhs.tid < rhs.tid;
168 }
169}
170
171inline bool
173{
174 return operator<( rhs, lhs );
175}
176
177inline bool
178operator<=( const SourceTablePosition& lhs, const SourceTablePosition& rhs )
179{
180 return not operator>( lhs, rhs );
181}
182
183inline bool
185{
186 return not operator<( lhs, rhs );
187}
188
189} // namespace nest
190
191#endif /* #ifndef SOURCE_TABLE_POSITION_H */
Container with a vector-of-vectors structure.
Definition block_vector.h:156
Namespace for the NEST simulation kernel.
Definition beta_normalization_factor.h:33
bool operator<=(const Time &t1, const Time &t2)
Definition nest_time.h:578
bool operator<(const histentry_extended &he, double t)
Definition histentry.h:67
bool operator>(const Time &t1, const Time &t2)
Definition nest_time.h:572
bool operator==(const Time &t1, const Time &t2)
Definition nest_time.h:554
bool operator>=(const Time &t1, const Time &t2)
Definition nest_time.h:584
bool operator!=(const Time &t1, const Time &t2)
Definition nest_time.h:560
Three-tuple to store position in 3d vector of sources.
Definition source_table_position.h:40
SourceTablePosition()
Definition source_table_position.h:67
bool is_invalid() const
Returns true if the indices point outside the SourceTable, e.g., to signal that the end was reached.
Definition source_table_position.h:127
void decrease()
Decreases the inner most index (lcid).
Definition source_table_position.h:133
long tid
thread index
Definition source_table_position.h:41
long lcid
local connection index
Definition source_table_position.h:43
SourceTablePosition & operator=(const SourceTablePosition &rhs)=default
SourceTablePosition(const SourceTablePosition &rhs)=default
void seek_to_next_valid_index(const std::vector< std::vector< BlockVector< Source > > > &sources)
Decreases indices until a valid entry is found.
Definition source_table_position.h:82
long syn_id
synapse-type index
Definition source_table_position.h:42