VTK
vtkExodusIICache.h
Go to the documentation of this file.
1 #ifndef __vtkExodusIICache_h
2 #define __vtkExodusIICache_h
3 
4 // ============================================================================
5 // The following classes define an LRU cache for data arrays
6 // loaded by the Exodus reader. Here's how they work:
7 //
8 // The actual cache consists of two STL containers: a set of
9 // cache entries (vtkExodusIICacheEntry) and a list of
10 // cache references (vtkExodusIICacheRef). The entries in
11 // these containers are sorted for fast retrieval:
12 // 1. The cache entries are indexed by the timestep, the
13 // object type (edge block, face set, ...), and the
14 // object ID (if one exists). When you call Find() to
15 // retrieve a cache entry, you provide a key containing
16 // this information and the array is returned if it exists.
17 // 2. The list of cache references are stored in "least-recently-used"
18 // order. The least recently referenced array is the first in
19 // the list. Whenever you request an entry with Find(), it is
20 // moved to the back of the list if it exists.
21 // This makes retrieving arrays O(n log n) and popping LRU
22 // entries O(1). Each cache entry stores an iterator into
23 // the list of references so that it can be located quickly for
24 // removal.
25 
26 #include "vtkObject.h"
27 
28 #include <vtkstd/map> // used for cache storage
29 #include <vtkstd/list> // use for LRU ordering
30 
31 //BTX
33 {
34 public:
35  int Time;
37  int ObjectId;
38  int ArrayId;
40  {
41  Time = -1;
42  ObjectType = -1;
43  ObjectId = -1;
44  ArrayId = -1;
45  }
46  vtkExodusIICacheKey( int time, int objType, int objId, int arrId )
47  {
48  Time = time;
49  ObjectType = objType;
50  ObjectId = objId;
51  ArrayId = arrId;
52  }
54  {
55  Time = src.Time;
56  ObjectType = src.ObjectType;
57  ObjectId = src.ObjectId;
58  ArrayId = src.ArrayId;
59  }
60  bool match( const vtkExodusIICacheKey&other, const vtkExodusIICacheKey& pattern ) const
61  {
62  if ( pattern.Time && this->Time != other.Time )
63  return false;
64  if ( pattern.ObjectType && this->ObjectType != other.ObjectType )
65  return false;
66  if ( pattern.ObjectId && this->ObjectId != other.ObjectId )
67  return false;
68  if ( pattern.ArrayId && this->ArrayId != other.ArrayId )
69  return false;
70  return true;
71  }
72  bool operator < ( const vtkExodusIICacheKey& other ) const
73  {
74  if ( this->Time < other.Time )
75  return true;
76  else if ( this->Time > other.Time )
77  return false;
78  if ( this->ObjectType < other.ObjectType )
79  return true;
80  else if ( this->ObjectType > other.ObjectType )
81  return false;
82  if ( this->ObjectId < other.ObjectId )
83  return true;
84  else if ( this->ObjectId > other.ObjectId )
85  return false;
86  if ( this->ArrayId < other.ArrayId )
87  return true;
88  return false;
89  }
90 };
91 
93 class vtkExodusIICache;
95 
96 typedef vtkstd::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*> vtkExodusIICacheSet;
97 typedef vtkstd::map<vtkExodusIICacheKey,vtkExodusIICacheEntry*>::iterator vtkExodusIICacheRef;
98 typedef vtkstd::list<vtkExodusIICacheRef> vtkExodusIICacheLRU;
99 typedef vtkstd::list<vtkExodusIICacheRef>::iterator vtkExodusIICacheLRURef;
100 
102 {
103 public:
107 
109 
110  vtkDataArray* GetValue() { return this->Value; }
111 
112 protected:
115 
116  friend class vtkExodusIICache;
117 };
118 //ETX
119 
121 {
122 public:
123  static vtkExodusIICache* New();
125  void PrintSelf( ostream& os, vtkIndent indent );
126 
128  void Clear();
129 
131  void SetCacheCapacity( double sizeInMiB );
132 
137  double GetSpaceLeft()
138  { return this->Capacity - this->Size; }
139 
143  int ReduceToSize( double newSize );
144 
145  //BTX
147  void Insert( vtkExodusIICacheKey& key, vtkDataArray* value );
148 
153 
158  int Invalidate( vtkExodusIICacheKey key );
159 
169  int Invalidate( vtkExodusIICacheKey key, vtkExodusIICacheKey pattern );
170  //ETX
171 
172 protected:
175 
177  ~vtkExodusIICache();
178 
179 
181  void RecomputeSize();
182 
184  double Capacity;
185 
187  double Size;
188 
189  //BTX
197 
200  //ETX
201 
202 private:
203  vtkExodusIICache( const vtkExodusIICache& ); // Not implemented
204  void operator = ( const vtkExodusIICache& ); // Not implemented
205 };
206 #endif // __vtkExodusIICache_h