Added files via upload

This commit is contained in:
ShikyC 2016-03-27 20:36:32 +08:00
parent 245af0eeb9
commit 15ce24de82
2 changed files with 65 additions and 45 deletions

View file

@ -11,39 +11,35 @@
#ifndef CACHE_H
#define CACHE_H
template<class T, int L>
class Cache
{
template <class T, int L>
class Cache {
public:
Cache();
void put(T value);
T get(int offset = 0) const;
Cache ();
void put (T value);
T get (int offset = 0) const;
private:
T data_[L];
T data_ [L];
int current_ = 0;
};
template<class T, int L>
Cache<T,L>::Cache()
{
for (int i = 0; i < L; i++){
data_[i] = 0;
template <class T, int L>
Cache <T, L>::Cache () {
for (int i = 0; i < L; i++) {
data_ [i] = 0;
}
}
template<class T, int L>
void Cache<T,L>::put(T value)
{
data_[current_] = value;
template <class T, int L>
void Cache <T, L>::put (T value) {
data_ [current_] = value;
current_ = (current_ + 1) % L;
}
template<class T, int L>
T Cache<T,L>::get(int offset) const
{
template <class T, int L>
T Cache <T, L>::get (int offset) const {
int index = (current_ + offset) % L;
return data_[index];
return data_ [index];
}
#endif // CACHE_H
#endif // CACHE_H