public int Iterate(RowTree tree, ushort value) { var noOfInstructions = tree.Instructions.Length; int currentCheck = -1; uint resultBitField = 0; for (var i = 0; i < noOfInstructions; i += 1) { var currentInstruction = tree.Instructions[i]; if (currentCheck != currentInstruction.Chunk) { currentCheck = currentInstruction.Chunk; // do check resultBitField = mEvaluator.Evaluate(tree.TestChunks[currentCheck], tree.Branches, value); } var validationMask = resultBitField & currentInstruction.Mask; if (validationMask > 0) { var branchIndex = mAnalyser.GetRightmostBit(validationMask) + tree.TestChunks[currentCheck].KeyOffset; var arrayIndex = tree.TestChunks[currentCheck].LeafOffset + branchIndex; return(tree.Leaves[arrayIndex]); } } return(-1); }
public void Iterate_2() { var evaluator = new Mock <INodeEvaluator>(); var analyser = new Mock <IBitAnalyser>(); var stepper = new Stepper(evaluator.Object, analyser.Object); ushort[] BRANCH_KEYS = new ushort[] { // first branch key 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, }; const int FIRST_MASK = 0x1; const int SECOND_MASK = 0xfe; var rowTree = new RowTree { Branches = BRANCH_KEYS, Instructions = new Instruction[] { new Instruction { Chunk = 0, Mask = FIRST_MASK, }, new Instruction { Chunk = 0, Mask = SECOND_MASK, }, }, Leaves = new int[] { 0, }, TestChunks = new TestChunk[] { new TestChunk { KeyOffset = 0, LeafOffset = 0, LeafLength = 16, } }, }; ushort value = 100; evaluator.Setup(ev => ev.Evaluate(It.IsAny <TestChunk>(), It.IsAny <ushort[]>(), value)) .Returns(0xfe); analyser.Setup(a => a.GetRightmostBit(It.IsAny <uint>())) .Returns(0); var actual = stepper.Iterate(rowTree, value); Assert.AreEqual(0, actual); evaluator.Verify(ev => ev.Evaluate(It.IsAny <TestChunk>(), BRANCH_KEYS, value), Times.Once()); analyser.Verify(a => a.GetRightmostBit(It.IsAny <uint>()), Times.Once()); analyser.Verify(a => a.GetRightmostBit(SECOND_MASK), Times.Once()); evaluator.VerifyNoOtherCalls(); analyser.VerifyNoOtherCalls(); }
public void RestoreExpandedRows(RowTree rows) { if (rows == null) { return; } CurrencyManager source = grid.CurrencyManager; if (source == null) { return; // No data source. } RowTree current = rows; int currentLevel = 0; for (int index = 0; index < source.List.Count; index++) { MemberWrapper wrapper = (MemberWrapper)source.List[index]; Debug.Assert(wrapper != null, "wrapper != null"); CellEditorData cellData = (CellEditorData)wrapper.Tag; Debug.Assert(cellData != null, "cellData != null"); if (cellData.IsExpanded || cellData.Level > currentLevel) { continue; // Already expanded or below an expanded node for which we don't have any children listed. } while (cellData.Level < currentLevel) { current = current.Parent; currentLevel--; } RowTree expanded = current[wrapper.Name]; if (expanded != null) { // Found it - expand this row. NameColumn.ExpandRow(source, index); // Look for child expanded rows (if any). current = expanded; currentLevel++; } } }
public void SaveExpandedRows(ref RowTree rows) { CurrencyManager source = grid.CurrencyManager; if (source == null) { return; // No data source. } if (rows == null) { rows = new RowTree(null, null); } RowTree parent = rows; int currentLevel = 0; for (int index = 0; index < source.List.Count; index++) { MemberWrapper wrapper = (MemberWrapper)source.List[index]; Debug.Assert(wrapper != null, "wrapper != null"); CellEditorData cellData = (CellEditorData)wrapper.Tag; Debug.Assert(cellData != null, "cellData != null"); while (cellData.Level < currentLevel) { Debug.Assert(parent.Parent != null, "parent.Parent != null"); parent = parent.Parent; currentLevel--; } if (cellData.IsExpanded) { RowTree current = parent[wrapper.Name]; if (current == null) { current = new RowTree(wrapper.Name, parent); parent.Add(current); } parent = current; currentLevel++; } else if (parent[wrapper.Name] != null) { parent.Remove(wrapper.Name); } } }
public void Iterate_0() { var evaluator = new Mock <INodeEvaluator>(); var analyser = new Mock <IBitAnalyser>(); var stepper = new Stepper(evaluator.Object, analyser.Object); var rowTree = new RowTree { Branches = new ushort[] { }, Instructions = new Instruction[] { }, Leaves = new int[] { }, TestChunks = new TestChunk[] { }, }; ushort value = 100; var actual = stepper.Iterate(rowTree, value); Assert.AreEqual(-1, actual); evaluator.Verify(ev => ev.Evaluate(It.IsAny <TestChunk>(), It.IsAny <ushort[]>(), value), Times.Never()); analyser.Verify(a => a.GetRightmostBit(It.IsAny <uint>()), Times.Never()); evaluator.VerifyNoOtherCalls(); analyser.VerifyNoOtherCalls(); }
internal void Add(RowTree row) { m_children.Add(row.Name, row); }
internal RowTree(string name, RowTree parent) { m_name = name; m_parent = parent; }