File indexing completed on 2024-04-21 03:54:30

0001 /*
0002     SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef SPATIAL_INDEX_ENTRY_P_H
0008 #define SPATIAL_INDEX_ENTRY_P_H
0009 
0010 #include <cstdint>
0011 
0012 #pragma pack(push)
0013 #pragma pack(1)
0014 
0015 /** Entry in the spatial index.
0016  *  This is essentially just a pair of numbers, the first being the position
0017  *  on the z-order curve and defines the order, the second being the index into the
0018  *  property table.
0019  *
0020  *  These entries exist in very large quantities, so compact storage is important.
0021  */
0022 class SpatialIndexEntry
0023 {
0024 public:
0025     inline constexpr SpatialIndexEntry(uint32_t z, uint32_t propertyIdx)
0026         : m_z(z)
0027         , m_unused(0)
0028         , m_propHigh(propertyIdx >> 8)
0029         , m_propLow(propertyIdx)
0030     {
0031     }
0032 
0033     inline constexpr uint32_t z() const
0034     {
0035         return m_z;
0036     }
0037 
0038     inline constexpr uint32_t propertyIndex() const
0039     {
0040         return m_propHigh << 8 | m_propLow;
0041     }
0042 
0043 private:
0044     uint32_t m_z : 22;
0045     [[maybe_unused]] uint32_t m_unused : 6;
0046     uint32_t m_propHigh : 4;
0047     uint8_t m_propLow;
0048 };
0049 
0050 #pragma pack(pop)
0051 
0052 inline constexpr bool operator<(SpatialIndexEntry lhs, SpatialIndexEntry rhs)
0053 {
0054     return lhs.z() < rhs.z();
0055 }
0056 
0057 inline constexpr bool operator<(SpatialIndexEntry lhs, uint32_t rhs)
0058 {
0059     return lhs.z() < rhs;
0060 }
0061 
0062 inline constexpr bool operator<(uint32_t lhs, SpatialIndexEntry rhs)
0063 {
0064     return lhs < rhs.z();
0065 }
0066 
0067 #endif