| 72 | }; |
| 73 | |
| 74 | void AddFreeNode(NodeType* node) |
| 75 | { |
| 76 | // Use binary search to find the insert location (assumes that FreeNodes are always sorted) |
| 77 | int32 left = 0, right = FreeNodes.Count() - 1; |
| 78 | const uint32 nodeSize = (uint32)node->Width * (uint32)node->Height; |
| 79 | while (left <= right) |
| 80 | { |
| 81 | int32 mid = left + (right - left) / 2; |
| 82 | const NodeType* midNode = FreeNodes.Get()[mid]; |
| 83 | const uint32 midSize = (uint32)midNode->Width * (uint32)midNode->Height; |
| 84 | if (nodeSize == midSize) |
| 85 | { |
| 86 | // Insert right after node of the same size |
| 87 | left = mid; |
| 88 | break; |
| 89 | } |
| 90 | if (nodeSize > midSize) |
| 91 | { |
| 92 | // Go to the left half (contains nodes with higher sizes) |
| 93 | right = mid - 1; |
| 94 | } |
| 95 | else |
| 96 | { |
| 97 | // Go to the right half (contains nodes with lower sizes) |
| 98 | left = mid + 1; |
| 99 | } |
| 100 | } |
| 101 | FreeNodes.Insert(left, node); |
| 102 | } |
| 103 | |
| 104 | public: |
| 105 | FORCE_INLINE bool IsInitialized() |