internal Style(Workbook wb, XfRecord xf) : base(wb) { if (xf.FontIdx > 0 && xf.FontIdx < wb.Fonts.Count) { _font = wb.Fonts[xf.FontIdx - 1]; } _format = wb.Formats[xf.FormatIdx]; _typeAndProtection = xf.TypeAndProtection; if (_typeAndProtection.IsCell) { _parentStyle = wb.Styles[xf.ParentIdx]; } _horizontalAlignment = xf.HorizontalAlignment; _wrapped = xf.Wrapped; _verticalAlignment = xf.VerticalAlignment; _rotation = xf.Rotation; _indentLevel = xf.IndentLevel; _shrinkContent = xf.ShrinkContent; _parentStyleAttributes = xf.ParentStyle; _leftLineStyle = xf.LeftLineStyle; _rightLineStyle = xf.RightLineStyle; _topLineStyle = xf.TopLineStyle; _bottomLineStyle = xf.BottomLineStyle; _leftLineColor = wb.Palette.GetColor(xf.LeftLineColor); _rightLineColor = wb.Palette.GetColor(xf.RightLineColor); _diagonalRightTopToLeftBottom = xf.DiagonalRightTopToLeftBottom; _diagonalLeftBottomToTopRight = xf.DiagonalLeftBottomToTopRight; _topLineColor = wb.Palette.GetColor(xf.TopLineColor); _bottomLineColor = wb.Palette.GetColor(xf.BottomLineColor); _diagonalLineColor = wb.Palette.GetColor(xf.DiagonalLineColor); _diagonalLineStyle = xf.DiagonalLineStyle; _fillPattern = xf.FillPattern; _patternColor = wb.Palette.GetColor(xf.PatternColor); _patternBackground = wb.Palette.GetColor(xf.PatternBackground); }
public static bool EqualsZero(Nibble a) { var eq0high = EqualsZero(a.High); var eq0low = EqualsZero(a.Low); return(Gates.And(eq0high, eq0low)); }
public Direction2D(Radians angle) { float radians = angle.FloatAsRadians(); float increment = (radians / Mathf.PI) * 8; var nibble = Nibble.Zero; if (increment < 3 || increment > 13) { nibble |= (Nibble)CONST_RIGHT; } if (increment < 7 && increment > 1) { nibble |= (Nibble)CONST_UP; } if (increment < 11 && increment > 5) { nibble |= (Nibble)CONST_LEFT; } if (increment < 15 && increment > 9) { nibble |= (Nibble)CONST_DOWN; } this.value = nibble; }
private void InvSubNibble(ref Nibble nibble) { int x = nibble.NibbleValue >> 2; int y = (byte)(nibble.NibbleValue << 6) >> 6; nibble.NibbleValue = _sBoxI[x * 4 + y]; }
public Block(Word wordN1N2, Word wordN3N4) { _nibbles = new Nibble[4]; _nibbles[0] = wordN1N2.HighNibble; _nibbles[1] = wordN1N2.LowNibble; _nibbles[2] = wordN3N4.HighNibble; _nibbles[3] = wordN3N4.LowNibble; }
public Block(Nibble n1, Nibble n2, Nibble n3, Nibble n4) { _nibbles = new Nibble[4]; _nibbles[0] = n1; _nibbles[1] = n2; _nibbles[2] = n3; _nibbles[3] = n4; }
// component = X | Recipient public bool Read(byte component) { if (Nibble.ToNibble(reciever, false) == component) { return(true); } return(false); }
// 브랜치 노드의 차일드 노드 public TrieNode GetChild(Nibble radix) { if (Type != NodeType.FullNode) { throw new Exception("can't access child node"); } DecodeRLP(); return(chidrens[radix]); }
public Direction2D(Vector2 vector) { if (vector == Vector2.zero) { this.value = Nibble.Zero; return; } this.value = new Direction2D(new Radians(vector)).value; }
/// <summary> /// The constructor for the record. /// </summary> /// <param name="biff">The GenericBiff record that should contain the correct type and data for the XF record.</param> /// <exception cref="InvalidRecordIdException"> /// An InvalidRecordIdException is thrown if biff contains an invalid type or invalid data. /// </exception> public XfRecord(GenericBiff biff) { if (biff.Id == (ushort)RecordType.Xf) { BinaryReader reader = new BinaryReader(biff.GetDataStream()); _fontIdx = reader.ReadUInt16(); _formatIdx = reader.ReadUInt16(); ushort data = reader.ReadUInt16(); _typeAndProtection = new TypeAndProtection(data & 0x000F); _parentIdx = (ushort)((data & 0xFFF0) >> 8); byte data2 = reader.ReadByte(); _horizontalAlignment = (HorizontalAlignment)(data2 & 0x07); _wrapped = (data & 0x088) != 0; _verticalAlignment = (VerticalAlignment)((data2 & 0x70) >> 4); data2 = reader.ReadByte(); _rotation = new Rotation(data2); data2 = reader.ReadByte(); _indentLevel = new Nibble((byte)(data2 & 0x0F)); _shrinkContent = (data2 & 0x10) == 1; _parentStyle = (ParentStyleAttributes)(reader.ReadByte()); uint data3 = reader.ReadUInt32(); _leftLineStyle = (LineStyle)(data3 & 0x0000000F); _rightLineStyle = (LineStyle)((data3 & 0x000000F0) >> 1); _topLineStyle = (LineStyle)((data3 & 0x00000F00) >> 2); _bottomLineStyle = (LineStyle)((data3 & 0x0000F000) >> 3); _rightLineColor = (ushort)((data3 & 0x007F0000) >> 4); _leftLineColor = (ushort)((data3 & 0x3F800000) >> 5); _diagonalRightTopToLeftBottom = (data & 0x40000000) == 1; _diagonalLeftBottomToTopRight = (data & 0x80000000) == 1; data3 = reader.ReadUInt32(); _topLineColor = (ushort)(data3 & 0x0000007F); _bottomLineColor = (ushort)((data3 & 0x00003F80) >> 1); _diagonalLineColor = (ushort)((data3 & 0x001FC000) >> 3); _diagonalLineStyle = (LineStyle)((data3 & 0x01E00000) >> 5); _fillPattern = (FillPattern)((data3 & 0xFC000000) >> 6); data = reader.ReadUInt16(); _patternColor = (ushort)(data & 0x007F); _patternBackground = (ushort)((data & 0x3F80) >> 7); Debug.Assert(reader.BaseStream.Position == reader.BaseStream.Length); } else { throw new InvalidRecordIdException(biff.Id, RecordType.Xf); } }
// 브랜치 노드의 차일드 노드 public void SetChild(Nibble radix, TrieNode node) { if (Type != NodeType.FullNode) { throw new Exception("can't access child node"); } DecodeRLP(); chidrens[radix] = node; Dirty = true; }
public static Nibble[] FromBytes(params byte[] bytes) { Nibble[] nibbles = new Nibble[2 * bytes.Length]; for (int i = 0; i < bytes.Length; i++) { nibbles[i * 2] = new Nibble((byte)((bytes[i] & 240) >> 4)); nibbles[i * 2 + 1] = new Nibble((byte)(bytes[i] & 15)); } return(nibbles); }
private void InvMixColumns(ref Block block) { Nibble[] tempArray = new Nibble[4]; block.Nibbles.CopyTo(tempArray, 0); tempArray[0].NibbleValue = (byte)(GMul(0x9, block.Nibbles[0].NibbleValue) ^ GMul(0x2, block.Nibbles[1].NibbleValue)); tempArray[1].NibbleValue = (byte)(GMul(0x2, block.Nibbles[0].NibbleValue) ^ GMul(0x9, block.Nibbles[1].NibbleValue)); tempArray[2].NibbleValue = (byte)(GMul(0x9, block.Nibbles[2].NibbleValue) ^ GMul(0x2, block.Nibbles[3].NibbleValue)); tempArray[3].NibbleValue = (byte)(GMul(0x2, block.Nibbles[2].NibbleValue) ^ GMul(0x9, block.Nibbles[3].NibbleValue)); tempArray.CopyTo(block.Nibbles, 0); }
public Nibble PopFront() { Nibble nibble = Nibble.Null; if (Length > 0) { nibble = this[0]; Path = Path.Skip(1).ToArray(); } return(nibble); }
public Nibble Pop() { Nibble nibble = Nibble.Null; if (Length > 0) { nibble = this[Length - 1]; Path = Path.Take(Length - 1).ToArray(); } return(nibble); }
internal MCP23S17RegisterNibble(Nibble nibble, byte address, MCP23S17 chip) : base(address, chip) { this._nibble = nibble; this.Bits = new MCP23S17RegisterBit[4]; var rangeStart = nibble.GetRangeStart(); var rangeEnd = nibble.GetRangeEnd(); for (var i = rangeStart; i < rangeEnd; i++) { this.Bits[i - rangeStart] = new MCP23S17RegisterBit(i, address, chip); } }
public Block(Word[] words) { if (words.Length != 2) { throw new ArgumentOutOfRangeException($"Arguemnt {nameof(words)} should be of length 2"); } _nibbles = new Nibble[4]; _nibbles[0] = words[0].HighNibble; _nibbles[1] = words[0].LowNibble; _nibbles[2] = words[1].HighNibble; _nibbles[3] = words[1].LowNibble; }
public Block(byte[] block) { if (block.Length != 2) { throw new ArgumentOutOfRangeException($"Arguemnt {nameof(block)} should be of length 2"); } _nibbles = new Nibble[4]; _nibbles[0] = new Nibble(block[0], false); _nibbles[1] = new Nibble(block[0]); _nibbles[2] = new Nibble(block[1], false); _nibbles[3] = new Nibble(block[1]); }
public Nibble[] PopFront(int count) { List <Nibble> nibbles = new List <Nibble>(); for (int i = 0; i < count; i++) { Nibble nibble = PopFront(); if (!nibble.IsNull) { nibbles.Add(nibble); } } return(nibbles.ToArray()); }
public Byte2 Do(Nibble address, bool store, Byte2 data, bool clock) { var invertedAddress = Gates.Invert(address.Three); var storeAtRam0 = Gates.And(invertedAddress, store); var storeAtRam1 = Gates.And(address.Three, store); var output0 = _ram0.Do(address, storeAtRam0, data, clock); var output1 = _ram1.Do(address, storeAtRam1, data, clock); var outputTotal = Select16.Do(address.Three, output1, output0); return(outputTotal); }
private Nibble AddDirectionComponent(Nibble direction) { Nibble value = this.value | direction; if (value.ContainsAllFlags(HorizontalConflict)) { value &= ~HorizontalConflict; } if (value.ContainsAllFlags(VerticalConflict)) { value &= ~VerticalConflict; } return(value); }
public static Byte AddNibble(Nibble a, Nibble b, bool c) { var add1 = AddTwoBits(a.Low, b.Low, c); var add2 = AddTwoBits(a.High, b.High, add1.Two); var high = new Nibble(new Bit2(false, false), new Bit2(add2.High.High, add2.High.Low)); var low = new Nibble(new Bit2(add2.Low.High, add2.Low.Low), new Bit2(add1.Low.High, add1.Low.Low)); var nibble = new Byte(high, low); return(nibble); }
public void VisitBranch(TrieNode node, TrieVisitContext trieVisitContext) { AddProofItem(node, trieVisitContext); _nodeToVisitFilter.Remove(node.Keccak); if (trieVisitContext.IsStorage) { HashSet <int> bumpedIndexes = new HashSet <int>(); foreach (int storageIndex in _storageNodeInfos[node.Keccak].StorageIndices) { Nibble childIndex = _fullStoragePaths[storageIndex][_pathTraversalIndex]; Keccak childHash = node.GetChildHash((byte)childIndex); if (childHash == null) { Console.WriteLine($"Empty at {storageIndex}"); AddEmpty(node, trieVisitContext); } else { if (!_storageNodeInfos.ContainsKey(childHash)) { _storageNodeInfos[childHash] = new StorageNodeInfo(); } if (!bumpedIndexes.Contains((byte)childIndex)) { bumpedIndexes.Add((byte)childIndex); _storageNodeInfos[childHash].PathIndex = _pathTraversalIndex + 1; } _storageNodeInfos[childHash].StorageIndices.Add(storageIndex); _nodeToVisitFilter.Add(childHash); } } } else { _nodeToVisitFilter.Add(node.GetChildHash((byte)_fullAccountPath[_pathTraversalIndex])); } _pathTraversalIndex++; }
public static byte[] ConvertPattern(Pattern pattern) { byte[] bytes = new byte[25]; MemoryStream stream = new MemoryStream(bytes); stream.WriteByte(Nibble.Combine((byte)Math.Min(15, pattern.miniCycles.Length), pattern.miniCycleDuration)); stream.WriteByte(Nibble.Combine(pattern.startIntensity, pattern.cycleCount)); MiniCycle[] miniCycles = pattern.miniCycles; // code will ignore more than 15 mini cycles for (int i = 0; i < Math.Min(14, miniCycles.Length) / 2; i += 2) { MiniCycle mc1 = miniCycles[i]; MiniCycle mc2 = miniCycles[i + 1]; stream.WriteByte(Nibble.Combine(mc1.intensity, mc2.intensity)); stream.WriteByte(mc1.durationMultiplier); stream.WriteByte(mc2.durationMultiplier); } if (miniCycles.Length > 14) { stream.WriteByte((byte)(miniCycles[14].intensity >> 4)); stream.WriteByte(miniCycles[14].durationMultiplier); } return(stream.ToArray()); }
public void Store_different_values_at_different_addresses3() { // Arrange var ram = new RandomAccessMemory4(); var byte2A = new Byte2(42); var byte2B = new Byte2(3); var byte2C = new Byte2(999); var addressA = new Nibble(2); var addressB = new Nibble(7); // Act ram.Do(addressA, false, byte2A, false); ram.Do(addressA, true, byte2A, false); ram.Do(addressA, true, byte2A, true); ram.Do(addressB, true, byte2B, false); ram.Do(addressB, true, byte2B, true); var output = ram.Do(addressB, false, byte2C, false); // Assert output.ToInt16().Should().Be(3); }
// keyRemainder는 Empty일 수 있다. // key는 Empty일 수 없다. // stack은 0보다 크다 protected TrieNode InsertNode(TrieKey key, byte[] value, TrieKey keyRemainder, Stack <TrieNode> stack) { Guard.Assert(!key.Empty); Guard.Assert(stack.Count > 0); // 스택의 최종 노드 TrieNode node = stack.Pop(); // 최종 노드가 브랜치 노드인 경우 if (node.Type == NodeType.FullNode) { stack.Push(node); // 브랜치 노드의 자식 노드로 새로운 리프 노드 추가 // keyRemainder is not empty always stack.Push(new TrieNode(this, keyRemainder.Skip(1), value)); } else { TrieKey nodeKey = node.Key; TrieNode fullNode = new TrieNode(this); int matchingLength = keyRemainder.Compare(nodeKey); if (matchingLength > 0) { // 공유키로 익스텐션 노드 생성 TrieKey sharedKey = new TrieKey(keyRemainder.Take(matchingLength).Path, false); stack.Push(new TrieNode(this, sharedKey, fullNode)); nodeKey = nodeKey.Skip(matchingLength); keyRemainder = keyRemainder.Skip(matchingLength); } // 스택에 브랜치 노드 추가 stack.Push(fullNode); // 기존 노드 if (!nodeKey.Empty) { Nibble branchKey = nodeKey.PopFront(); if (nodeKey.Empty && node.Type == NodeType.ShortNode) { // replace extension node to branch node var child = node.Next; fullNode.SetChild(branchKey, child.EncodeRLP()); } else { node.Key = nodeKey; fullNode.SetChild(branchKey, node.EncodeRLP()); } } else { Guard.Assert(node.Type == NodeType.ValueNode); // 브랜치 노드에 값 설정 fullNode.Value = node.Value; } // 스택에 새로운 리프 노드를 추가한다. // 만약, 잔여 키가 비어있으면 브랜치 노드에 값 설정한다. if (keyRemainder.Empty) { fullNode.Value = value; } else { stack.Push(new TrieNode(this, keyRemainder.Skip(1), value)); } } return(SaveStack(key, stack)); }
// 루트 부터 key에 해당하는 경로를 탐색하여 // 일치하는 노드, 잔여 경로, 노드 스택(경로에 해당하는) 을 구한다. protected (TrieNode found, TrieKey keyRemainder, Stack <TrieNode> stack) FindNode(TrieNode root, TrieKey key) { if (ReferenceEquals(root, null)) { throw new ArgumentNullException(nameof(root)); } if (ReferenceEquals(key, null) || key.Empty) { throw new ArgumentNullException(nameof(key)); } // 노드 경로 스택 Stack <TrieNode> stack = new Stack <TrieNode>(); // 노드와 검색 경로 TrieNode node = root; TrieKey keyRemainder = key.Clone(); while (node != null && node.Type != NodeType.EmptyNode) { // 노드 스택에 노드 추가 stack.Push(node); // 현재 노드가 브랜치 노드이면 if (node.Type == NodeType.FullNode) { // 브랜치 노드에서 경로가 종료되면 탐색 종료 if (keyRemainder.Empty) { return(node, TrieKey.EmptyKey, stack); } // 경로에 해당하는 자식 노드가 없으면 탐색 종료 Nibble radix = keyRemainder[0]; TrieNode child = node.GetChild(radix); if (child == null) { return(null, keyRemainder, stack); } // 자식 노드로 탐색 계속 진행 node = child; keyRemainder.PopFront(); continue; } // 현재 노드가 익스텐션 노드이면 if (node.Type == NodeType.ShortNode) { // 노드 키 ( 항상 키가 존재해야 한다 ) TrieKey k = node.Key; Guard.Assert(!k.Empty); // 익스텐션 키가 일치하지 않으면 탐색 종료 int matchingLength = keyRemainder.Compare(k); if (matchingLength != k.Length) { return(null, keyRemainder, stack); } // 익스텐션 노드의 자식 노드로 계속 탐색 진행 //keyRemainder.PopFront(k.Length); keyRemainder = keyRemainder.Skip(k.Length); node = node.Next; continue; } // 리프 노드 return(keyRemainder == node.Key ? (node, TrieKey.EmptyKey, stack) : (null, keyRemainder, stack)); } throw new Exception("wtf!"); }
public Word(byte word) { HighNibble = new Nibble(word, false); LowNibble = new Nibble(word); }
public Word(Nibble highNibble, Nibble lowNibble) { HighNibble = highNibble; LowNibble = lowNibble; }
/// <summary> /// Combine this <see cref="Nibble">nibble</see> <see cref="System.Byte">value</see> as the high-order nibble /// with the provided low-order <see cref="Nibble">nibble</see> <see cref="System.Byte">value</see>. /// </summary> /// <param name="nibble"></param> /// <returns></returns> public byte Append(Nibble nibble) { return(bval.AddComp3(nibble.Value)); }