Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
cache_simulator.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2004 Tanguy Fautré.
3 // For conditions of distribution and use,
4 // see copyright notice in tri_stripper.h
5 //
7 // SVN: $Id: cache_simulator.h 86 2005-06-08 17:47:27Z gpsnoopy $
9 
10 #ifndef TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H
11 #define TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H
12 
13 #include <algorithm>
14 #include <limits>
15 #include <deque>
16 
17 
18 
19 
20 namespace triangle_stripper {
21 
22  namespace detail {
23 
24 
25 
26 
28 {
29 public:
31 
32  void clear();
33  void resize(size_t Size);
34  void reset();
35  void push_cache_hits(bool Enabled = true);
36  size_t size() const;
37 
38  void push(index i, bool CountCacheHit = false);
39  void merge(const cache_simulator & Backward, size_t PossibleOverlap);
40 
41  void reset_hitcount();
42  size_t hitcount() const;
43 
44 protected:
45  typedef std::deque<index> indices_deque;
46 
47  indices_deque m_Cache;
48  size_t m_NbHits;
49  bool m_PushHits;
50 };
51 
52 
53 
54 
55 
57 // cache_simulator inline functions
59 
61  : m_NbHits(0),
63 {
64 
65 }
66 
67 
69 {
71  m_Cache.clear();
72 }
73 
74 
75 inline void cache_simulator::resize(const size_t Size)
76 {
78 }
79 
80 
82 {
83  std::fill(m_Cache.begin(), m_Cache.end(), std::numeric_limits<index>::max());
85 }
86 
87 
88 inline void cache_simulator::push_cache_hits(bool Enabled)
89 {
90  m_PushHits = Enabled;
91 }
92 
93 
94 inline size_t cache_simulator::size() const
95 {
96  return m_Cache.size();
97 }
98 
99 
100 inline void cache_simulator::push(const index i, const bool CountCacheHit)
101 {
102  if (CountCacheHit || m_PushHits) {
103 
104  if (std::find(m_Cache.begin(), m_Cache.end(), i) != m_Cache.end()) {
105 
106  // Should we count the cache hits?
107  if (CountCacheHit)
108  ++m_NbHits;
109 
110  // Should we not push the index into the cache if it's a cache hit?
111  if (! m_PushHits)
112  return;
113  }
114  }
115 
116  // Manage the indices cache as a FIFO structure
117  m_Cache.push_front(i);
118  m_Cache.pop_back();
119 }
120 
121 
122 inline void cache_simulator::merge(const cache_simulator & Backward, const size_t PossibleOverlap)
123 {
124  const size_t Overlap = std::min(PossibleOverlap, size());
125 
126  for (size_t i = 0; i < Overlap; ++i)
127  push(Backward.m_Cache[i], true);
128 
129  m_NbHits += Backward.m_NbHits;
130 }
131 
132 
134 {
135  m_NbHits = 0;
136 }
137 
138 
139 inline size_t cache_simulator::hitcount() const
140 {
141  return m_NbHits;
142 }
143 
144 
145 
146 
147  } // namespace detail
148 
149 } // namespace triangle_stripper
150 
151 
152 
153 
154 #endif // TRI_STRIPPER_HEADER_GUARD_CACHE_SIMULATOR_H
png_uint_32 i
Definition: png.h:2640
void merge(const cache_simulator &Backward, size_t PossibleOverlap)
#define true
Definition: ftrandom.c:49
float min(float a, float b)
Definition: Vector2.hpp:307
local int max
Definition: enough.c:170
unsigned int index
Definition: public_types.h:21
void push(index i, bool CountCacheHit=false)