File tree Expand file tree Collapse file tree 1 file changed +16
-6
lines changed
Expand file tree Collapse file tree 1 file changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -1415,21 +1415,31 @@ namespace OrthoTree
14151415
14161416 static inline constexpr depth_t GetDepthID (NodeID key) noexcept
14171417 {
1418- for (depth_t d = 0 ; IsValidKey (key); ++d, key = GetParentKey (key))
1419- if (key == 1 ) // If only sentinel bit remains, exit with node depth
1420- return d;
1418+ if constexpr (IS_LINEAR_TREE)
1419+ {
1420+ depth_t constexpr maxBitNo = IS_32BIT_LOCATION ? 32 : 64 ;
1421+ depth_t const leadingZeros = std::countl_zero (key);
1422+ depth_t const usedBitNo = maxBitNo - leadingZeros - 1 ;
1423+ return usedBitNo / DIMENSION_NO;
1424+ }
1425+ else
1426+ {
1427+ for (depth_t d = 0 ; IsValidKey (key); ++d, key = GetParentKey (key))
1428+ if (key == 1 ) // If only sentinel bit remains, exit with node depth
1429+ return d;
14211430
1422- CRASH (); // Bad key
1431+ CRASH (); // Bad key
1432+ }
14231433 return 0 ;
14241434 }
14251435
14261436 static inline constexpr NodeID RemoveSentinelBit (NodeIDCR key, std::optional<depth_t > depthIDOptional = std::nullopt ) noexcept
14271437 {
14281438 if constexpr (IS_LINEAR_TREE)
14291439 {
1430- constexpr depth_t bitCount = sizeof (NodeID) * CHAR_BIT;
1440+ depth_t constexpr maxBitNo = sizeof (NodeID) * CHAR_BIT;
14311441 auto const leadingZeros = std::countl_zero (key);
1432- auto const sentinelBitPosition = bitCount - leadingZeros - 1 ;
1442+ auto const sentinelBitPosition = maxBitNo - leadingZeros - 1 ;
14331443 return key - (NodeID{ 1 } << sentinelBitPosition);
14341444 }
14351445 else
You can’t perform that action at this time.
0 commit comments