public void MyHashtable_Add2_Remove1_succeeds() { var hashtbl = new MyHashtable <string, Person>(10); var p = new Person() { Name = "Louise", City = "Dublin" }; var p2 = new Person() { Name = "Mary", City = "Dublin" }; hashtbl.Add(p.Name, p); hashtbl.Add(p2.Name, p2); hashtbl.Remove(p.Name); Assert.AreEqual(hashtbl.Count(), 1); }
public MyHashtable generate_unsat_core() { if (empty == null) { fatal("Not UNSAT, Cannot Generate Core"); } MyHashtable hash = new MyHashtable(); foreach (int uid in empty.reasons) { hash.Add(uid, null); } long oldpos = storage.Position; storage.Seek(0, SeekOrigin.End); while (storage.Position > 0) { ResolveNode nd = ResolveNode.DeSerializeBackward(storage); sharp_assert(!is_node(nd.uid)); if (hash.Contains(nd.uid)) { foreach (int id in nd.reasons) { int uid = id; if (is_node(id)) { uid = node_uid(id); } if (!hash.Contains(uid)) { hash.Add(uid, null); } } hash.Remove(nd.uid); } } storage.Seek(oldpos, SeekOrigin.Begin); return(hash); }
public void remove(int n, NodeType op, int i1, int i2) { sharp_assert(op == NodeType.AND || op == NodeType.XOR); sharp_assert(i1 < i2); sharp_assert(!((op == NodeType.XOR) && (IS_NEGATED(i1) || IS_NEGATED(i2)))); sharp_assert(!IS_NEGATED(n)); //put special mark on the XOR node int l, r; l = i1; r = i2; if (op == NodeType.XOR) { l += XOR_MARK; } NodeHashMapKey key = new NodeHashMapKey(l, r); // ulong key = ((ulong)l << 32) + (ulong) r; sharp_assert((int)hash_table[key] == n); hash_table.Remove(key); }
// gretay -- change start public int gen_interpolant_from_signals_ex(int a_node, int a_cls_id, int b_node, int b_cls_id, int[] c_cls_id, int[] c_interp) { //solver.dump_file = new StreamWriter ("dump_file"); //solver.dump_file.WriteLine ("{0} = INIT_VARS", solver.num_variables()); int a_flag = solver.alloc_flag(); int b_flag = solver.alloc_flag(); solver.mark_transitive_fanins(a_node, a_flag); solver.mark_transitive_fanins(b_node, b_flag); assert(c_cls_id.Length == c_interp.Length); MyHashtable uid2lits = new MyHashtable(); MyHashtable uid2sig = new MyHashtable(); MyHashtable involved = find_all_involved(); prepare_original_nodes(a_flag, b_flag, uid2lits, uid2sig, involved); // init A info int a_uid = solver.clause(a_cls_id).uid; if (involved.Contains(a_uid)) { uid2lits[a_uid] = solver.clause(a_cls_id).literals; int s = solver.zero(); foreach (int lit in solver.clause(a_cls_id).literals) { sharp_assert(solver.node(lit).flag(a_flag)); if (solver.node(lit).flag(b_flag)) { s = solver.bor(s, lit); } } uid2sig[a_uid] = s; //uid2sig[a_uid] = a_node; } // init B info int b_uid = solver.clause(b_cls_id).uid; if (involved.Contains(b_uid)) { uid2lits[b_uid] = solver.clause(b_cls_id).literals; uid2sig[b_uid] = solver.one(); } // init C info for (int i = 0; i < c_cls_id.Length; i++) { Clause cl = solver.clause(c_cls_id[i]); if (involved.Contains(cl.uid)) { uid2lits[cl.uid] = cl.literals; uid2sig[cl.uid] = c_interp[i]; } } long oldpos = storage.Position; storage.Seek(0, SeekOrigin.Begin); while (storage.Position < storage.Length) { ResolveNode nd = ResolveNode.DeSerializeForward(storage); if (!involved.Contains(nd.uid)) { continue; } int [] lits; int signal; int uid = nd.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); lits = (int[])uid2lits[uid]; signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < nd.reasons.Length; ++i) { uid = nd.reasons[i]; sharp_assert(uid < (1 << 29)); sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if ((solver.variable(pivot).flag(a_flag)) && (!solver.variable(pivot).flag(b_flag))) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } if (!uid2lits.Contains(nd.uid)) { uid2lits[nd.uid] = lits; } sharp_assert(!uid2sig.Contains(nd.uid)); uid2sig[nd.uid] = signal; } storage.Seek(oldpos, SeekOrigin.Begin); { int uid = empty.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < empty.reasons.Length; ++i) { uid = empty.reasons[i]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if ((solver.variable(pivot).flag(a_flag)) && (!solver.variable(pivot).flag(b_flag))) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } sharp_assert(lits.Length == 0); sharp_assert(involved.Count == 0); sharp_assert(uid2lits.Count == 0); sharp_assert(uid2sig.Count == 0); //solver.dump_file.WriteLine ("{0} = CONSTRAINT", signal); //solver.dump_file.Close(); solver.free_flag(a_flag); solver.free_flag(b_flag); //solver.free_flag(c_flag); return(signal); } }
public int gen_interpolant_from_clauses(int a_gid, int b_gid) { //solver.dump_file = new StreamWriter ("dump_file"); //solver.dump_file.WriteLine ("{0} = INIT_VARS", solver.num_variables()); sharp_assert(solver.is_pure_clause_based()); solver.convert_vars_to_pi(); MyHashtable uid2lits = new MyHashtable(); MyHashtable uid2sig = new MyHashtable(); MyHashtable involved = find_all_involved(); int [] var_flag = new int [solver.variables.size()]; prepare_original_clauses(a_gid, b_gid, uid2lits, uid2sig, involved, var_flag); long oldpos = storage.Position; storage.Seek(0, SeekOrigin.Begin); while (storage.Position < storage.Length) { ResolveNode nd = ResolveNode.DeSerializeForward(storage); if (!involved.Contains(nd.uid)) { continue; } int uid = nd.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < nd.reasons.Length; ++i) { uid = nd.reasons[i]; sharp_assert(uid < (1 << 29)); sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if (var_flag[pivot] == A_LOCAL) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } if (!uid2lits.Contains(nd.uid)) { uid2lits[nd.uid] = lits; } sharp_assert(!uid2sig.Contains(nd.uid)); uid2sig[nd.uid] = signal; } storage.Seek(oldpos, SeekOrigin.Begin); { int uid = empty.reasons[0]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits = (int[])uid2lits[uid]; int signal = (int)uid2sig[uid]; int count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } for (int i = 1; i < empty.reasons.Length; ++i) { uid = empty.reasons[i]; sharp_assert(involved.Contains(uid)); sharp_assert(uid2lits.Contains(uid)); sharp_assert(uid2sig.Contains(uid)); int [] lits1 = (int[])uid2lits[uid]; int signal1 = (int)uid2sig[uid]; count = (int)involved[uid] - 1; if (count == 0) { uid2lits.Remove(uid); uid2sig.Remove(uid); involved.Remove(uid); } else { involved[uid] = count; } int pivot = find_pivot(lits, lits1); lits = resolve(lits, lits1); if (var_flag[pivot] == A_LOCAL) { signal = solver.bor(signal, signal1); } else { signal = solver.band(signal, signal1); } } sharp_assert(lits.Length == 0); sharp_assert(involved.Count == 0); sharp_assert(uid2lits.Count == 0); sharp_assert(uid2sig.Count == 0); //solver.dump_file.WriteLine ("{0} = CONSTRAINT", signal); //solver.dump_file.Close(); return(signal); } }