@@ -316,38 +316,6 @@ static bool btree_compare_keys(
316
316
return key_comparer::bool_compare (comp, x, y);
317
317
}
318
318
319
- // btree_is_node_big<> is a recursive template to determine whether a
320
- // node of TargetNodeSize bytes needs a larger base_fields type
321
- // (uint16, instead of uint8) to accomodate >= 256 values per node.
322
- template <int TargetNodeSize, int ValueSize>
323
- struct btree_is_node_big :
324
- btree_is_node_big<(TargetNodeSize / 2 ), (ValueSize / 2 )> {
325
- };
326
- template <int TargetNodeSize>
327
- struct btree_is_node_big <TargetNodeSize, 1 > {
328
- enum {
329
- // In the base case, TargetNodeSize corresponds to single-byte
330
- // entries and is the maximum number of values.
331
- is_big = base::integral_constant<bool , (TargetNodeSize >= 256 )>::value,
332
- };
333
- };
334
-
335
- // A helper for sizing the btree node's base_fields. The "type"
336
- // typedef in this struct is an integral type large enough to hold as
337
- // many ValueSize-values as will fit a node of TargetNodeSize bytes.
338
- template <int TargetNodeSize, int ValueSize>
339
- struct btree_base_field_type {
340
- enum {
341
- // "value_space" is the maximum leaf node count. leaf nodes have
342
- // a greatest maximum of the node types.
343
- value_space = TargetNodeSize - 2 * sizeof (void *),
344
- };
345
- typedef typename base::if_<
346
- btree_is_node_big<value_space, ValueSize>::is_big,
347
- uint16,
348
- uint8>::type type;
349
- };
350
-
351
319
template <typename Key, typename Compare,
352
320
typename Alloc, int TargetNodeSize, int ValueSize>
353
321
struct btree_common_params {
@@ -365,12 +333,21 @@ struct btree_common_params {
365
333
typedef Key key_type;
366
334
typedef ssize_t size_type;
367
335
typedef ptrdiff_t difference_type;
368
- typedef typename btree_base_field_type<TargetNodeSize, ValueSize>::type
369
- base_field_type;
370
336
371
337
enum {
372
338
kTargetNodeSize = TargetNodeSize,
339
+
340
+ // Available space for values. This is largest for leaf nodes,
341
+ // which has overhead no fewer than two pointers.
342
+ kNodeValueSpace = TargetNodeSize - 2 * sizeof (void *),
373
343
};
344
+
345
+ // This is an integral type large enough to hold as many
346
+ // ValueSize-values as will fit a node of TargetNodeSize bytes.
347
+ typedef typename base::if_<
348
+ (kNodeValueSpace / ValueSize) >= 256 ,
349
+ uint16,
350
+ uint8>::type node_count_type;
374
351
};
375
352
376
353
// A parameters structure for holding the type parameters for a btree_map.
@@ -541,7 +518,7 @@ class btree_node {
541
518
linear_search_type, binary_search_type>::type search_type;
542
519
543
520
struct base_fields {
544
- typedef typename Params::base_field_type field_type;
521
+ typedef typename Params::node_count_type field_type;
545
522
546
523
// A boolean indicating whether the node is a leaf or not.
547
524
bool leaf;
@@ -1479,6 +1456,10 @@ class btree : public Params::key_compare {
1479
1456
COMPILE_ASSERT (kNodeValues <
1480
1457
(1 << (8 * sizeof (typename base_fields::field_type))),
1481
1458
target_node_size_too_large);
1459
+
1460
+ // Test the assumption made in setting kNodeValueSpace.
1461
+ COMPILE_ASSERT (sizeof (base_fields) >= 2 * sizeof (void *),
1462
+ node_space_assumption_incorrect);
1482
1463
};
1483
1464
1484
1465
// //
0 commit comments