OmniSciDB  29e35f4d58
anonymous_namespace{StringDictionary.cpp} Namespace Reference

Functions

size_t file_size (const int fd)
 
int checked_open (const char *path, const bool recover)
 
void * checked_mmap (const int fd, const size_t sz)
 
void checked_munmap (void *addr, size_t length)
 
const uint64_t round_up_p2 (const uint64_t num)
 
uint32_t rk_hash (const std::string &str)
 
template<class T >
void log_encoding_error (const std::string &str)
 
bool is_like (const std::string &str, const std::string &pattern, const bool icase, const bool is_simple, const char escape)
 
bool is_regexp_like (const std::string &str, const std::string &pattern, const char escape)
 

Variables

const int SYSTEM_PAGE_SIZE = getpagesize()
 

Function Documentation

◆ checked_mmap()

void* anonymous_namespace{StringDictionary.cpp}::checked_mmap ( const int  fd,
const size_t  sz 
)

Definition at line 58 of file StringDictionary.cpp.

References CHECK.

Referenced by StringDictionary::appendToStorage(), and StringDictionary::StringDictionary().

58  {
59  auto ptr = mmap(nullptr, sz, PROT_WRITE | PROT_READ, MAP_SHARED, fd, 0);
60  CHECK(ptr != reinterpret_cast<void*>(-1));
61 #ifdef __linux__
62 #ifdef MADV_HUGEPAGE
63  madvise(ptr, sz, MADV_RANDOM | MADV_WILLNEED | MADV_HUGEPAGE);
64 #else
65  madvise(ptr, sz, MADV_RANDOM | MADV_WILLNEED);
66 #endif
67 #endif
68  return ptr;
69 }
int64_t const int32_t sz
#define CHECK(condition)
Definition: Logger.h:193
+ Here is the caller graph for this function:

◆ checked_munmap()

void anonymous_namespace{StringDictionary.cpp}::checked_munmap ( void *  addr,
size_t  length 
)

Definition at line 70 of file StringDictionary.cpp.

References CHECK_EQ.

Referenced by StringDictionary::appendToStorage(), and StringDictionary::~StringDictionary().

70  {
71  CHECK_EQ(0, munmap(addr, length));
72 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
+ Here is the caller graph for this function:

◆ checked_open()

int anonymous_namespace{StringDictionary.cpp}::checked_open ( const char *  path,
const bool  recover 
)

Definition at line 47 of file StringDictionary.cpp.

References logger::ERROR, LOG, and File_Namespace::open().

Referenced by StringDictionary::StringDictionary().

47  {
48  auto fd = open(path, O_RDWR | O_CREAT | (recover ? O_APPEND : O_TRUNC), 0644);
49  if (fd > 0) {
50  return fd;
51  }
52  auto err = std::string("Dictionary path ") + std::string(path) +
53  std::string(" does not exist.");
54  LOG(ERROR) << err;
55  throw DictPayloadUnavailable(err);
56 }
#define LOG(tag)
Definition: Logger.h:188
FILE * open(int fileId)
Opens/creates the file with the given id; returns NULL on error.
Definition: File.cpp:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ file_size()

size_t anonymous_namespace{StringDictionary.cpp}::file_size ( const int  fd)

Definition at line 40 of file StringDictionary.cpp.

References CHECK_EQ.

Referenced by Catalog_Namespace::Catalog::adjustAlteredTableFiles(), get_filesize(), File_Namespace::FileMgr::init(), File_Namespace::FileMgr::openDBMetaFile(), File_Namespace::FileMgr::openEpochFile(), and StringDictionary::StringDictionary().

40  {
41  struct stat buf;
42  int err = fstat(fd, &buf);
43  CHECK_EQ(0, err);
44  return buf.st_size;
45 }
#define CHECK_EQ(x, y)
Definition: Logger.h:201
+ Here is the caller graph for this function:

◆ is_like()

bool anonymous_namespace{StringDictionary.cpp}::is_like ( const std::string &  str,
const std::string &  pattern,
const bool  icase,
const bool  is_simple,
const char  escape 
)

Definition at line 423 of file StringDictionary.cpp.

References string_ilike(), string_ilike_simple(), string_like(), and string_like_simple().

Referenced by StringDictionary::getLike().

427  {
428  return icase
429  ? (is_simple ? string_ilike_simple(
430  str.c_str(), str.size(), pattern.c_str(), pattern.size())
431  : string_ilike(str.c_str(),
432  str.size(),
433  pattern.c_str(),
434  pattern.size(),
435  escape))
436  : (is_simple ? string_like_simple(
437  str.c_str(), str.size(), pattern.c_str(), pattern.size())
438  : string_like(str.c_str(),
439  str.size(),
440  pattern.c_str(),
441  pattern.size(),
442  escape));
443 }
DEVICE bool string_ilike(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: StringLike.cpp:257
DEVICE bool string_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: StringLike.cpp:246
DEVICE bool string_ilike_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
Definition: StringLike.cpp:59
DEVICE bool string_like_simple(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len)
Definition: StringLike.cpp:43
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_regexp_like()

bool anonymous_namespace{StringDictionary.cpp}::is_regexp_like ( const std::string &  str,
const std::string &  pattern,
const char  escape 
)

Definition at line 713 of file StringDictionary.cpp.

References regexp_like().

Referenced by StringDictionary::getRegexpLike().

715  {
716  return regexp_like(str.c_str(), str.size(), pattern.c_str(), pattern.size(), escape);
717 }
DEVICE bool regexp_like(const char *str, const int32_t str_len, const char *pattern, const int32_t pat_len, const char escape_char)
Definition: Regexp.cpp:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ log_encoding_error()

template<class T >
void anonymous_namespace{StringDictionary.cpp}::log_encoding_error ( const std::string &  str)

Definition at line 264 of file StringDictionary.cpp.

References logger::ERROR, and LOG.

264  {
265  LOG(ERROR) << "Could not encode string: " << str
266  << ", the encoded value doesn't fit in " << sizeof(T) * 8
267  << " bits. Will store NULL instead.";
268 }
#define LOG(tag)
Definition: Logger.h:188

◆ rk_hash()

uint32_t anonymous_namespace{StringDictionary.cpp}::rk_hash ( const std::string &  str)

Definition at line 92 of file StringDictionary.cpp.

References StringDictionary::INVALID_STR_ID, StringDictionary::MAX_STRCOUNT, and StringDictionary::MAX_STRLEN.

Referenced by StringDictionary::getOrAddBulk(), StringDictionary::getOrAddImpl(), StringDictionary::getUnlocked(), StringDictionary::increaseCapacity(), and StringDictionary::StringDictionary().

92  {
93  uint32_t str_hash = 1;
94  // rely on fact that unsigned overflow is defined and wraps
95  for (size_t i = 0; i < str.size(); ++i) {
96  str_hash = str_hash * 997 + str[i];
97  }
98  return str_hash;
99 }
+ Here is the caller graph for this function:

◆ round_up_p2()

const uint64_t anonymous_namespace{StringDictionary.cpp}::round_up_p2 ( const uint64_t  num)

Definition at line 74 of file StringDictionary.cpp.

Referenced by StringDictionary::StringDictionary().

74  {
75  uint64_t in = num;
76  in--;
77  in |= in >> 1;
78  in |= in >> 2;
79  in |= in >> 4;
80  in |= in >> 8;
81  in |= in >> 16;
82  in++;
83  // TODO MAT deal with case where filesize has been increased but reality is
84  // we are constrained to 2^31.
85  // In that situation this calculation will wrap to zero
86  if (in == 0 || (in > (UINT32_MAX))) {
87  in = UINT32_MAX;
88  }
89  return in;
90 }
+ Here is the caller graph for this function:

Variable Documentation

◆ SYSTEM_PAGE_SIZE

const int anonymous_namespace{StringDictionary.cpp}::SYSTEM_PAGE_SIZE = getpagesize()