• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

50.0
/include/spike/app/cache.hpp
1
/*  Cache format for seekless zip loading
2

3
    Copyright 2021-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19
#include "spike/io/bincore_fwd.hpp"
20
#include "spike/util/supercore.hpp"
21
#include <memory>
22
#include <string_view>
23
#include <thread>
24
#include <variant>
25

26
struct CacheGeneratorImpl;
27
struct HybridLeaf;
28
struct ZipEntryLeaf;
29
struct CacheHeader;
30

31
struct CacheBaseHeader {
32
  static constexpr uint32 ID = CompileFourCC("SPCH");
33
  uint32 id = ID;
34
  uint8 version = 3;
35
  uint8 numLevels;
36
  uint16 maxPathSize;
37
  uint32 numFiles;
38
  uint32 zipCRC;
39
  uint64 zipSize;
40
  uint64 zipCheckupOffset;
41
};
42

43
struct WALThread;
44

45
struct CacheGenerator {
46
  CacheGenerator();
47
  ~CacheGenerator();
48
  void AddFile(std::string_view fileName, size_t zipOffset, size_t fileSize);
49
  void WaitAndWrite(BinWritterRef wr);
50
  CacheBaseHeader meta{};
51

52
  struct Metrics {
53
    size_t numSearchHits;
54
    size_t numSearchMisses;
55
  };
56
  static Metrics GlobalMetrics();
57

58
private:
59
  friend class WALThread;
60
  std::unique_ptr<WALThread> workThread;
61
  std::thread walThread;
62
};
63

64
struct ZipEntry {
65
  uint64 offset;
66
  uint64 size = 0;
67
};
68

69
enum class ZIPIOEntryType {
70
  String,
71
  View,
72
};
73

74
struct ZIPIOEntry : ZipEntry {
×
75
  using variant_type = std::variant<std::string_view, std::string>;
76
  variant_type name;
77

78
  std::string_view AsView() const {
79
    return std::visit(
80
        [](auto &item) {
81
          return std::string_view{item.data(), item.size()};
82
        },
83
        name);
84
  }
85

86
  operator bool() const;
87
};
88

89
struct ZIPIOEntryRawIterator {
90
  virtual ZIPIOEntry Fist() const = 0;
91
  virtual ZIPIOEntry Next() const = 0;
92
  virtual size_t Count() const = 0;
93
  virtual ~ZIPIOEntryRawIterator() = default;
94
};
95

96
struct Cache {
97
  ZIPIOEntry FindFile(std::string_view pattern);
98
  ZipEntry RequestFile(std::string_view path);
99
  void Mount(const void *data_) { data = data_; }
1✔
100

101
  std::unique_ptr<ZIPIOEntryRawIterator> Iter(ZIPIOEntryType type) const;
102

103
private:
104
  friend struct ZIPIOEntryRawIterator_impl;
105
  friend struct ZIPIOContextCached;
106
  const CacheHeader &Header() const;
107

108
  const void *data;
109
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc