aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/marisa-trie/marisa/grimoire/io/mapper.h
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-11-30 13:26:22 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-11-30 15:44:45 +0300
commit0a98fece5a9b54f16afeb3a94b3eb3105e9c3962 (patch)
tree291d72dbd7e9865399f668c84d11ed86fb190bbf /contrib/python/marisa-trie/marisa/grimoire/io/mapper.h
parentcb2c8d75065e5b3c47094067cb4aa407d4813298 (diff)
downloadydb-0a98fece5a9b54f16afeb3a94b3eb3105e9c3962.tar.gz
YQ Connector:Use docker-compose in integrational tests
Diffstat (limited to 'contrib/python/marisa-trie/marisa/grimoire/io/mapper.h')
-rw-r--r--contrib/python/marisa-trie/marisa/grimoire/io/mapper.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/contrib/python/marisa-trie/marisa/grimoire/io/mapper.h b/contrib/python/marisa-trie/marisa/grimoire/io/mapper.h
new file mode 100644
index 0000000000..e06072501d
--- /dev/null
+++ b/contrib/python/marisa-trie/marisa/grimoire/io/mapper.h
@@ -0,0 +1,68 @@
+#pragma once
+#ifndef MARISA_GRIMOIRE_IO_MAPPER_H_
+#define MARISA_GRIMOIRE_IO_MAPPER_H_
+
+#include <cstdio>
+
+#include "../../base.h"
+
+namespace marisa {
+namespace grimoire {
+namespace io {
+
+class Mapper {
+ public:
+ Mapper();
+ ~Mapper();
+
+ void open(const char *filename);
+ void open(const void *ptr, std::size_t size);
+
+ template <typename T>
+ void map(T *obj) {
+ MARISA_THROW_IF(obj == NULL, MARISA_NULL_ERROR);
+ *obj = *static_cast<const T *>(map_data(sizeof(T)));
+ }
+
+ template <typename T>
+ void map(const T **objs, std::size_t num_objs) {
+ MARISA_THROW_IF((objs == NULL) && (num_objs != 0), MARISA_NULL_ERROR);
+ MARISA_THROW_IF(num_objs > (MARISA_SIZE_MAX / sizeof(T)),
+ MARISA_SIZE_ERROR);
+ *objs = static_cast<const T *>(map_data(sizeof(T) * num_objs));
+ }
+
+ void seek(std::size_t size);
+
+ bool is_open() const;
+
+ void clear();
+ void swap(Mapper &rhs);
+
+ private:
+ const void *ptr_;
+ void *origin_;
+ std::size_t avail_;
+ std::size_t size_;
+#if (defined _WIN32) || (defined _WIN64)
+ void *file_;
+ void *map_;
+#else // (defined _WIN32) || (defined _WIN64)
+ int fd_;
+#endif // (defined _WIN32) || (defined _WIN64)
+
+ void open_(const char *filename);
+ void open_(const void *ptr, std::size_t size);
+
+ const void *map_data(std::size_t size);
+
+ // Disallows copy and assignment.
+ Mapper(const Mapper &);
+ Mapper &operator=(const Mapper &);
+};
+
+} // namespace io
+} // namespace grimoire
+} // namespace marisa
+
+#endif // MARISA_GRIMOIRE_IO_MAPPER_H_