git.iko.soy/ikoHSE/SolveAvdoshin
on master help sign in
sped up BlockCount a little
commit139acc7d87b2ce1f7a7791f9b986bae47f414451 authorIlya Gulkov <isgulkov@edu.hse.ru> dateSun 11 Oct 2015, 21:57 (11 years ago) parent52ae294
1 file changed+18−17
SolveAvdoshin/BooleanFunctions.cs+18−17
SolveAvdoshin/BooleanFunctions.cs+18−17
@@ -385,7 +385,7 @@ namespace SolveAvdoshin
385385 return (byte)res;
386386 }
387387
388− public override HashSet<string> GetSetOfAllBlockStrings()
388+ public override IEnumerable<string> GetSetOfAllBlockStrings()
389389 {
390390 throw new NotImplementedException();
391391 }
@@ -875,13 +875,17 @@ namespace SolveAvdoshin
875875 return ToString() == obj.ToString();
876876 }
877877
878− public abstract HashSet<string> GetSetOfAllBlockStrings();
878+ public abstract IEnumerable<string> GetSetOfAllBlockStrings();
879879
880880 public int CountBlocks()
881881 {
882− var allBlocks = GetSetOfAllBlockStrings();
882+ var allBlocks = new HashSet<string>();
883+
884+ foreach(string s in GetSetOfAllBlockStrings()) {
885+ allBlocks.Add(s);
886+ }
883887
884− return allBlocks != null ? allBlocks.Count : 0;
888+ return allBlocks.Count;
885889 }
886890
887891 public IEnumerable<BooleanExpression> CombineWith(BooleanExpression anotherExpression,
@@ -967,20 +971,17 @@ namespace SolveAvdoshin
967971 return Left.CountOps() + Right.CountOps() + 1;
968972 }
969973
970− public override HashSet<string> GetSetOfAllBlockStrings()
974+ public override IEnumerable<string> GetSetOfAllBlockStrings()
971975 {
972− var allBlocks = new HashSet<string>();
973− allBlocks.Add(ToString());
976+ yield return ToString();
974977
975− var leftBlocks = Left.GetSetOfAllBlockStrings();
976− if(leftBlocks != null)
977− allBlocks.UnionWith(leftBlocks);
978−
979− var rightBlocks = Right.GetSetOfAllBlockStrings();
980− if(rightBlocks != null)
981− allBlocks.UnionWith(rightBlocks);
978+ foreach(string s in Left.GetSetOfAllBlockStrings()) {
979+ yield return s;
980+ }
982981
983− return allBlocks;
982+ foreach(string s in Right.GetSetOfAllBlockStrings()) {
983+ yield return s;
984+ }
984985 }
985986
986987 public override byte Eval()
@@ -1087,9 +1088,9 @@ namespace SolveAvdoshin
10871088 return 0;
10881089 }
10891090
1090− public override HashSet<string> GetSetOfAllBlockStrings()
1091+ public override IEnumerable<string> GetSetOfAllBlockStrings()
10911092 {
1092− return null;
1093+ yield break;
10931094 }
10941095
10951096 public override byte Eval()