Beispiel #1
0
        // ----------------------------------------------------------------------------------------
        /// <!-- CopyAll -->
        /// <summary>
        ///      Makes a copy preserving the keys
        /// </summary>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeList CopyAll()
        {
            EndemeList list = new EndemeList(Label, this.DefaultEnSet);

            foreach (Guid key in this)
            {
                list.Add(key, this[key].Copy());
            }
            if (!list.Sane)
            {
                throw new NullReferenceException("EndemeList '" + list.Label + "' is insane.");
            }
            return(list);
        }
Beispiel #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- OrderBy -->
        /// <summary>
        ///      Orders the elements in the list using the 'NewMatch' algorithm (produces a new list)
        /// </summary>
        /// <param name="sortEndeme"></param>
        /// <returns></returns>
        /// <remarks>beta code - nearly production ready</remarks>
        public EndemeList OrderBy(Endeme sortEndeme)
        {
            if (sortEndeme.EnSet == null)
            {
                sortEndeme.EnSet = DefaultEnSet;
            }


            // --------------------------------------------------------------------------
            //  Put the keys in order, preserving the keys
            // --------------------------------------------------------------------------
            EndemeList toOrder = this.CopyAll();

            foreach (Guid key in toOrder)
            {
                toOrder[key].TempMatch = sortEndeme.Match(toOrder[key].ItemEndeme, WeightFormula.Refined);
                // TODO: change this to Match1
            }


            // --------------------------------------------------------------------------
            //  Order the list by match using Linq  TODO: use this!
            // --------------------------------------------------------------------------
            List <Guid> orderedKeys = toOrder._list.OrderBy(x => x.Value.TempMatch).Select(x => x.Key).ToList();


            //// --------------------------------------------------------------------------
            ////  Order the list by match without Linq
            //// --------------------------------------------------------------------------
            //Dictionary<Guid,double> quantRaw = new Dictionary<Guid,double>();
            //for (int i = 0; i < toOrder.Count; ++i)
            //    quantRaw.Add(toOrder[i].ItemKey, toOrder[i].TempMatch);
            //SortedDictionary<Guid,double> raw = new SortedDictionary<Guid,double>(quantRaw);
            //List<Guid> orderedKeys = new List<Guid>();
            //List<double> values = new List<double>(raw.Values);
            //values.Sort();
            //for (int i = 0; i < values.Count; ++i)
            //{
            //    Guid g = Guid.Empty;
            //    foreach (Guid key in raw.Keys)
            //    {
            //        if (raw[key] == values[i] && raw[key] > 0)
            //            g = key;
            //    }
            //    if (g != Guid.Empty)
            //    {
            //        orderedKeys.Add(g);
            //        raw.Remove(g);
            //    }
            //}


            // --------------------------------------------------------------------------
            //  Put the list in order, preserving the keys
            // --------------------------------------------------------------------------
            EndemeList ordered = new EndemeList(Label, toOrder.DefaultEnSet);

            foreach (Guid key in orderedKeys)
            {
                ordered.Add(key, toOrder[key]);
            }

            if (!Sane)
            {
                throw new NullReferenceException("EndemeList '" + Label + "' is insane.");
            }
            return(ordered);
        }