public static DataStreamValue operator ^(DataStreamValue t1, DataStreamValue t2) { var result = new DataStreamValue(); var table1 = CreateTableByStream(t1.Stream); var table2 = CreateTableByStream(t2.Stream); var varNames = table1.Keys.Union(table2.Keys); var table3 = new Dictionary <string, SemilatticeValue>(); foreach (var varName in varNames) { var semilatticeValue = new SemilatticeValue(SemilatticeValueEnum.UNDEF); var isFirstVar = table1.Keys.Contains(varName); var isSecondVar = table2.Keys.Contains(varName); if (isFirstVar && !isSecondVar) { semilatticeValue = table1[varName] ^ semilatticeValue; } else if (!isFirstVar && isSecondVar) { semilatticeValue = semilatticeValue ^ table2[varName]; } else if (isFirstVar && isSecondVar) { semilatticeValue = table1[varName] ^ table2[varName]; } table3.Add(varName, semilatticeValue); } result.Stream = CreateStreamByTable(table3); return(result); }
public void ChangeStreamValue(string varName, SemilatticeValue value) { var table = CreateTableByStream(Stream); if (table.Keys.Contains(varName)) { table[varName] = value; Stream = CreateStreamByTable(table); } else { Stream.Add(new SemilatticeStreamValue(varName, value)); } }
static public void TestForValueOperator() { var undef = new SemilatticeValue(""); Debug.Assert(undef.TypeValue == SemilatticeValueEnum.UNDEF && undef.ConstValue == null); var c1 = new SemilatticeValue("123"); Debug.Assert(c1.TypeValue == SemilatticeValueEnum.CONST && c1.ConstValue == "123"); var c2 = new SemilatticeValue("456.45"); Debug.Assert(c2.TypeValue == SemilatticeValueEnum.CONST && c2.ConstValue == "456.45"); var c3 = new SemilatticeValue("-123"); Debug.Assert(c3.TypeValue == SemilatticeValueEnum.CONST && c3.ConstValue == "-123"); var c4 = new SemilatticeValue("123"); Debug.Assert(c4.TypeValue == SemilatticeValueEnum.CONST && c4.ConstValue == "123"); var nac = new SemilatticeValue("fun()"); Debug.Assert(nac.TypeValue == SemilatticeValueEnum.NAC && nac.ConstValue == null); var t = c1 ^ undef; Debug.Assert(t.TypeValue == SemilatticeValueEnum.CONST && t.ConstValue == "123"); t = undef ^ c1; Debug.Assert(t.TypeValue == SemilatticeValueEnum.CONST && t.ConstValue == "123"); t = undef ^ nac; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); t = nac ^ undef; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); t = nac ^ nac; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); t = undef ^ undef; Debug.Assert(t.TypeValue == SemilatticeValueEnum.UNDEF && t.ConstValue == null); t = c1 ^ c2; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); t = c1 ^ c4; Debug.Assert(t.TypeValue == SemilatticeValueEnum.CONST && t.ConstValue == "123"); t = c1 ^ nac; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); t = nac ^ c2; Debug.Assert(t.TypeValue == SemilatticeValueEnum.NAC && t.ConstValue == null); }
public SemilatticeStreamValue(string varName, SemilatticeValue value) { VarName = varName; Value = value; }