49 std::optional<FilePointer>
find(
char const* filePath);
58 static constexpr bool canLookUp(
char const* fileName) {
59 char const* c = fileName;
61 unsigned char ch = *c;
62 if (ch <
' ' || ch >
'~') {
79 return c != fileName && c[-1] !=
'.' && c[-1] !=
' ';
82 static constexpr size_t kMaxFolders = 4;
83 static constexpr size_t kMaxPathLength = 256;
97 static constexpr uint32_t kMinLookupsBeforeIndexing = 2;
98 static constexpr uint32_t kMaxLookupsBeforeIndexing = 64;
105 constexpr Space(
size_t start,
size_t blockSize)
106 : entriesEnd_{start}, namesStart_{blockSize < start ? start : blockSize}, blockSize_{namesStart_} {}
110 constexpr std::optional<uint16_t>
take(
size_t entrySize,
size_t namesSize) {
111 if (namesStart_ - entriesEnd_ < entrySize + namesSize
112 || blockSize_ - namesStart_ + namesSize > UINT16_MAX) {
115 entriesEnd_ += entrySize;
116 namesStart_ -= namesSize;
117 return blockSize_ - namesStart_;
128 FilePointer filePointer;
135 Folder* findFolder(
char const* path,
size_t pathLength);
136 Folder* indexFolder(
char const* path);
137 void forget(
size_t slot);
140 void indexingDidNotPay();
142 std::array<Folder*, kMaxFolders> folders_{};
143 char lastFolderLookedUp_[kMaxPathLength] = {};
145 uint32_t lookupsBeforeIndexing_ = kMinLookupsBeforeIndexing;
146 uint32_t useCounter_ = 0;
Definition sample_folder_index.cpp:51
constexpr Space(size_t start, size_t blockSize)
For a block of blockSize bytes whose first start bytes are taken.
Definition sample_folder_index.h:105
constexpr std::optional< uint16_t > take(size_t entrySize, size_t namesSize)
Definition sample_folder_index.h:110
Definition sample_folder_index.h:45
void blockStolen(Block *block)
Definition sample_folder_index.cpp:273
static constexpr uint32_t kMaxEntriesToRead
Definition sample_folder_index.h:86
void clear()
Forgets every folder, and frees the memory.
Definition sample_folder_index.cpp:298
uint32_t lookupsInARow_
Of files in lastFolderLookedUp_.
Definition sample_folder_index.h:144
std::optional< FilePointer > find(char const *filePath)
Definition sample_folder_index.cpp:89
void folderLost(Folder const &folder)
A folder's index is being thrown away, before it would have been otherwise.
Definition sample_folder_index.cpp:288
static constexpr bool canLookUp(char const *fileName)
Definition sample_folder_index.h:58
static constexpr size_t kMaxMemoryPerFolder
Definition sample_folder_index.h:89
static constexpr uint32_t kHitsToPayOff
Definition sample_folder_index.h:96
Definition sample_folder_index.h:127
uint16_t longName
Distances back from the end of the Entry's block to the names.
Definition sample_folder_index.h:129
One indexed folder. Its files are listed in its chain of Blocks, in the order they're in the folder.
Definition sample_folder_index.cpp:36