1 | /* |
2 | * Legal Notice |
3 | * |
4 | * This document and associated source code (the "Work") is a part of a |
5 | * benchmark specification maintained by the TPC. |
6 | * |
7 | * The TPC reserves all right, title, and interest to the Work as provided |
8 | * under U.S. and international laws, including without limitation all patent |
9 | * and trademark rights therein. |
10 | * |
11 | * No Warranty |
12 | * |
13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
23 | * WITH REGARD TO THE WORK. |
24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
32 | * |
33 | * Contributors |
34 | * - Sergey Vasilevskiy, Doug Johnson |
35 | */ |
36 | |
37 | /****************************************************************************** |
38 | * Description: This class encapsulates customer tier distribution |
39 | * functions and provides functionality to: |
40 | * - Generate customer tier based on customer ID |
41 | * - Generate non-uniform customer ID |
42 | * - Generate customer IDs in a specified partition, and |
43 | * outside the specified partition a set percentage of |
44 | * the time. |
45 | ******************************************************************************/ |
46 | |
47 | #ifndef CUSTOMER_SELECTION_H |
48 | #define CUSTOMER_SELECTION_H |
49 | |
50 | #include "utilities/Random.h" |
51 | |
52 | namespace TPCE { |
53 | |
54 | /* |
55 | * Define customer tier type. |
56 | */ |
57 | enum eCustomerTier { eCustomerTierOne = 1, eCustomerTierTwo, eCustomerTierThree }; |
58 | |
59 | class CCustomerSelection { |
60 | CRandom *m_pRND; // external random number generator |
61 | |
62 | TIdent m_iStartFromCustomer; |
63 | TIdent m_iCustomerCount; |
64 | |
65 | /* |
66 | * Used when partitioning by C_ID. |
67 | */ |
68 | bool m_bPartitionByCID; |
69 | int m_iPartitionPercent; |
70 | TIdent m_iMyStartFromCustomer; |
71 | TIdent m_iMyCustomerCount; |
72 | |
73 | /* |
74 | * Forward permutation (used to convert ordinal C_ID into real C_ID). |
75 | */ |
76 | TIdent Permute(TIdent iLow, TIdent iHigh); |
77 | |
78 | /* |
79 | * Inverse permutation (used to convert real C_ID into it's ordinal |
80 | * number). |
81 | */ |
82 | TIdent InversePermute(TIdent iLow, TIdent iHigh); |
83 | |
84 | /* |
85 | * Get lower 3 digits. |
86 | */ |
87 | inline TIdent CLow(TIdent C_ID) { |
88 | return ((C_ID - 1) % 1000); |
89 | } |
90 | |
91 | /* |
92 | * Get higher digits. |
93 | */ |
94 | inline TIdent CHigh(TIdent C_ID) { |
95 | return ((C_ID - 1) / 1000); |
96 | } |
97 | |
98 | public: |
99 | /* |
100 | * Default constructor. |
101 | */ |
102 | CCustomerSelection(); |
103 | |
104 | /* |
105 | * Constructor to set the customer range. |
106 | */ |
107 | CCustomerSelection(CRandom *pRND, TIdent iStartFromCustomer, TIdent iCustomerCount); |
108 | |
109 | /* |
110 | * Constructor to set subrange when paritioning by C_ID. |
111 | */ |
112 | CCustomerSelection(CRandom *pRND, TIdent iStartFromCustomer, TIdent iCustomerCount, int iPartitionPercent, |
113 | TIdent iMyStartFromCustomer, TIdent iMyCustomerCount); |
114 | |
115 | /* |
116 | * Re-set the customer range for the parition. |
117 | */ |
118 | void SetPartitionRange(TIdent iStartFromCustomer, TIdent iCustomerCount); |
119 | |
120 | /* |
121 | * Return scrambled inverse customer id. |
122 | */ |
123 | UINT GetInverseCID(TIdent C_ID); |
124 | |
125 | /* |
126 | * Return customer tier. |
127 | */ |
128 | eCustomerTier GetTier(TIdent C_ID); |
129 | |
130 | /* |
131 | * Return a non-uniform random customer and the associated tier. |
132 | */ |
133 | void GenerateRandomCustomer(TIdent &C_ID, eCustomerTier &C_TIER); |
134 | }; |
135 | |
136 | } // namespace TPCE |
137 | |
138 | #endif // CUSTOMER_SELECTION_H |
139 | |