File: fast_cache.hpp

package info (click to toggle)
seqan3 3.0.2%2Bds-9
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 16,052 kB
  • sloc: cpp: 144,641; makefile: 1,288; ansic: 294; sh: 228; xml: 217; javascript: 50; python: 27; php: 25
file content (43 lines) | stat: -rw-r--r-- 1,071 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2016, the SDSL Project Authors.  All rights reserved.
// Please see the AUTHORS file for details.  Use of this source code is governed
// by a BSD license that can be found in the LICENSE file.
#ifndef INCLUDED_SDSL_FAST_CACHE
#define INCLUDED_SDSL_FAST_CACHE

#include "int_vector.hpp"

namespace sdsl {

#define CACHE_SIZE 0x3FFULL

struct fast_cache {
	typedef int_vector<>::size_type size_type;
	size_type						m_table[2 * (CACHE_SIZE + 1)];
	// Constructor
	fast_cache()
	{
		for (size_type i = 0; i < (CACHE_SIZE + 1); ++i) {
			m_table[i << 1] = (size_type)-1;
		}
	}
	// Returns true if the request i is cached and
	// x is set to the answer of request i
	bool exists(size_type i, size_type& x)
	{
		if (m_table[(i & CACHE_SIZE) << 1] == i) {
			x = m_table[((i & CACHE_SIZE) << 1) + 1];
			return true;
		} else
			return false;
	}
	// Writes the answer for request i to the cache
	void write(size_type i, size_type x)
	{
		m_table[(i & CACHE_SIZE) << 1]		 = i;
		m_table[((i & CACHE_SIZE) << 1) + 1] = x;
	}
};

} // end namespace sdsl

#endif