From 810f22d976a9eaaa69001f6ed9ec8a31de5a967e Mon Sep 17 00:00:00 2001 From: Michael Steindorfer Date: Fri, 19 Aug 2022 14:30:48 +0200 Subject: [PATCH] [Capsule] Add sequence representations for slices --- .../_BitmapIndexedDictionaryNode.swift | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/Sources/Capsule/_BitmapIndexedDictionaryNode.swift b/Sources/Capsule/_BitmapIndexedDictionaryNode.swift index d2ff179c..16fb7294 100644 --- a/Sources/Capsule/_BitmapIndexedDictionaryNode.swift +++ b/Sources/Capsule/_BitmapIndexedDictionaryNode.swift @@ -98,11 +98,26 @@ final class BitmapIndexedDictionaryNode: DictionaryNode where Key: H } var nodeSliceInvariant: Bool { - UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).prefix(bitmapIndexedNodeArity).allSatisfy { $0 is ReturnBitmapIndexedNode } + UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).prefix(header.nodeCount).allSatisfy { $0 is ReturnBitmapIndexedNode } } var collSliceInvariant: Bool { - UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).suffix(hashCollisionNodeArity).allSatisfy { $0 is ReturnHashCollisionNode } + UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).suffix(header.collCount).allSatisfy { $0 is ReturnHashCollisionNode } + } + + // TODO: should not materialize as `Array` for performance reasons + var _dataSlice: [ReturnPayload] { + UnsafeMutableBufferPointer(start: dataBaseAddress, count: header.dataCount).map { $0 } + } + + // TODO: should not materialize as `Array` for performance reasons + var _nodeSlice: [ReturnBitmapIndexedNode] { + UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).prefix(header.nodeCount).map { $0 as! ReturnBitmapIndexedNode } + } + + // TODO: should not materialize as `Array` for performance reasons + var _collSlice: [ReturnHashCollisionNode] { + UnsafeMutableBufferPointer(start: trieBaseAddress, count: header.trieCount).suffix(header.collCount).map { $0 as! ReturnHashCollisionNode } } init(dataCapacity: Capacity, trieCapacity: Capacity) {