CCF
Loading...
Searching...
No Matches
tpcc_common.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the Apache 2.0 License.
3#pragma once
4
5#include <random>
6
7namespace tpcc
8{
9 static constexpr int32_t num_warehouses = 10;
10 static constexpr int32_t districts_per_warehouse = 10;
11 static constexpr int32_t customers_per_district = 10;
12 static constexpr int32_t num_items = 100;
13 // YYYY-MM-DD HH:MM:SS This is supposed to be a date/time field from Jan 1st
14 // 1900 - Dec 31st 2100 with a resolution of 1 second. See TPC-C 1.3.1.
15 static constexpr int DATETIME_SIZE = 14;
16 static constexpr std::array<char, tpcc::DATETIME_SIZE + 1> tx_time = {
17 "12345 time"};
18
19 // Defined by TPC-C 4.3.2.3.
20 static void make_last_name(int num, char* name)
21 {
22 static const char* const SYLLABLES[] = {
23 "BAR",
24 "OUGHT",
25 "ABLE",
26 "PRI",
27 "PRES",
28 "ESE",
29 "ANTI",
30 "CALLY",
31 "ATION",
32 "EING",
33 };
34 static const int LENGTHS[] = {
35 3,
36 5,
37 4,
38 3,
39 4,
40 3,
41 4,
42 5,
43 5,
44 4,
45 };
46
47 int indicies[] = {num / 100, (num / 10) % 10, num % 10};
48
49 int offset = 0;
50 for (uint32_t i = 0; i < sizeof(indicies) / sizeof(*indicies); ++i)
51 {
52 memcpy(
53 name + offset,
54 SYLLABLES[indicies[i]],
55 static_cast<size_t>(LENGTHS[indicies[i]]));
56 offset += LENGTHS[indicies[i]];
57 }
58 name[offset] = '\0';
59 }
60
61 static float random_float(float min, float max, std::mt19937& rand_generator)
62 {
63 if (min == max)
64 {
65 return min;
66 }
67 std::uniform_real_distribution<float> dist(min, max);
68 return dist(rand_generator);
69 }
70
71 static uint32_t random_int(
72 uint32_t min, uint32_t max, std::mt19937& rand_generator)
73 {
74 if (min == max)
75 {
76 return min;
77 }
78 std::uniform_int_distribution<uint32_t> dist(min, max - 1);
79 return dist(rand_generator);
80 }
81
82 static int32_t random_int_excluding(
83 int lower, int upper, int excluding, std::mt19937& rand_generator)
84 {
85 int num = random_int(lower, upper - 1, rand_generator);
86 if (num >= excluding)
87 {
88 num += 1;
89 }
90 return num;
91 }
92}
Definition tpcc_common.h:8