Hermes2D  2.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 Linearizer;
32  class Vectorizer;
33  class Orderizer;
34  };
35 
41  class HERMES_API HashTable : public Hermes::Mixins::Loggable
42  {
43  public:
45  Node* get_node(int id) const;
46 
48  int get_max_node_id() const;
49 
50  protected:
51  HashTable();
52  virtual ~HashTable();
53 
55  int get_num_nodes() const;
56 
58  Node* peek_vertex_node(int p1, int p2) const;
59 
61  Node* peek_edge_node(int p1, int p2) const;
62 
66  Node* get_vertex_node(int p1, int p2);
67 
71  Node* get_edge_node(int p1, int p2);
72 
73  static const int H2D_DEFAULT_HASH_SIZE = 0x8000; // 32K entries
74 
75  Array<Node> nodes;
76 
79  void init(int size = H2D_DEFAULT_HASH_SIZE);
80 
82  void copy(const HashTable* ht);
83 
85  void rebuild();
86 
88  void free();
89 
91  void remove_vertex_node(int id);
92 
94  void remove_edge_node(int id);
95 
96  // Internal members
97  private:
98 
99  Node** v_table;
100  Node** e_table;
101 
102  int mask;
103 
104  inline int hash(int p1, int p2) const { return (984120265*p1 + 125965121*p2) & mask; }
105 
108  Node* search_list(Node* node, int p1, int p2) const;
109 
111  void copy_list(Node** ptr, Node* node);
112 
113  friend struct Node;
114  friend class MeshReaderH2D;
115  template<typename Scalar> friend class NeighborSearch;
116  template<typename Scalar> friend class Space;
117  template<typename Scalar> friend class H1Space;
118  template<typename Scalar> friend class L2Space;
119  template<typename Scalar> friend class HcurlSpace;
120  template<typename Scalar> friend class HdivSpace;
121  friend class Views::ScalarView;
122  friend class Views::Linearizer;
123  };
124  }
125 }
126 #endif