-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d96f1bd
commit 361f228
Showing
8 changed files
with
119 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
|
||
typedef struct Hoard* hoard_t; | ||
|
||
hoard_t hoard_init(); | ||
int hoard_put(hoard_t h, int64_t* src, size_t count, size_t offset); | ||
int hoard_get(hoard_t h, int64_t* dest, size_t count, size_t offset); | ||
void hoard_finalize(hoard_t h); | ||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "hoard.hpp" | ||
#include "hoard-c.h" | ||
|
||
hoard_t hoard_init() | ||
{ | ||
Hoard* h = new (Hoard); | ||
return h; | ||
} | ||
int hoard_put(hoard_t h, int64_t* src, size_t count, size_t offset) | ||
{ | ||
return (h->put(src, count, offset)); | ||
} | ||
int hoard_get(hoard_t h, int64_t* dest, size_t count, size_t offset) | ||
{ | ||
return h->get(dest, count, offset); | ||
} | ||
void hoard_finalize(hoard_t h) { delete h; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#include <vector> | ||
#include <cstdint> | ||
#include <cstddef> | ||
#include <iostream> | ||
|
||
/* just a big ol' flat array of data. There is no paging out of excess | ||
* data. no least recently used or anything like that. Just how fast | ||
* can we update this data structure concurrently */ | ||
|
||
class Hoard { | ||
public: | ||
Hoard() = default; | ||
int put(int64_t* src, size_t count, size_t offset); | ||
int get(int64_t* dest, size_t count, size_t offset); | ||
|
||
private: | ||
std::vector<int64_t> m_hoard; | ||
void show() | ||
{ | ||
for (const auto& x : m_hoard) std::cout << x << " "; | ||
std::cout << std::endl; | ||
} | ||
}; | ||
|
||
int Hoard::put(int64_t* src, size_t count, size_t offset) | ||
{ | ||
if (m_hoard.size() < offset + count) | ||
m_hoard.resize((m_hoard.size() + offset + count) * 2); | ||
|
||
// having trouble using insert() correctly concurrently... | ||
// m_hoard.insert(m_hoard.begin()+offset, src, src+count); | ||
for (size_t i = 0; i < count; i++) m_hoard[offset + i] = src[i]; | ||
#ifdef DEBUG_HOARD | ||
std::cout << "Hoard::put: " << src[0] << "... " << count << " items at " | ||
<< offset << std::endl; | ||
; | ||
show(); | ||
#endif | ||
return count; | ||
} | ||
int Hoard::get(int64_t* dest, size_t count, size_t offset) | ||
{ | ||
#ifdef DEBUG_HOARD | ||
std::cout << "Hoard::get: " << count << " items at " << offset << " " | ||
<< m_hoard[offset] << std::endl; | ||
show(); | ||
#endif | ||
for (size_t i = 0; i < count; i++) dest[i] = m_hoard[offset + i]; | ||
return count; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters