/***************************** Constructor *********************************/
 public DataSet()
 {
     egoLikedTweets = new HashSet<long>();
     egoLikedTweetsInTimeline = new HashSet<long>();
     egoUnLikedTweetsInTimeline = new HashSet<long>();
     timeline = new SortedSet<long>(new TweetIDComparer());
     egoLikedTweets.Clear();
     egoLikedTweetsInTimeline.Clear();
     egoUnLikedTweetsInTimeline.Clear();
     timeline.Clear();
 }
        private static void RunTest(SortedDictionary<int, User> sortedDict, SortedSet<User> sortedSet, IEnumerable<int> testSizes,
            string label,
            Func<SortedDictionary<int, User>, int, TimeSpan> testFuncSoretdDict, Func<SortedSet<User>, int, TimeSpan> testFuncSortedSet)
        {
            foreach (int test in testSizes)
            {
                var result = testFuncSoretdDict(sortedDict, test);
                Console.WriteLine("{0} with Sorted Dictionary ({1}): {2}", label, test, result);

                result = testFuncSortedSet(sortedSet, test);
                Console.WriteLine("{0} with Sorted Set ({1}): {2}", label, test, result);

                sortedDict.Clear();
                sortedSet.Clear();
                Console.WriteLine();
            }
        }
Beispiel #3
0
		public void Clear ()
		{
			var set = new SortedSet<int> { 2, 3, 4, 5 };
			Assert.AreEqual (4, set.Count);
			set.Clear ();
			Assert.AreEqual (0, set.Count);
		}
Beispiel #4
0
    public override Outcome CheckOutcomeCore(ErrorHandler handler, int taskID = -1)
    {  
      Contract.EnsuresOnThrow<UnexpectedProverOutputException>(true);
      
      var result = Outcome.Undetermined;

      if (Process == null)
        return result;

      try {
        currentErrorHandler = handler;
        FlushProverWarnings();

        int errorLimit;
        if (CommandLineOptions.Clo.ConcurrentHoudini) {
          Contract.Assert(taskID >= 0);
          errorLimit = CommandLineOptions.Clo.Cho[taskID].ProverCCLimit;
        } else {
          errorLimit = CommandLineOptions.Clo.ProverCCLimit;
        }

        if (errorLimit < 1)
          errorLimit = 1;

        int errorsLeft = errorLimit;

        var globalResult = Outcome.Undetermined;

        while (true) {
          string[] labels = null;
          bool popLater = false;

          try {
            errorsLeft--;
            
            result = GetResponse();

            var reporter = handler as VC.VCGen.ErrorReporter;
            // TODO(wuestholz): Is the reporter ever null?
            if (usingUnsatCore && result == Outcome.Valid && reporter != null && 0 < NamedAssumes.Count)
            {
              if (usingUnsatCore)
              {
                UsedNamedAssumes = new HashSet<string>();
                SendThisVC("(get-unsat-core)");
                var resp = Process.GetProverResponse();
                if (resp.Name != "")
                {
                  UsedNamedAssumes.Add(resp.Name);
                  if (CommandLineOptions.Clo.PrintNecessaryAssumes)
                  {
                    reporter.AddNecessaryAssume(resp.Name.Substring("aux$$assume$$".Length));
                  }
                }
                foreach (var arg in resp.Arguments)
                {
                  UsedNamedAssumes.Add(arg.Name);
                  if (CommandLineOptions.Clo.PrintNecessaryAssumes)
                  {
                    reporter.AddNecessaryAssume(arg.Name.Substring("aux$$assume$$".Length));
                  }
                }
              }
              else
              {
                UsedNamedAssumes = null;
              }
            }

            if (CommandLineOptions.Clo.RunDiagnosticsOnTimeout && result == Outcome.TimeOut)
            {
              #region Run timeout diagnostics

              if (CommandLineOptions.Clo.TraceDiagnosticsOnTimeout)
              {
                Console.Out.WriteLine("Starting timeout diagnostics with initial time limit {0}.", options.TimeLimit);
              }

              SendThisVC("; begin timeout diagnostics");

              var start = DateTime.UtcNow;
              var unverified = new SortedSet<int>(ctx.TimeoutDiagnosticIDToAssertion.Keys);
              var timedOut = new SortedSet<int>();
              int frac = 2;
              int queries = 0;
              int timeLimitPerAssertion = 0 < options.TimeLimit ? (options.TimeLimit / 100) * CommandLineOptions.Clo.TimeLimitPerAssertionInPercent : 1000;
              while (true)
              {
                int rem = unverified.Count;
                if (rem == 0)
                {
                  if (0 < timedOut.Count)
                  {
                    result = CheckSplit(timedOut, ref popLater, options.TimeLimit, timeLimitPerAssertion, ref queries);
                    if (result == Outcome.Valid)
                    {
                      timedOut.Clear();
                    }
                    else if (result == Outcome.TimeOut)
                    {
                      // Give up and report which assertions were not verified.
                      var cmds = timedOut.Select(id => ctx.TimeoutDiagnosticIDToAssertion[id]);

                      if (cmds.Any())
                      {
                        handler.OnResourceExceeded("timeout after running diagnostics", cmds);
                      }
                    }
                  }
                  else
                  {
                    result = Outcome.Valid;
                  }
                  break;
                }

                // TODO(wuestholz): Try out different ways for splitting up the work (e.g., randomly).
                var cnt = Math.Max(1, rem / frac);
                // It seems like assertions later in the control flow have smaller indexes.
                var split = new SortedSet<int>(unverified.Where((val, idx) => (rem - idx - 1) < cnt));
                Contract.Assert(0 < split.Count);
                var splitRes = CheckSplit(split, ref popLater, timeLimitPerAssertion, timeLimitPerAssertion, ref queries);
                if (splitRes == Outcome.Valid)
                {
                  unverified.ExceptWith(split);
                  frac = 1;
                }
                else if (splitRes == Outcome.Invalid)
                {
                  result = splitRes;
                  break;
                }
                else if (splitRes == Outcome.TimeOut)
                {
                  if (2 <= frac && (4 <= (rem / frac)))
                  {
                    frac *= 4;
                  }
                  else if (2 <= (rem / frac))
                  {
                    frac *= 2;
                  }
                  else
                  {
                    timedOut.UnionWith(split);
                    unverified.ExceptWith(split);
                    frac = 1;
                  }
                }
                else
                {
                  break;
                }
              }

              unverified.UnionWith(timedOut);

              var end = DateTime.UtcNow;

              SendThisVC("; end timeout diagnostics");

              if (CommandLineOptions.Clo.TraceDiagnosticsOnTimeout)
              {
                Console.Out.WriteLine("Terminated timeout diagnostics after {0:F0} ms and {1} prover queries.", end.Subtract(start).TotalMilliseconds, queries);
                Console.Out.WriteLine("Outcome: {0}", result);
                Console.Out.WriteLine("Unverified assertions: {0} (of {1})", unverified.Count, ctx.TimeoutDiagnosticIDToAssertion.Keys.Count);

                string filename = "unknown";
                var assertion = ctx.TimeoutDiagnosticIDToAssertion.Values.Select(t => t.Item1).FirstOrDefault(a => a.tok != null && a.tok != Token.NoToken && a.tok.filename != null);
                if (assertion != null)
                {
                  filename = assertion.tok.filename;
                }
                File.AppendAllText("timeouts.csv", string.Format(";{0};{1};{2:F0};{3};{4};{5};{6}\n", filename, options.TimeLimit, end.Subtract(start).TotalMilliseconds, queries, result, unverified.Count, ctx.TimeoutDiagnosticIDToAssertion.Keys.Count));
              }

              #endregion
            }

            if (globalResult == Outcome.Undetermined)
              globalResult = result;
            
            if (result == Outcome.Invalid || result == Outcome.TimeOut || result == Outcome.OutOfMemory) {
              IList<string> xlabels;
              if (CommandLineOptions.Clo.UseLabels) {
                labels = GetLabelsInfo();
                if (labels == null)
                {
                  xlabels = new string[] { };
                }
                else
                {
                  xlabels = labels.Select(a => a.Replace("@", "").Replace("+", "")).ToList();
                }
              }
              else if(CommandLineOptions.Clo.SIBoolControlVC) {
                  labels = new string[0];
                  xlabels = labels;
              } else {
                labels = CalculatePath(handler.StartingProcId());
                xlabels = labels;
              }
                Model model = (result == Outcome.TimeOut || result == Outcome.OutOfMemory) ? null :
                    GetErrorModel();
              handler.OnModel(xlabels, model, result);
            }
            
            if (labels == null || !labels.Any() || errorsLeft == 0) break;
          } finally {
            if (popLater)
            {
              SendThisVC("(pop 1)");
            }
          }

          if (CommandLineOptions.Clo.UseLabels) {
            var negLabels = labels.Where(l => l.StartsWith("@")).ToArray();
            var posLabels = labels.Where(l => !l.StartsWith("@"));
            Func<string, string> lbl = (s) => SMTLibNamer.QuoteId(SMTLibNamer.LabelVar(s));
            if (!options.MultiTraces)
              posLabels = Enumerable.Empty<string>();
            var conjuncts = posLabels.Select(s => "(not " + lbl(s) + ")").Concat(negLabels.Select(lbl)).ToArray();
            string expr = conjuncts.Length == 1 ? conjuncts[0] : ("(or " + conjuncts.Concat(" ") + ")"); ;
            if (!conjuncts.Any())
            {
              expr = "false";
            }
            SendThisVC("(assert " + expr + ")");
            SendCheckSat();
          }
          else {
            string source = labels[labels.Length - 2];
            string target = labels[labels.Length - 1];
            SendThisVC("(assert (not (= (ControlFlow 0 " + source + ") (- " + target + "))))");
            SendCheckSat();
          }
        }

        FlushLogFile();

        if (CommandLineOptions.Clo.RestartProverPerVC && Process != null)
          Process.NeedsRestart = true;

        return globalResult;

      } finally {
        currentErrorHandler = null;
      }
    }
        /// <summary>
        /// Handle 'special' Panels
        /// </summary>
        public override void ProcessChildren(TFormWriter writer, TControlDef ctrl)
        {
            SortedSet <int>ButtonWidths = new SortedSet <int>();
            SortedSet <int>ButtonTops = new SortedSet <int>();
            List <TControlDef>Buttons = new List <TControlDef>();

            int NewButtonWidthForAll = -1;

            if (ctrl.controlName == PNL_FILTER_AND_FIND)
            {
                listNumericColumns.Clear();

                writer.Template.SetCodelet("FILTERANDFIND", "true");

                writer.SetControlProperty(ctrl, "Dock", "Left");
                writer.SetControlProperty(ctrl, "BackColor", "System.Drawing.Color.LightSteelBlue");
                writer.SetControlProperty(ctrl, "Width", "0");

                if (!ctrl.HasAttribute("ExpandedWidth"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALWIDTH", "150");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALWIDTH", ctrl.GetAttribute("ExpandedWidth"));
                }

                if ((ctrl.HasAttribute("InitiallyExpanded"))
                    && (ctrl.GetAttribute("InitiallyExpanded").ToLower() != "false"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALLYEXPANDED", "true");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERINITIALLYEXPANDED", "false");
                }

                if (!ctrl.HasAttribute("ShowApplyFilterButton"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERAPPLYFILTERBUTTONCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERAPPLYFILTERBUTTONCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowApplyFilterButton"));
                }

                if (!ctrl.HasAttribute("ShowKeepFilterTurnedOnButton"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWKEEPFILTERTURNEDONBUTTONCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWKEEPFILTERTURNEDONBUTTONCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowKeepFilterTurnedOnButton"));
                }

                if (!ctrl.HasAttribute("ShowFilterIsAlwaysOnLabel"))
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWFILTERISALWAYSONLABELCONTEXT", "TUcoFilterAndFind.FilterContext.None");
                }
                else
                {
                    writer.Template.SetCodelet("FINDANDFILTERSHOWFILTERISALWAYSONLABELCONTEXT", "TUcoFilterAndFind." +
                        ctrl.GetAttribute("ShowFilterIsAlwaysOnLabel"));
                }

                writer.Template.SetCodelet("CUSTOMDISPOSING",
                    "if (FFilterAndFindObject != null && FFilterAndFindObject.FilterFindPanel != null)" + Environment.NewLine +
                    "{" + Environment.NewLine +
                    "    FFilterAndFindObject.FilterFindPanel.Dispose();" + Environment.NewLine +
                    "}");

                XmlNodeList controlAttributesList = null;
                XmlNode ctrlNode = ctrl.xmlNode;

                foreach (XmlNode child in ctrlNode.ChildNodes)
                {
                    if (child.Name == "ControlAttributes")
                    {
                        controlAttributesList = child.ChildNodes;
                    }
                }

                ProcessTemplate snippetFilterAndFindDeclarations = writer.Template.GetSnippet("FILTERANDFINDDECLARATIONS");
                writer.Template.InsertSnippet("FILTERANDFINDDECLARATIONS", snippetFilterAndFindDeclarations);

                ProcessTemplate snippetFilterAndFindMethods = writer.Template.GetSnippet("FILTERANDFINDMETHODS");

                writer.Template.SetCodelet("INDIVIDUALFILTERPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALEXTRAFILTERPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALFINDPANELS", "");
                writer.Template.SetCodelet("INDIVIDUALFILTERFINDPANELEVENTS", "");
                writer.Template.SetCodelet("INDIVIDUALFILTERFINDPANELPROPERTIES", "");
                writer.Template.SetCodelet("NUMERICFILTERFINDCOLUMNS", "");
                writer.Template.SetCodelet("FILTERBUTTON", "");

                if (ctrl.HasAttribute("FilterButton"))
                {
                    // This specifies the button text (optional) and status bar text separated by semi-colon
                    // eg FilterButton=F&ilter;Click to Toggle the Analysis Values filter on and off
                    string attVal = ctrl.GetAttribute("FilterButton");
                    int pos = attVal.IndexOf(';');

                    if ((pos >= 0) && (pos < attVal.Length - 1))
                    {
                        string codelet = String.Empty;

                        if (pos > 0)
                        {
                            codelet = String.Format("chkToggleFilter.Text = \"{0}\";{1}", attVal.Substring(0, pos), Environment.NewLine);
                        }

                        codelet += String.Format("FPetraUtilsObject.SetStatusBarText(chkToggleFilter, \"{0}\");", attVal.Substring(pos + 1));
                        writer.Template.SetCodelet("FILTERBUTTON", codelet);
                    }
                }

                // Process each of the three Filter/Find definitions
                int TotalPanels = ProcessIndividualFilterFindPanel(writer,
                    "FilterControls",
                    "Filter",
                    "StandardFilter",
                    controlAttributesList,
                    "INDIVIDUALFILTERPANELS");
                TotalPanels += ProcessIndividualFilterFindPanel(writer,
                    "ExtraFilterControls",
                    "Filter",
                    "ExtraFilter",
                    controlAttributesList,
                    "INDIVIDUALEXTRAFILTERPANELS");
                TotalPanels += ProcessIndividualFilterFindPanel(writer, "FindControls", "Find", "Find", controlAttributesList, "INDIVIDUALFINDPANELS");

                if (TotalPanels == 0)
                {
                    throw new Exception("Found no controls for the Filter/Find panel");
                }

                // Manual code methods
                if (FCodeStorage.ManualFileExistsAndContains("void CreateFilterFindPanelsManual()"))
                {
                    writer.Template.SetCodelet("CREATEFILTERFINDPANELSMANUAL", "CreateFilterFindPanelsManual();" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("CREATEFILTERFINDPANELSMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("void FilterToggledManual(bool"))
                {
                    writer.Template.SetCodelet("FILTERTOGGLEDMANUAL", "FilterToggledManual(pnlFilterAndFind.Width == 0);" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("FILTERTOGGLEDMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("void ApplyFilterManual(ref"))
                {
                    writer.Template.SetCodelet("APPLYFILTERMANUAL", "ApplyFilterManual(ref AFilterString);" + Environment.NewLine);
                }
                else
                {
                    writer.Template.SetCodelet("APPLYFILTERMANUAL", "");
                }

                if (FCodeStorage.ManualFileExistsAndContains("bool IsMatchingRowManual("))
                {
                    writer.Template.SetCodelet("ISMATCHINGROW", "IsMatchingRowManual");
                }
                else
                {
                    writer.Template.SetCodelet("ISMATCHINGROW", "FFilterAndFindObject.FindPanelControls.IsMatchingRow");
                }

                // Write the whole thing out
                writer.Template.InsertSnippet("FILTERANDFINDMETHODS", snippetFilterAndFindMethods);
            }
            else
            {
                TControlDef subChildCtrl;

                TLogging.LogAtLevel(1, "PanelGenerator:Processing Children '" + ctrl.controlName + "' (about to call base method)");

                base.ProcessChildren(writer, ctrl);

                foreach (TControlDef childCtrl in ctrl.Children)
                {
                    TLogging.LogAtLevel(1, "Child Name: " + childCtrl.controlName);

                    if ((childCtrl.HasAttribute("AutoButtonMaxWidths"))
                        || (childCtrl.GetAttribute("AutoButtonMaxWidths") == "true"))
                    {
                        TLogging.LogAtLevel(1, "Control '" + childCtrl.controlName + "' has AutoButtonMaxWidths = true!");


                        XmlNode controlsNode = TXMLParser.GetChild(childCtrl.xmlNode, "Controls");

                        if ((controlsNode != null) && TYml2Xml.GetChildren(controlsNode, true)[0].Name.StartsWith("Row"))
                        {
                            TLogging.LogAtLevel(1, "Row processing");

                            // this defines the layout with several rows with several controls per row
                            foreach (XmlNode row in TYml2Xml.GetChildren(controlsNode, true))
                            {
                                StringCollection controls = TYml2Xml.GetElements(row);

                                foreach (string ctrlname in controls)
                                {
                                    subChildCtrl = writer.CodeStorage.GetControl(ctrlname);

                                    TLogging.LogAtLevel(1, "Child: '" + subChildCtrl.controlName + "'");

                                    ProcessButtonsForMaxWidthDetermination(writer, subChildCtrl, ButtonWidths, ButtonTops, Buttons);
                                }

                                ProcessButtonsForMaxWidthSizing(writer, childCtrl, ButtonWidths, ButtonTops, Buttons, out NewButtonWidthForAll);
                            }
                        }
                        else
                        {
                            if ((controlsNode != null) && (childCtrl.Children.Count != 0))
                            {
                                TLogging.LogAtLevel(1, "Controls processing");

                                foreach (TControlDef subChildCtrl2 in childCtrl.Children)
                                {
                                    TLogging.LogAtLevel(1, "Child: '" + subChildCtrl2.controlName + "'");

                                    ProcessButtonsForMaxWidthDetermination(writer, subChildCtrl2, ButtonWidths, ButtonTops, Buttons);
                                }

                                ProcessButtonsForMaxWidthSizing(writer, childCtrl, ButtonWidths, ButtonTops, Buttons, out NewButtonWidthForAll);
                            }
                        }

                        if ((Buttons.Count > 0)
                            && ((childCtrl.HasAttribute("AutoButtonMaxWidthsAutoSizesContainerWidth"))
                                && ((childCtrl.GetAttribute("AutoButtonMaxWidthsAutoSizesContainerWidth").ToLower() == "true"))))
                        {
                            int NewContainerWidth = 5 + 7 + (Buttons.Count * NewButtonWidthForAll) + ((Buttons.Count - 1) * 5); // + ((Buttons.Count - 1) * 12) - (Buttons.Count * 2);
                            TLogging.LogAtLevel(1, "NewContainerWidth: " + NewContainerWidth.ToString());
                            writer.SetControlProperty(childCtrl, "Size", "new System.Drawing.Size(" +
                                NewContainerWidth.ToString() + ", " + childCtrl.GetAttribute("Height").ToString() + ")");
                        }

                        Buttons.Clear();
                        ButtonWidths.Clear();
                    }
                }
            }
        }
        /// <summary>
        ///  test adds several items to the collection, and then enumerates the collection in sorted order. The test is repeated 50 times to get a more consistent result
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="numItemsToTest"></param>
        /// <returns></returns>
        static TimeSpan RunTestTwoSortedSet(SortedSet<User> collection, int numItemsToTest)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            // perform the test 50 times:
            for (int counter = 0; counter < 50; counter++)
            {
                collection.Clear();

                // add random items
                Random rnd = new Random();

                var sequence = from n in Enumerable.Range(1, numItemsToTest)
                               select rnd.Next() * n;

                foreach (var item in sequence)
                    collection.Add(new User(item, "family", "name"));

                // enumerate 1000 times
                double sum = 0;
                for (int inner = 0; inner < 1000; inner++)
                {
                    //  I am performing the sort each time through the loop on purpose, even though it does take more time.
                    // I want to measure the cost of the sort because in most applications where order matters, you would need
                    // to enumerate the set in different locations in the code, or after items have been added or removed.
                    // That requires a sort.
                    //  IEnumerable ordered = collection as IEnumerable;
                    //SortedDictionary<int, User>.ValueCollection values = collection.Values;
                    //var max = collection.Values.Max();
                    IEnumerable ordered = collection as IEnumerable;

                    // var sum = collection.Values.Sum();
                    // must enumerate to make it work:
                    // sum += ordered.Sum();
                    ordered.GetEnumerator();
                }
            }

            timer.Stop();
            return timer.Elapsed;
        }
        /// <summary>
        /// adds several items to a collection, then searches for items in that collection. The test is repeated 50 times to get a more consistent result
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="numItemsToTest"></param>
        /// <returns></returns>
        static TimeSpan RunTestOneSortedSet(SortedSet<User> collection, int numItemsToTest)
        {
            Stopwatch timer = new Stopwatch();
            timer.Start();

            // perform the test 50 times:
            for (int counter = 0; counter < 50; counter++)
            {
                collection.Clear();
                // add some random items
                Random rnd = new Random();
                var sequence = from n in Enumerable.Range(1, numItemsToTest)
                               select rnd.Next() * n;

                foreach (var item in sequence)
                   collection.Add(new User(item, "family", "name"));

                // search for 1000 random items
                var sequence2 = from n in Enumerable.Range(1, 1000)
                                select rnd.Next() * n;

                bool found = false;
                foreach (var item in sequence2)
                {
                    // This method is an O(ln n) operation.
                    found &= collection.Contains(new User(item, "family", "name"));
                }
            }

            timer.Stop();
            return timer.Elapsed;
        }