source: icGREP/icgrep-devel/icgrep/grep/searchable_buffer.h

Last change on this file was 6229, checked in by nmedfort, 5 months ago

Potential stall fix for -include=7*

File size: 1.3 KB
Line 
1#ifndef SEARCHABLE_BUFFER_H
2#define SEARCHABLE_BUFFER_H
3
4#include <llvm/ADT/StringRef.h>
5#include <util/aligned_allocator.h>
6#include <vector>
7
8namespace grep {
9
10class SearchableBuffer  {
11
12    enum : unsigned {
13        MAX_SIMD_WIDTH_SUPPORTED   = 512U
14        , DEFAULT_INITIAL_CAPACITY = 4096U
15    };
16
17    template <typename T>
18    using BufferAllocator = AlignedAllocator<T, (MAX_SIMD_WIDTH_SUPPORTED / (sizeof(T) * 8))>;
19
20    template <typename T>
21    using BufferType = std::vector<T, BufferAllocator<T>>;
22
23public:
24
25    void append(const llvm::StringRef candidate) {
26        mInternalBuffer.reserve(candidate.size() + 1);
27        mInternalBuffer.insert(mInternalBuffer.end(), candidate.begin(), candidate.end());
28        mInternalBuffer.push_back(0);
29        mEntries++;
30    }
31
32    void reset() {
33        mInternalBuffer.clear();
34        mEntries = 0;
35    }
36
37    size_t getCandidateCount() const {return mEntries; }
38
39    const char * data() const { return mInternalBuffer.data(); }
40
41    size_t size() const { return mInternalBuffer.size(); }
42
43    SearchableBuffer(const unsigned initialCapacity = DEFAULT_INITIAL_CAPACITY)
44    : mEntries(0) {
45        mInternalBuffer.reserve(initialCapacity);
46    }
47
48private:
49    size_t           mEntries;
50    BufferType<char> mInternalBuffer;
51};
52
53}
54
55#endif // SEARCHABLE_BUFFER_H
Note: See TracBrowser for help on using the repository browser.