private void CleanUpDeadWeakReferences()
        {
            int newCount = 0;

            // determine how many entries are valid
            for (int i = Count - 1; i >= 0; --i)
            {
                if (this[i].IsValid())
                {
                    ++newCount;
                }
            }

            // if all the entries are valid, there's nothing to do
            if (newCount == Count)
            {
                return;
            }

            // compact the valid entries
            Compacter compacter  = new Compacter(this, newCount);
            int       runStart   = 0;     // starting index of current run
            bool      runIsValid = false; // whether run contains valid or invalid entries

            for (int i = 0, n = Count; i < n; ++i)
            {
                if (runIsValid != this[i].IsValid())    // run has ended
                {
                    if (runIsValid)
                    {
                        // emit a run of valid entries to the compacter
                        compacter.Include(runStart, i);
                    }

                    // start a new run
                    runStart   = i;
                    runIsValid = !runIsValid;
                }
            }

            // emit the last run of valid entries
            if (runIsValid)
            {
                compacter.Include(runStart, Count);
            }

            // finish the job
            compacter.Finish();
        }
Beispiel #2
0
 public static void Main(string[] args)
 {
     if (args.Length != 1)
     {
         return;
     }
     else if (args[0] == "mmah-convert")
     {
         Converter conv = new Converter();
         conv.Parse("../work/graphics.txt");
         conv.WriteResults("../library/data/x-mmah-medians.js",
                           "../library/data/x-mmah-strokes.js",
                           "../library/data/mmah.json");
     }
     else if (args[0] == "hl-compact")
     {
         Compacter comp = new Compacter();
         comp.Parse("../library/data/x-hl-strokes.json");
         comp.WriteResults("../library/data/orig.json");
     }
 }