From 076e104b8672924c3d80cd1da2fdb5ebee1766ac Mon Sep 17 00:00:00 2001 From: Douglas Rumbaugh Date: Thu, 24 Aug 2023 17:00:31 -0400 Subject: Migrated over to using psudb-common utilities/headers --- include/util/Cursor.h | 14 ++++------ include/util/base.h | 73 ------------------------------------------------ include/util/bf_config.h | 2 +- include/util/hash.h | 61 ---------------------------------------- include/util/timer.h | 37 ------------------------ include/util/types.h | 2 -- 6 files changed, 6 insertions(+), 183 deletions(-) delete mode 100644 include/util/base.h delete mode 100644 include/util/hash.h delete mode 100644 include/util/timer.h (limited to 'include/util') diff --git a/include/util/Cursor.h b/include/util/Cursor.h index 815458c..1b0b8ed 100644 --- a/include/util/Cursor.h +++ b/include/util/Cursor.h @@ -9,9 +9,11 @@ */ #pragma once -#include "util/base.h" #include "framework/RecordInterface.h" -#include "io/PagedFile.h" + +#include "psu-ds/BloomFilter.h" +#include "psu-ds/PriorityQueue.h" +#include "psu-util/alignment.h" namespace de { template @@ -37,19 +39,13 @@ struct Cursor { * not be closed. */ template -inline static bool advance_cursor(Cursor &cur, PagedFileIterator *iter = nullptr) { +inline static bool advance_cursor(Cursor &cur) { cur.ptr++; cur.cur_rec_idx++; if (cur.cur_rec_idx >= cur.rec_cnt) return false; if (cur.ptr >= cur.end) { - if (iter && iter->next()) { - cur.ptr = (R*)iter->get_item(); - cur.end = cur.ptr + (PAGE_SIZE / sizeof(R)); - return true; - } - return false; } return true; diff --git a/include/util/base.h b/include/util/base.h deleted file mode 100644 index 1729687..0000000 --- a/include/util/base.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * include/util/base.h - * - * Copyright (C) 2023 Douglas Rumbaugh - * Dong Xie - * - * All rights reserved. Published under the Modified BSD License. - * - */ -#pragma once - -#include -#include -#include -#include - -namespace de { - -// The correct quantity for use in alignment of buffers to be -// compatible with O_DIRECT -const size_t SECTOR_SIZE = 512; - -// The standard sized block of data (in bytes) for use in IO -// operations. -const size_t PAGE_SIZE = 4096; - -// The size of a cacheline, for alignment purposes. -const size_t CACHELINE_SIZE = 64; - -// The largest representable PageNum. A given file cannot -// have more pages than this. -const size_t MAX_PAGE_COUNT = UINT32_MAX; - -// The largest representable FileId. The file manager cannot -// manage more files than this. -const size_t MAX_FILE_COUNT = UINT32_MAX; - -// The largest representable FrameId. No buffer can be defined with -// more frames than this. -const size_t MAX_FRAME_COUNT = UINT32_MAX; - -// The number of bytes of zeroes available in ZEROBUF. Will be -// a multiple of the parm::PAGE_SIZE. -constexpr size_t ZEROBUF_SIZE = 8 * PAGE_SIZE; - -// A large, preallocated, buffer of zeroes used for pre-allocation -// of pages in a file. -alignas(SECTOR_SIZE) const char ZEROBUF[ZEROBUF_SIZE] = {0}; - - -// alignment code taken from TacoDB (file: tdb_base.h) -template -constexpr T -TYPEALIGN(uint64_t ALIGNVAL, T LEN) { - return (((uint64_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64_t) ((ALIGNVAL) - 1))); -} - -#define SHORTALIGN(LEN) TYPEALIGN(2, (LEN)) -#define INTALIGN(LEN) TYPEALIGN(4, (LEN)) -#define LONGALIGN(LEN) TYPEALIGN(8, (LEN)) -#define DOUBLEALIGN(LEN) TYPEALIGN(8, (LEN)) -#define MAXALIGN(LEN) TYPEALIGN(8, (LEN)) -#define CACHELINEALIGN(LEN) TYPEALIGN(CACHELINE_SIZE, (LEN)) -#define MAXALIGN_OF 8 - -// Returns a pointer to the idx'th page contained within a multi-page -// buffer. buffer must be page aligned, and idx must be less than the -// number of pages within the buffer, or the result is undefined. -static inline char *get_page(char *buffer, size_t idx) { - return buffer + (idx * PAGE_SIZE); -} - -} diff --git a/include/util/bf_config.h b/include/util/bf_config.h index b4d68bc..2390643 100644 --- a/include/util/bf_config.h +++ b/include/util/bf_config.h @@ -9,7 +9,7 @@ */ #pragma once -#include "util/base.h" +#include "psu-util/alignment.h" namespace de { diff --git a/include/util/hash.h b/include/util/hash.h deleted file mode 100644 index 04871dc..0000000 --- a/include/util/hash.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - * include/util/hash.h - * - * Copyright (C) 2023 Dong Xie - * - * All rights reserved. Published under the Modified BSD License. - * - */ -#pragma once - -#include -#include - -namespace de { - -// 40343 is a "magic constant" that works well, -// 38299 is another good value. -// Both are primes and have a good distribution of bits. -const uint64_t kHashMagicNum = 40343; - -inline uint64_t rotr64(uint64_t x, size_t n) { - return (((x) >> n) | ((x) << (64 - n))); -} - -inline uint64_t hash(uint64_t input) { - uint64_t local_rand = input; - uint64_t local_rand_hash = 8; - local_rand_hash = 40343 * local_rand_hash + ((local_rand) & 0xFFFF); - local_rand_hash = 40343 * local_rand_hash + ((local_rand >> 16) & 0xFFFF); - local_rand_hash = 40343 * local_rand_hash + ((local_rand >> 32) & 0xFFFF); - local_rand_hash = 40343 * local_rand_hash + (local_rand >> 48); - local_rand_hash = 40343 * local_rand_hash; - return rotr64(local_rand_hash, 43); -} - -inline uint64_t hash_bytes(const char* str, size_t len) { - uint64_t hashState = len; - - for(size_t idx = 0; idx < len; ++idx) { - hashState = kHashMagicNum * hashState + str[idx]; - } - - // The final scrambling helps with short keys that vary only on the high order bits. - // Low order bits are not always well distributed so shift them to the high end, where they'll - // form part of the 14-bit tag. - return rotr64(kHashMagicNum * hashState, 6); -} - -inline uint64_t hash_bytes_with_salt(const char* str, size_t len, uint16_t salt) { - uint64_t hashState = len; - - for(size_t idx = 0; idx < len; ++idx) { - hashState = kHashMagicNum * hashState + str[idx]; - } - - hashState = kHashMagicNum * hashState + salt; - - return rotr64(kHashMagicNum * hashState, 6); -} - -} diff --git a/include/util/timer.h b/include/util/timer.h deleted file mode 100644 index a9784a8..0000000 --- a/include/util/timer.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * include/util/timer.h - * - * Copyright (C) 2023 Douglas Rumbaugh - * - * All rights reserved. Published under the Modified BSD License. - * - */ -#pragma once - -#include - -#ifdef ENABLE_TIMER -#define TIMER_INIT() \ - auto timer_start = std::chrono::high_resolution_clock::now(); \ - auto timer_stop = std::chrono::high_resolution_clock::now(); - -#define TIMER_START() \ - timer_start = std::chrono::high_resolution_clock::now() - -#define TIMER_STOP() \ - timer_stop = std::chrono::high_resolution_clock::now() - -#define TIMER_RESULT() \ - std::chrono::duration_cast(timer_stop - timer_start).count() - -#else - #define TIMER_INIT() \ - do {} while(0) - #define TIMER_START() \ - do {} while(0) - #define TIMER_STOP() \ - do {} while(0) - #define TIMER_RESULT() \ - 0l -#endif - diff --git a/include/util/types.h b/include/util/types.h index de5e379..3010e78 100644 --- a/include/util/types.h +++ b/include/util/types.h @@ -18,8 +18,6 @@ #include #include -#include "util/base.h" - namespace de { using std::byte; -- cgit v1.2.3