Hermes2D  3.0
hash.h
1 // This file is part of Hermes2D.
2 //
3 // Hermes2D is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 2 of the License, or
6 // (at your option) any later version.
7 //
8 // Hermes2D is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with Hermes2D. If not, see <http://www.gnu.org/licenses/>.
15 
16 #ifndef __H2D_HASH_H
17 #define __H2D_HASH_H
18 
19 #include "hermes_common.h"
20 
21 namespace Hermes
22 {
23  namespace Hermes2D
24  {
25  struct Node;
26 
27  namespace Views
28  {
29  class MeshView;
30  class ScalarView;
31  class Orderizer;
32  };
33 
39  class HERMES_API HashTable : public Hermes::Mixins::Loggable
40  {
41  public:
43  Node* get_node(int id) const;
44 
46  int get_max_node_id() const;
47 
49  static const int H2D_DEFAULT_HASH_SIZE = 0x8000;
50 
52  Node* peek_vertex_node(int p1, int p2) const;
53 
55  Node* peek_edge_node(int p1, int p2) const;
56 
57  inline Array<Node> &get_nodes() { return nodes; }
58 
59  protected:
60  HashTable();
61  virtual ~HashTable();
62 
64  int get_num_nodes() const;
65 
69  Node* get_vertex_node(int p1, int p2);
70 
74  Node* get_edge_node(int p1, int p2);
75 
77  Array<Node> nodes;
78 
81  void init(int size = H2D_DEFAULT_HASH_SIZE);
82 
84  void copy(const HashTable* ht);
85 
87  void rebuild();
88 
90  void free();
91 
93  void remove_vertex_node(int id);
94 
96  void remove_edge_node(int id);
97 
98  // Internal members
99  private:
100 
102  Node** v_table;
104  Node** e_table;
105 
106  int mask;
107 
108  inline int hash(int p1, int p2) const { return (984120265 * p1 + 125965121 * p2) & mask; }
109 
112  Node* search_list(Node* node, int p1, int p2) const;
113 
115  void copy_list(Node** ptr, Node* node);
116 
117  friend struct Node;
118  friend class MeshUtil;
119  friend class MeshReaderH2D;
120  template<typename Scalar> friend class NeighborSearch;
121  template<typename Scalar> friend class Space;
122  template<typename Scalar> friend class H1Space;
123  template<typename Scalar> friend class L2Space;
124  template<typename Scalar> friend class HcurlSpace;
125  template<typename Scalar> friend class HdivSpace;
126  };
127  }
128 }
129 #endif
Definition: adapt.h:24
Stores one node of a mesh.
Definition: element.h:45
Array< Node > nodes
Array storing all nodes.
Definition: hash.h:77
Visualizes a Scalar PDE solution.
Definition: scalar_view.h:37
Represents a finite element space over a domain.
Definition: api2d.h:34
This class characterizes a neighborhood of a given edge in terms of adjacent elements and provides me...
Stores and searches node tables.
Definition: hash.h:39