public void DDecode(char[] array) { var ilen = 3 + ((array[0] + array[1])/16); var elen = 3 + ((array[ilen] + array[ilen + 1])/16); var icode = new char[ilen]; var ecode = new char[elen]; Array.Copy(array, 0, icode, 0, ilen); Array.Copy(array, ilen, ecode, 0, elen); var bi = new BitArray(icode); var be = new BitArray(ecode); Id.Decode(bi); Event.Decode(be); }
public void Decode(BitArray bt) { Event.Decode(bt); }
public char[] EncodeCharArray() { var bt = new BitArray(); bt = Id.Encode(bt); bt = Event.Encode(bt); return bt.Bits; }
private void DecodeCheck4(BitArray bt) { var valCheck4 = bt.ReadBits(1); if (valCheck4 == 0) { SetAsNode(DecN(bt), 0, null, bt); return; } if (valCheck4 == 1) { SetAsNode(DecN(bt), null, 0, bt); return; } throw new EventOperationException("Decode Failed (Check4)", this, null); }
public void Decode(char[] bits) { var bt = new BitArray(); bt.SetBits(bits); Id.Decode(bt); Event.Decode(bt); }
public void SetAsNode(int value, int? leftValue, int? rightValue, BitArray bt) { Value = value; if (leftValue.HasValue) { Left = new Event(leftValue.Value); } else { Left = new Event(); Left.Decode(bt); } if (rightValue.HasValue) { Right = new Event(rightValue.Value); } else { Right = new Event(); Right.Decode(bt); } }
private void DecodeCheck2(BitArray bt) { var valCheck2 = bt.ReadBits(2); if (valCheck2 == 0) { Value = 0; Left = new Event(0); Right = new Event(); Right.Decode(bt); return; } if (valCheck2 == 1) { SetAsNode(0, null, 0, bt); return; } if (valCheck2 == 2) { SetAsNode(0, null, null, bt); return; } if (valCheck2 == 3) { DecodeCheck3(bt); return; } throw new EventOperationException("Decode Failed (Check2)", this, null); }
public void EncN(BitArray bt, int val, int nb) { if (val < (1 << nb)) { bt.AddBits(0, 1); bt.AddBits(val, nb); } else { bt.AddBits(1, 1); EncN(bt, val - (1 << nb), nb + 1); } }
public BitArray Encode(BitArray bt) { if (bt == null) { bt = new BitArray(); } if (IsLeaf) { bt.AddBits(1, 1); EncN(bt, Value, 2); return bt; } if ((!IsLeaf && Value == 0) && (Left.IsLeaf && Left.Value == 0) && (!Right.IsLeaf || Right.Value != 0)) { bt.AddBits(0, 1); bt.AddBits(0, 2); Right.Encode(bt); return bt; } if ((!IsLeaf && Value == 0) && (!Left.IsLeaf || Left.Value != 0) && (Right.IsLeaf && Right.Value == 0)) { bt.AddBits(0, 1); bt.AddBits(1, 2); Left.Encode(bt); return bt; } if ((!IsLeaf && Value == 0) && (!Left.IsLeaf || Left.Value != 0) && (!Right.IsLeaf || Right.Value != 0)) { bt.AddBits(0, 1); bt.AddBits(2, 2); Left.Encode(bt); Right.Encode(bt); return bt; } if ((!IsLeaf && Value != 0) && (Left.IsLeaf && Left.Value == 0) && (!Right.IsLeaf || Right.Value != 0)) { bt.AddBits(0, 1); bt.AddBits(3, 2); bt.AddBits(0, 1); bt.AddBits(0, 1); EncN(bt, Value, 2); Right.Encode(bt); return bt; } if ((!IsLeaf && Value != 0) && (!IsLeaf || Left.Value != 0) && (Right.IsLeaf && Right.Value == 0)) { bt.AddBits(0, 1); bt.AddBits(3, 2); bt.AddBits(0, 1); bt.AddBits(1, 1); EncN(bt, Value, 2); Left.Encode(bt); return bt; } if ((!IsLeaf && Value != 0) && (!Left.IsLeaf || Left.Value != 0) && (!Right.IsLeaf || Right.Value != 0)) { bt.AddBits(0, 1); bt.AddBits(3, 2); bt.AddBits(1, 1); EncN(bt, Value, 2); Left.Encode(bt); Right.Encode(bt); return bt; } throw new EventOperationException( string.Format( "Encoding failed with IsLeaf:{0} & Value:{1}{2}", IsLeaf, Value, IsLeaf ? "" : string.Format( " Left: IsLeaf:{0} & Value:{1} Right: IsLeaf:{2} & Value:{3}", Left.IsLeaf, Left.Value, Right.IsLeaf, Right.Value)), this, null); }
public void Decode(BitArray bt) { var valCheck1 = bt.ReadBits(1); if (valCheck1 == 1) { SetAsLeaf(DecN(bt)); return; } if (valCheck1 == 0) { DecodeCheck2(bt); return; } throw new EventOperationException("Decode Failed", this, null); }
public char DecN(BitArray bt) { var n = 0; var b = 2; while (bt.ReadBits(1) == 1) { n += (1 << b); b++; } var n2 = bt.ReadBits(b); n += n2; return (char)n; }
public void SetAsNode(int? value, int? leftValue, int? rightValue, BitArray bt) { if (value.HasValue) { Value = value.Value; } else { Value = -1; } if (leftValue.HasValue) { Left = new Id(leftValue.Value); } else { Left = new Id(); Left.Decode(bt); } if (rightValue.HasValue) { Right = new Id(rightValue.Value); } else { Right = new Id(); Right.Decode(bt); } }
public BitArray Encode(BitArray bt) { if (bt == null) { bt = new BitArray(); } if (IsLeaf && Value == 0) { bt.AddBits(0, 3); return bt; } if (IsLeaf && Value == 1) { bt.AddBits(0, 2); bt.AddBits(1, 1); return bt; } if (!IsLeaf && (Left.IsLeaf && Left.Value == 0) && (!Right.IsLeaf || Right.Value == 1)) { bt.AddBits(1, 2); Right.Encode(bt); return bt; } if (!IsLeaf && (Right.IsLeaf && Right.Value == 0) && (!Left.IsLeaf || Left.Value == 1)) { bt.AddBits(2, 2); Left.Encode(bt); return bt; } if (!IsLeaf && (!Right.IsLeaf || Right.Value == 1) && (!Left.IsLeaf || Left.Value == 1)) { //System.out.println("id enc d"); bt.AddBits(3, 2); Left.Encode(bt); Right.Encode(bt); return bt; } throw new IdOperationException("Encode Failed", this, null); }
// code and decode dos ids public void Decode(BitArray bt) { var val = bt.ReadBits(2); if (val == 0) { SetAsLeaf(bt.ReadBits(1)); return; } if (val == 1) { SetAsNode(null, 0, null, bt); return; } if (val == 2) { SetAsNode(null, null, 0, bt); return; } if (val == 3) { SetAsNode(null, null, null, bt); return; } throw new IdOperationException("Decode Failed", this, null); }