NEST  2.6.0,not_revisioned_source_dir@0
sparse_node_array.h
Go to the documentation of this file.
1 /*
2  * sparse_node_array.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 SPARSE_NODE_ARRAY_H
24 #define SPARSE_NODE_ARRAY_H
25 
26 #include <cassert>
27 #include <vector>
28 #include <map>
29 
30 #include "nest.h"
31 
32 namespace nest {
33  class Node;
34 
53 {
54 private:
55 
56  struct NodeEntry_ {
60  };
61 
62 public:
65 
70  size_t size() const;
71 
73  void reserve(size_t);
74 
76  void clear();
77 
79  size_t max_size() const;
80 
84  void add_local_node(Node&);
85 
92  void add_remote_node(index);
93 
107  Node* get_node_by_gid(index) const;
108 
116  Node* get_node_by_index(size_t) const;
117 
122  index get_max_gid() const;
123 
124  std::map<long, size_t> get_step_ctr() const;
125 
126 private:
127  std::vector<NodeEntry_> nodes_;
131  double gid_idx_scale_;
132  mutable std::map<long, size_t> step_ctr_;
133 };
134 
135 } // namespace nest
136 
137 inline
139 {
140  return nodes_.size();
141 }
142 
143 inline
145 {
146  nodes_.clear();
147  max_gid_ = 0;
148  local_min_gid_ = 0;
149  local_max_gid_ = 0;
150  gid_idx_scale_ = 1.;
151  step_ctr_.clear();
152 }
153 
154 inline
156 {
157  return nodes_.max_size();
158 }
159 
160 inline
162 {
163  assert(idx < nodes_.size());
164  return nodes_[idx].node_;
165 }
166 
167 inline
169 {
170  return max_gid_;
171 }
172 
173 inline
174 std::map<long, size_t> nest::SparseNodeArray::get_step_ctr() const
175 {
176  return step_ctr_;
177 }
178 
179 #endif /* SPARSE_NODE_ARRAY_H */
size_t index
Unsigned long type for enumerations.
Definition: nest.h:109
index local_max_gid_
largest local GID
Definition: sparse_node_array.h:130
size_t size() const
Return size of container.
Definition: sparse_node_array.h:138
void add_local_node(Node &)
Add single local node.
Definition: sparse_node_array.cpp:49
std::map< long, size_t > get_step_ctr() const
Definition: sparse_node_array.h:174
Provide sparse representation of local nodes.
Definition: sparse_node_array.h:52
void clear()
Clear the array.
Definition: sparse_node_array.h:144
std::vector< NodeEntry_ > nodes_
stores local node information
Definition: sparse_node_array.h:127
assert(pNet!=0)
index get_max_gid() const
Return largest GID in global network.
Definition: sparse_node_array.h:168
void reserve(size_t)
Reserve space for given number of elements.
Definition: sparse_node_array.cpp:44
size_t max_size() const
Return maximum size of underlying vector.
Definition: sparse_node_array.h:155
SparseNodeArray()
Create empty spare node array.
Definition: sparse_node_array.cpp:34
index max_gid_
largest GID in network
Definition: sparse_node_array.h:128
index local_min_gid_
smallest local GID
Definition: sparse_node_array.h:129
Node * get_node_by_index(size_t) const
Lookup node based on index into container.
Definition: sparse_node_array.h:161
Definition: sparse_node_array.h:56
Default types used by the NEST kernel.
Base class for all NEST network objects.
Definition: node.h:96
NodeEntry_(Node &, index)
Definition: sparse_node_array.cpp:28
double gid_idx_scale_
interpolation factor
Definition: sparse_node_array.h:131
Node * get_node_by_gid(index) const
Lookup node based on GID.
Definition: sparse_node_array.cpp:88
std::map< long, size_t > step_ctr_
for analysis, measure misses
Definition: sparse_node_array.h:132
void add_remote_node(index)
Register non-local node.
Definition: sparse_node_array.cpp:82
Node * node_
Definition: sparse_node_array.h:58
index gid_
store gid locally for faster searching
Definition: sparse_node_array.h:59