-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResultsCache.cpp
38 lines (31 loc) · 1.09 KB
/
ResultsCache.cpp
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
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <cstdio>
#include <cstring>
#include <iostream>
#include "ResultsCache.h"
bool ResultsCache::retrieveResult(unsigned int aCategory, unsigned int aMethodIdx, size_t aLength, int aId1, int aId2, float* aOut)
{
// Compute the key
sprintf(aKeyTmp, "%u|%u|%u|%d|%d", aCategory, aMethodIdx, static_cast<unsigned int>(aLength), aId1, aId2);
aKey = aKeyTmp;
// If it is in cache, copy the value to the output array
std::map< std::string, std::vector<float> >::const_iterator im = mCache.find(aKey);
if(im != mCache.end())
{
memcpy(aOut, &(im->second[0]), aLength*sizeof(float));
return true;
}
return false;
}
void ResultsCache::addResult(unsigned int aCategory, unsigned int aMethodIdx, size_t aLength, int aId1, int aId2, const float* aOut)
{
// Compute the key
sprintf(aKeyTmp, "%u|%u|%u|%d|%d", aCategory, aMethodIdx, static_cast<unsigned int>(aLength), aId1, aId2);
aKey = aKeyTmp;
// Cache the value
std::vector<float> x;
x.assign(aOut, aOut+aLength);
mCache[aKey] = x;
}