public static int GetIndexOfFirstMatchingFsmValue(IPage page, FsmValue targetFsm) { FreeSpaceMapPageHeader header = GetFsmPageHeader(page); var content = page.Content; var length = content.Length; var fsmByte = (byte)targetFsm; const int full = ((byte)FsmValue.Full | ((byte)FsmValue.Full << 4)); for (int i = header.Length; i < length; i++) { if (content[i] == full) { continue; } var first = (byte)(0x0F & content[i]); var second = (byte)((0xF0 & content[i]) >> 4); if (first == fsmByte) { return((i - header.Length) * 2); } if (second == fsmByte) { return((i - header.Length) * 2 + 1); } } return(-1); }
public static void SetAllFsmValues(IPage page, FsmValue value) { FreeSpaceMapPageHeader header = GetFsmPageHeader(page); byte byteValue = (byte)((byte)value | ((byte)value << 4)); for (int i = header.Length; i < page.Length; i++) { page.Content[i] = byteValue; } }
public static FsmValue GetFsmValue(IPage page, int index) { FreeSpaceMapPageHeader header = GetFsmPageHeader(page); int i = header.Length + index / 2; if (index % 2 == 0) { return((FsmValue)(0x0F & page.Content[i])); } return((FsmValue)((0x0F & page.Content[i] >> 4))); }
public static PageHeaderBase GetPageHeader(IPage page) { PageHeaderBase ph; PageType pt = PageHeaderBase.GetPageType(page); switch (pt) { case PageType.FreeSpaceMap: ph = new FreeSpaceMapPageHeader(); ph.Read(page); return(ph); case PageType.Heading: ph = new HeadingPageHeader(); ph.Read(page); return(ph); case PageType.MultipageItem: ph = new MultipageItemPageHeader(); ph.Read(page); return(ph); case PageType.FixedSizeItem: ph = new FixedSizeItemsPageHeader(); ph.Read(page); return(ph); case PageType.BPlusTree: ph = new BPlusTreeNodePageHeader(); ph.Read(page); return(ph); case PageType.RadixTree: ph = new RadixTreeNodesPageHeader(); ph.Read(page); return(ph); } return(null); }
public static void SetFsmValue(IPage page, int index, FsmValue newValue) { FreeSpaceMapPageHeader header = GetFsmPageHeader(page); if (index < 0 || index > (page.Length - header.Length) * 2) { throw new ArgumentOutOfRangeException(nameof(index)); } int targetIndex = index / 2 + header.Length; byte b = page.Content[targetIndex]; if (index % 2 == 0) { b = (byte)((b & 0xF0) | (byte)newValue); } else { b = (byte)((b & 0x0F) | ((byte)newValue << 4)); } page.Content[targetIndex] = b; }