Exemple #1
0
 public override BaseRef Unwrap()
 {
     if (_cached == null)
     {
         _cached = new NumRef(N, Filter ?? RefFilter.All, NonOverlapping, Inclusive);
     }
     return(_cached);
 }
Exemple #2
0
        public IEnumerable <KeyValuePair <FloorSelection, FloorSelection> > MatchFrom(IReadOnlyList <FloorSelection> floors, BaseRef start, IEnumerable <FloorSelection> selectedByStart)
        {
            Contract.Requires(floors != null);
            Contract.Requires(start != null);
            Contract.Requires(selectedByStart != null);
            Contract.Ensures(Contract.Result <IEnumerable <KeyValuePair <FloorSelection, FloorSelection> > >() != null);

            //Select all matching pairs
            var selected = start.FilterByMode(selectedByStart.SelectMany(a => {
                var matches = MatchImpl(floors, a.Index)
                              .Select(b => new KeyValuePair <FloorSelection, FloorSelection>(a, b))
                              .Where(p => Inclusive || p.Key.Index != p.Value.Index);

                return(FilterByMode(matches));
            }));

            //If we don't care about overlaps we're done, good to go
            if (!NonOverlapping)
            {
                return(selected);
            }

            //We need to reject overlaps
            //First group into overlapping sets
            var sets = new List <List <KeyValuePair <FloorSelection, FloorSelection> > >();

            foreach (var kvp in selected)
            {
                var set = sets.FirstOrDefault(s => s.Any(a => a.Key.Index <= kvp.Value.Index && a.Value.Index >= kvp.Key.Index));
                if (set != null)
                {
                    set.Add(kvp);
                }
                else
                {
                    sets.Add(new List <KeyValuePair <FloorSelection, FloorSelection> > {
                        kvp
                    });
                }
            }

            //Now filter *each set* by the filter mode
            return(sets.SelectMany(FilterByMode));
        }