SDSL 3.0.3
Succinct Data Structure Library
Loading...
Searching...
No Matches
fast_cache.hpp
Go to the documentation of this file.
1// Copyright (c) 2016, the SDSL Project Authors. All rights reserved.
2// Please see the AUTHORS file for details. Use of this source code is governed
3// by a BSD license that can be found in the LICENSE file.
4#ifndef INCLUDED_SDSL_FAST_CACHE
5#define INCLUDED_SDSL_FAST_CACHE
6
7#include <sdsl/int_vector.hpp>
8
9namespace sdsl
10{
11
12#define CACHE_SIZE 0x3FFULL
13
15{
18 // Constructor
20 {
21 for (size_type i = 0; i < (CACHE_SIZE + 1); ++i)
22 {
23 m_table[i << 1] = (size_type)-1;
24 }
25 }
26 // Returns true if the request i is cached and
27 // x is set to the answer of request i
29 {
30 if (m_table[(i & CACHE_SIZE) << 1] == i)
31 {
32 x = m_table[((i & CACHE_SIZE) << 1) + 1];
33 return true;
34 }
35 else
36 return false;
37 }
38 // Writes the answer for request i to the cache
40 {
41 m_table[(i & CACHE_SIZE) << 1] = i;
42 m_table[((i & CACHE_SIZE) << 1) + 1] = x;
43 }
44};
45
46} // end namespace sdsl
47
48#endif
int_vector_size_type size_type
#define CACHE_SIZE
int_vector.hpp contains the sdsl::int_vector class.
Namespace for the succinct data structure library.
void write(size_type i, size_type x)
int_vector ::size_type size_type
bool exists(size_type i, size_type &x)
size_type m_table[2 *(CACHE_SIZE+1)]