Exemplo n.º 1
0
    public bool Sort(System.Comparison <_Ty> comparer)
    {
        if (m_nLeng <= 1)
        {
            return(false);
        }

        bool bSort = false;
        _Ty  temp;
        int  i          = m_nLeng - 1;
        int  j          = 0;
        int  nSwapIndex = 0;

        while (i > 0)
        {
            nSwapIndex = 0;
            for (j = 0; j < i; j++)
            {
                if (comparer(m_pData[j + 1], m_pData[j]) < 0)
                {//
                    temp           = m_pData[j + 1];
                    m_pData[j + 1] = m_pData[j];
                    m_pData[j]     = temp;
                    nSwapIndex     = j;//记录交换下标
                    bSort          = true;
                }
            }
            i = nSwapIndex;
        }
        return(bSort);
    }
Exemplo n.º 2
0
 /// <summary>
 /// 初始堆进行调整
 /// 将H[0..length-1]建成堆
 /// 调整完之后第一个元素是序列的最小的元素
 /// </summary>
 /// <param name="length">Length.</param>
 /// <param name="comparer">Comparer.</param>
 private void BuildingHeap(System.Comparison <T> comparer)
 {
     //最后一个有孩子的节点的位置 i=  (length -1) / 2
     for (int i = (size - 1) / 2; i >= 0; --i)
     {
         HeapAdjust(i, size, comparer);
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Запрос всех элементов данного типа по предикату
        /// </summary>
        /// <typeparam name="Extent">Бизнес-класс</typeparam>
        /// <param name="Match">Предикат</param>
        /// <param name="Comparision">Сравнение</param>
        /// <returns>Результат</returns>
        public static List <Extent> Query <Extent>(Predicate <Extent> Match, System.Comparison <Extent> Comparision)
        {
            testAndThrow();
            List <Extent> result = new List <Extent>(db.Query <Extent>(Match));

            result.Sort(Comparision);
            return(result);
        }
    void Start()
    {
        isLoaded = false;
        Load(file);

        System.Comparison <Task> comparison = (x, y) => x.TimeToPresent.CompareTo(y.TimeToPresent);
        TasksList.Sort(comparison);
    }
Exemplo n.º 5
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	配列のソート実行
     */
    //----------------------------------------------------------------------------
    public void Sort(System.Comparison <T> fnComparer)
    {
        if (m_Buffer == null)
        {
            return;
        }

        System.Array.Sort(m_Buffer, 0, m_BufferSize, new Comparer(fnComparer));
    }
    static int Sort(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1 && TypeChecker.CheckTypes(L, 1, typeof(System.Collections.Generic.List <string>)))
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.ToObject(L, 1);
                obj.Sort();
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(System.Collections.Generic.List <string>), typeof(System.Comparison <string>)))
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.ToObject(L, 1);
                System.Comparison <string> arg0 = null;
                LuaTypes funcType2 = LuaDLL.lua_type(L, 2);

                if (funcType2 != LuaTypes.LUA_TFUNCTION)
                {
                    arg0 = (System.Comparison <string>)ToLua.ToObject(L, 2);
                }
                else
                {
                    LuaFunction func = ToLua.ToLuaFunction(L, 2);
                    arg0 = DelegateFactory.CreateDelegate(typeof(System.Comparison <string>), func) as System.Comparison <string>;
                }

                obj.Sort(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(System.Collections.Generic.List <string>), typeof(System.Collections.Generic.IComparer <string>)))
            {
                System.Collections.Generic.List <string>      obj  = (System.Collections.Generic.List <string>)ToLua.ToObject(L, 1);
                System.Collections.Generic.IComparer <string> arg0 = (System.Collections.Generic.IComparer <string>)ToLua.ToObject(L, 2);
                obj.Sort(arg0);
                return(0);
            }
            else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(System.Collections.Generic.List <string>), typeof(int), typeof(int), typeof(System.Collections.Generic.IComparer <string>)))
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.ToObject(L, 1);
                int arg0 = (int)LuaDLL.lua_tonumber(L, 2);
                int arg1 = (int)LuaDLL.lua_tonumber(L, 3);
                System.Collections.Generic.IComparer <string> arg2 = (System.Collections.Generic.IComparer <string>)ToLua.ToObject(L, 4);
                obj.Sort(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: System.Collections.Generic.List<string>.Sort"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        unsafe public void AddSpongyEdges(ICollection <AnchorEdge> spongyEdges)
        {
            AnchorEdge[] regularEdges = new AnchorEdge[spongyEdges.Count];
            int          idx          = 0;

            foreach (var edge in spongyEdges)
            {
                regularEdges[idx++] = RegularEdge(edge.anchorId1, edge.anchorId2);
            }
            System.Comparison <AnchorEdge> alphabeticCompare = (x, y) =>
            {
                int cmp1 = x.anchorId1.CompareTo(y.anchorId1);
                if (cmp1 < 0)
                {
                    return(-1);
                }
                if (cmp1 > 0)
                {
                    return(1);
                }
                int cmp2 = x.anchorId2.CompareTo(y.anchorId2);
                return(cmp2);
            };
            System.Array.Sort(regularEdges, alphabeticCompare);

            int spongyIdx = 0;

            for (int frozenIdx = 0; frozenIdx < frozenEdges.Count; ++frozenIdx)
            {
                if (spongyIdx >= regularEdges.Length)
                {
                    break;
                }
                int frozenToSpongy = alphabeticCompare(frozenEdges[frozenIdx], regularEdges[spongyIdx]);
                if (frozenToSpongy >= 0)
                {
                    if (frozenToSpongy > 0)
                    {
                        // insert edge here
                        frozenEdges.Insert(frozenIdx, regularEdges[spongyIdx]);
                    }
                    // If existing frozen is greater, we just inserted (above) spongy, so advance.
                    // If they are equal, we want to skip spongy, so advance.
                    // If existing is lesser, we haven't reached insertion point yet,
                    // so don't advance spongyIdx (stay out of this conditional branch if frozenToSpongy < 0).
                    ++spongyIdx;
                }
            }
            while (spongyIdx < regularEdges.Length)
            {
                frozenEdges.Add(regularEdges[spongyIdx++]);
            }
            checkError();
        }
 private void Awake()
 {
     Instance     = this;
     FogNullZones = new List <Bounds>();
     // Create3DNoiseTexture();
     // CreateDitherTexture();
     NoiseTexture3DInstance = NoiseTexture3D;
     Shader.SetGlobalTexture("_WeatherMakerNoiseTexture3D", NoiseTexture3D);
     nullFogZoneSorterReference = NullFogZoneSorter;
     lightSorterReference       = LightSorter;
 }
Exemplo n.º 9
0
 public void FindNodes()
 {
     nodes = FindObjectsOfType <MapNode>();
     System.Comparison <MapNode> comp = (a, b) => a.name.CompareTo(b.name);
     System.Array.Sort(nodes, comp);
     for (int i = 0; i < nodes.Length; ++i)
     {
         nodes[i].map      = this;
         nodes[i].node_idx = i;
     }
 }
Exemplo n.º 10
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	配列の内包チェック
     */
    //----------------------------------------------------------------------------
    public bool ChkInside(System.Comparison <T> fnComparer, T tTarget)
    {
        for (int i = 0; i < m_BufferSize; ++i)
        {
            if (fnComparer.Invoke(m_Buffer[i], tTarget) <= 0)
            {
                continue;
            }

            return(true);
        }

        return(false);
    }
Exemplo n.º 11
0
 /// <summary>
 /// 堆排序算法
 /// </summary>
 /// <param name="length">Length.</param>
 /// <param name="comparer">Comparer.</param>
 private void HeapSort(System.Comparison <T> comparer)
 {
     //初始堆
     BuildingHeap(comparer);
     //从最后一个元素开始对序列进行调整
     for (int i = size - 1; i > 0; --i)
     {
         //交换堆顶元素H[0]和堆中最后一个元素
         T temp = buffer [i];
         buffer [i] = buffer [0];
         buffer [0] = temp;
         //每次交换堆顶元素和堆中最后一个元素之后,都要对堆进行调整
         HeapAdjust(0, i, comparer);
     }
 }
Exemplo n.º 12
0
        // Random floating point numbers don't really add much confidence, better to explicitly test
        // specific edge cases and (logarithmic?) ranges.
        private void RoundTripFloatRandom <T>(System.Comparison <T> compare, double min, double max)
        {
            const int n = 10000;

            Random rand = new Random(0x1337);

            for (int i = 0; i < n; ++i)
            {
                // Add carefully, to avoid overflowing max range.
                double d    = rand.NextDouble();
                double num  = d * max + (1.0 - d) * min;
                T      tnum = (T)Convert.ChangeType(num, typeof(T));
                RoundTrip <T>(compare, false, tnum);
            }
        }
Exemplo n.º 13
0
        private void RoundTrip <T>(System.Comparison <T> compare, bool writeJsonToConsole, params T[] input)
        {
            string json = JsonMapper.ToJson(input);

            if (writeJsonToConsole)
            {
                Console.WriteLine(json);
            }
            T[] output = JsonMapper.ToObject <T[]>(json);

            Assert.AreEqual(input.Length, output.Length);
            for (int i = 0; i < input.Length; ++i)
            {
                Assert.That(compare(input[i], output[i]) == 0, "{0} does not match {1}", input[i], output[i]);
            }
        }
Exemplo n.º 14
0
    //默认的sort同优先级会乱序,所以使用自己写的插入排序实现
    public static void SortEx <T>(this List <T> list, System.Comparison <T> comparison)
    {
        int count = list.Count;
        T   tem;

        for (int j = 1; j < count; j++)
        {
            tem = list[j];

            int i = j - 1;
            for (; i >= 0 && comparison(list[i], tem) > 0; i--)
            {
                list[i + 1] = list[i];
            }
            list[i + 1] = tem;
        }
    }
Exemplo n.º 15
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	配列のソート実行
     */
    //----------------------------------------------------------------------------
    public void Sort(System.Comparison <T> fnComparer, System.Action <T> fnCreateSortNum)
    {
        if (m_Buffer == null)
        {
            return;
        }

        //-------------------
        // ソートに使用する番号を構築
        //-------------------
        for (int i = 0; i < m_BufferSize; ++i)
        {
            fnCreateSortNum.Invoke(m_Buffer[i]);
        }

        System.Array.Sort(m_Buffer, 0, m_BufferSize, new Comparer(fnComparer));
    }
    static int Sort(IntPtr L)
    {
        try
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 1)
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <string>));
                obj.Sort();
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <System.Collections.Generic.IComparer <string> >(L, 2))
            {
                System.Collections.Generic.List <string>      obj  = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <string>));
                System.Collections.Generic.IComparer <string> arg0 = (System.Collections.Generic.IComparer <string>)ToLua.ToObject(L, 2);
                obj.Sort(arg0);
                return(0);
            }
            else if (count == 2 && TypeChecker.CheckTypes <System.Comparison <string> >(L, 2))
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <string>));
                System.Comparison <string> arg0 = (System.Comparison <string>)ToLua.ToObject(L, 2);
                obj.Sort(arg0);
                return(0);
            }
            else if (count == 4)
            {
                System.Collections.Generic.List <string> obj = (System.Collections.Generic.List <string>)ToLua.CheckObject(L, 1, typeof(System.Collections.Generic.List <string>));
                int arg0 = (int)LuaDLL.luaL_checknumber(L, 2);
                int arg1 = (int)LuaDLL.luaL_checknumber(L, 3);
                System.Collections.Generic.IComparer <string> arg2 = (System.Collections.Generic.IComparer <string>)ToLua.CheckObject <System.Collections.Generic.IComparer <string> >(L, 4);
                obj.Sort(arg0, arg1, arg2);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: System.Collections.Generic.List<string>.Sort"));
            }
        }
        catch (Exception e)
        {
            return(LuaDLL.toluaL_exception(L, e));
        }
    }
        public void Sort(System.Comparison <T> comparison)
        {
            bool isChanged = false;

            lock (syncObject)
            {
                if (!_isReadOnly)
                {
                    _list.Sort(comparison);
                    isChanged = true;
                }
            }

            if (isChanged)
            {
                RaiseCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
            }
        }
Exemplo n.º 18
0
        /// <summary>
        /// Метод реализует сортировку, т.е. перестановку элементов последовательности в соотвествии с функцией
        /// сравнения, заданной аргументом
        /// </summary>
        /// <param name="compare">Функция, задающая сравнение друх входов</param>
        public void SortComparison(System.Comparison <PxEntry> compare)
        {
            if (typ.Vid != PTypeEnumeration.sequence)
            {
                throw new Exception("SortComparison can't be implemented to this vid");
            }
            PTypeSequence pts  = (PTypeSequence)typ;
            long          llen = this.Count();

            if (llen < 2)
            {
                return;           // сортировать не нужно
            }
            // Указатель на нулевой элемент и размер головы записи
            long p0   = this.Element(0).offset;
            int  size = pts.ElementType.HeadSize;

            // организуем массив offset'ов - указателей на головы элементов
            long[] offsets = new long[llen];
            for (long ind = 0; ind < llen; ind++)
            {
                offsets[ind] = p0 + size * ind;
            }
            //теперь сортируем используя функцию сравнения
            PxEntry e1 = new PxEntry(pts.ElementType, long.MinValue, this.fis);
            PxEntry e2 = new PxEntry(pts.ElementType, long.MinValue, this.fis);

            Array.Sort <long>(offsets, (long o1, long o2) =>
            {
                e1.offset = o1;
                e2.offset = o2;
                return(compare(e1, e2));
            });
            // Надеюсь, отсортировали

            // Превращаю массив смещений в массив индексов элементов
            int[] indexes = new int[llen];
            for (long ind = 0; ind < llen; ind++)
            {
                indexes[ind] = (int)((offsets[ind] - p0) / size);
            }
            // теперь в i-ом элементе массива находится индекс элемента (головы), который должен попасть на i-ю позицию
            ReorderSequenceArrayHeads(llen, p0, size, indexes);
        }
Exemplo n.º 19
0
    public static Delegate System_Comparison_int(LuaFunction func, LuaTable self, bool flag)
    {
        if (func == null)
        {
            System.Comparison <int> fn = delegate(int param0, int param1) { return(0); };
            return(fn);
        }

        if (!flag)
        {
            System.Comparison <int> d = (new System_Comparison_int_Event(func)).Call;
            return(d);
        }
        else
        {
            System.Comparison <int> d = (new System_Comparison_int_Event(func, self)).CallWithSelf;
            return(d);
        }
    }
Exemplo n.º 20
0
    //默认的sort同优先级会乱序,所以使用自己写的插入排序实现
    public static void SortEx <T>(this LinkedList <T> list, System.Comparison <T> comparison)
    {
        if (list.Count < 2)
        {
            return;
        }

        LinkedListNode <T> tem;
        LinkedListNode <T> last = list.First;//已经排好序的那部分的队尾,在它的后面是等待排序的节点
        LinkedListNode <T> cur  = last;

        do
        {
            do
            {
                if (comparison(last.Next.Value, cur.Value) >= 0)
                {
                    if (last == cur)//不用插入了
                    {
                        last = last.Next;
                        cur  = last;
                    }
                    else//插入
                    {
                        tem = last.Next;
                        list.Remove(tem);
                        list.AddAfter(cur, tem);
                        cur = last;
                    }
                    break;
                }
                if (cur.Previous == null)
                {
                    tem = last.Next;
                    list.Remove(tem);
                    list.AddBefore(cur, tem);
                    cur = last;
                    break;
                }
                cur = cur.Previous;
            }while (true);
        } while (last.Next != null);
    }
Exemplo n.º 21
0
        public void Sort(System.Comparison <T> comparer)
        {
            bool changed = true;

            while (changed)
            {
                changed = false;

                for (int i = 1; i < _len; i++)
                {
                    if (comparer.Invoke(_buffer[i - 1], _buffer[i]) > 0)
                    {
                        T temp = _buffer[i];
                        _buffer[i]     = _buffer[i - 1];
                        _buffer[i - 1] = temp;
                        changed        = true;
                    }
                }
            }
        }
Exemplo n.º 22
0
    /// <summary>
    /// Warning: bubble sort
    /// </summary>
    public void Sort(System.Comparison <T> comparer)
    {
        bool changed = true;

        while (changed)
        {
            changed = false;

            for (int i = 1; i < size; ++i)
            {
                if (comparer.Invoke(buffer[i - 1], buffer[i]) > 0)
                {
                    T temp = buffer[i];
                    buffer[i]     = buffer[i - 1];
                    buffer[i - 1] = temp;
                    changed       = true;
                }
            }
        }
    }
Exemplo n.º 23
0
        public override void Start()
        {
            _Instance = this;

            m_Grid = mDMono.transform.GetComponentEx <UIGrid>();

            if (m_Grid.arrangement == UIGrid.Arrangement.Horizontal)
            {
                m_Column = (int)FilterSetting.Size.x;
                m_Row    = (int)FilterSetting.Size.y;
            }
            else
            {
                m_Row    = (int)FilterSetting.Size.x;
                m_Column = (int)FilterSetting.Size.y;
            }
            InitFilterSettings();
            InitSelectionHandling();
            SortingComparison = SortingComparisonHandler.Comparison;
        }
Exemplo n.º 24
0
    public void SaveFile()
    {
        BinaryFormatter formatter = new BinaryFormatter();
        string          path      = Application.persistentDataPath + "/" + SceneManager.GetActiveScene().name;
        FileStream      stream    = new FileStream(path, FileMode.Create);

        if (nodes == null)
        {
            nodes = FindObjectsOfType <MapNode>();
            System.Comparison <MapNode> comp = (a, b) => a.name.CompareTo(b.name);
            System.Array.Sort(nodes, comp);
            for (int i = 0; i < nodes.Length; ++i)
            {
                nodes[i].node_idx = i;
            }
        }
        int attaker_idx  = -1;
        int defender_idx = -1;

        if (target_node != null && selected_node != null)
        {
            for (int i = 0; i < nodes.Length; ++i)
            {
                if (nodes[i] == selected_node)
                {
                    defender_idx = i;
                }
                if (nodes[i] == target_node)
                {
                    attaker_idx = i;
                }
            }
        }

        MapSaveData data = new MapSaveData(nodes, attaker_idx, defender_idx);

        formatter.Serialize(stream, data);
        stream.Close();

        saved_campaign = true;
    }
Exemplo n.º 25
0
        private Index(DataTable table, IndexField[] indexFields, System.Comparison <DataRow> comparison, DataViewRowState recordStates, IFilter rowFilter)
        {
            Bid.Trace("<ds.Index.Index|API> %d#, table=%d, recordStates=%d{ds.DataViewRowState}\n",
                      ObjectID, (table != null) ? table.ObjectID : 0, (int)recordStates);
            Debug.Assert(indexFields != null);
            Debug.Assert(null != table, "null table");
            if ((recordStates &
                 (~(DataViewRowState.CurrentRows | DataViewRowState.OriginalRows))) != 0)
            {
                throw ExceptionBuilder.RecordStateRange();
            }
            this.table = table;
            _listeners = new Listeners <DataViewListener>(ObjectID,
                                                          delegate(DataViewListener listener)
            {
                return(null != listener);
            });

            IndexFields       = indexFields;
            this.recordStates = recordStates;
            _comparison       = comparison;

            DataColumnCollection columns = table.Columns;

            isSharable = (rowFilter == null) && (comparison == null); // a filter or comparison make an index unsharable
            if (null != rowFilter)
            {
                this.rowFilter = new WeakReference(rowFilter);
                DataExpression expr = (rowFilter as DataExpression);
                if (null != expr)
                {
                    _hasRemoteAggregate = expr.HasRemoteAggregate();
                }
            }
            InitRecords(rowFilter);

            // do not AddRef in ctor, every caller should be responsible to AddRef it
            // if caller does not AddRef, it is expected to be a one-time read operation because the index won't be maintained on writes
        }
Exemplo n.º 26
0
        // sortowanie katowe punktow z tablicy p w kierunku przeciwnym do ruchu wskazowek zegara wzgledem punktu centralnego c
        // czyli sortowanie wzgledem roznacych katow odcinka (c,p[i]) z osia x
        // przy pomocy parametru ifAngleEqual mo¿na doprwcyzowaæ kryterium sortowania gdy katy sa rowne
        // (domyslnie nic nie doprecyzowujemy, pozostawiamy rowne)
        public static Point[] AngleSort(Point c, Point[] p, System.Comparison <Point> ifAngleEqual = null)
        {
            if (ifAngleEqual == null)
            {
                ifAngleEqual = (p1, p2) => 0;
            }
            if (p == null)
            {
                throw new System.ArgumentNullException();
            }
            if (p.Length < 2)
            {
                return(p);
            }
            System.Comparison <Point> cmp = delegate(Point p1, Point p2)
            {
                int r = -(new Geometry.Segment(c, p1)).Direction(p2);
                return(r != 0 ? r : ifAngleEqual(p1, p2));
            };
            var s1 = new System.Collections.Generic.List <Point>();
            var s2 = new System.Collections.Generic.List <Point>();

            for (int i = 0; i < p.Length; ++i)
            {
                if (p[i].y > c.y || (p[i].y == c.y && p[i].x >= c.x))
                {
                    s1.Add(p[i]);
                }
                else
                {
                    s2.Add(p[i]);
                }
            }
            s1.Sort(cmp);
            s2.Sort(cmp);
            s1.AddRange(s2);
            return(s1.ToArray());
        }
Exemplo n.º 27
0
        private void geneTest_Load(object sender, EventArgs e)
        {
            //泛型数据填充
            Person        p1      = new Person("张二", 31);
            Person        p2      = new Person("张六", 49);
            Person        p3      = new Person("张三", 33);
            List <Person> persons = new List <Person> {
                p1, p2, p3
            };

            lblinfo.Text = "数据填充完成!";
            Persons personCol = new Persons {
                p1, p2, p3
            };

            BtnDo.Text = personCol.GetAllNames();

            //按照默认规则对集合进行排序,通过不带参数的Sort方法对集合进行排序 - 通过数字
            //persons.Sort();
            //用 1 号比较器,Compare方法,对集合进行排序 - 通过名称
            //persons.Sort(NameComparer.Default);
            //用 2 号比较器,通过内置的泛型委托System.Comparison<T>,对集合排序 - 名称
            System.Comparison <Person> NameComparison = new System.Comparison <Person>(PersonComparison.Name);
            persons.Sort(NameComparison);
            //输出所有人姓名
            foreach (Person p in persons)
            {
                textBox1.Text += p.Name + " ";
            }
            //用 3 号搜索器 - 输出所有中年人姓名
            System.Predicate <Person> MidAgePredicate = new System.Predicate <Person>(PersonPredicate.MidAge);
            List <Person>             MidAgePersons   = persons.FindAll(MidAgePredicate);

            foreach (Person p in MidAgePersons)
            {
                textBox2.Text += p.Name + " ";
            }
        }
Exemplo n.º 28
0
    public static Delegate System_Comparison_string(LuaFunction func, LuaTable self, bool flag)
    {
        if (func == null)
        {
            System.Comparison <string> fn = delegate(string param0, string param1) { return(0); };
            return(fn);
        }

        if (!flag)
        {
            System_Comparison_string_Event target = new System_Comparison_string_Event(func);
            System.Comparison <string>     d      = target.Call;
            target.method = d.Method;
            return(d);
        }
        else
        {
            System_Comparison_string_Event target = new System_Comparison_string_Event(func, self);
            System.Comparison <string>     d      = target.CallWithSelf;
            target.method = d.Method;
            return(d);
        }
    }
Exemplo n.º 29
0
    public System.Comparison <int> System_Comparison_int(LuaFunction func, LuaTable self, bool flag)
    {
        if (func == null)
        {
            System.Comparison <int> fn = delegate(int param0, int param1) { return(0); };
            return(fn);
        }

        if (!flag)
        {
            System_Comparison_int_Event target = new System_Comparison_int_Event(func);
            System.Comparison <int>     d      = target.Call;
            target.method = d.Method;
            return(d);
        }
        else
        {
            System_Comparison_int_Event target = new System_Comparison_int_Event(func, self);
            System.Comparison <int>     d      = target.CallWithSelf;
            target.method = d.Method;
            return(d);
        }
    }
Exemplo n.º 30
0
    /// <summary>
    /// 已知H[s…m]除了H[s] 外均满足堆的定义
    /// 调整H[s],使其成为大顶堆.即将对第s个结点为根的子树筛选
    /// </summary>
    /// <param name="s">待调整的数组元素的位置.</param>
    /// <param name="length">数组的长度.</param>
    /// <param name="comparer">Comparer.</param>
    private void HeapAdjust(int s, int length, System.Comparison <T> comparer)
    {
        T   tmp   = buffer [s];
        int child = 2 * s + 1;         //左孩子结点的位置。(i+1 为当前调整结点的右孩子结点的位置)

        while (child < length)
        {
            if (child + 1 < length && comparer(buffer [child], buffer [child + 1]) < 0)                // 如果右孩子大于左孩子(找到比当前待调整结点大的孩子结点)
            {
                ++child;
            }
            if (comparer(buffer [s], buffer [child]) < 0) // 如果较大的子结点大于父结点
            {
                buffer [s] = buffer [child];              // 那么把较大的子结点往上移动,替换它的父结点
                s          = child;                       // 重新设置s ,即待调整的下一个结点的位置
                child      = 2 * s + 1;
            }
            else                            // 如果当前待调整结点大于它的左右孩子,则不需要调整,直接退出
            {
                break;
            }
            buffer [s] = tmp;                     // 当前待调整的结点放到比其大的孩子结点位置上
        }
    }