예제 #1
0
        /// <summary>
        /// Registers a global compare function.
        /// </summary>
        /// <remarks>
        /// This method wraps the native ups_register_compare function.
        /// </remarks>
        /// <param name="name">Descriptive name of the compare function</param>
        /// <param name="foo">Delegate object</param>
        public static void RegisterCompare(String name, CompareFunc foo)
        {
            CompareFunc pinned = new CompareFunc(foo);

            callbacks.Add(pinned);
            NativeMethods.RegisterCompare(name, pinned);
        }
예제 #2
0
        static void Main(string[] args)
        {
            object[] nums = new object[] { 1, 8, 4, 6, 0 };
            //object max= GetMax(nums, CompareInt);
            //Console.WriteLine(max);

            //用匿名方法改造
            CompareFunc func = delegate(object obj1, object obj2)
            {
                int n1 = (int)obj1;
                int n2 = (int)obj2;
                return(n1 > n2);
            };

            object max = GetMax(nums, func);

            Console.WriteLine(max);


            CompareFunc2 func2 = delegate(string a, string b, int c)
            {
                return(a + b + c);
            };



            Console.ReadKey();
        }
예제 #3
0
    public void Sort(CompareFunc comparer)
    {
        int  start   = 0;
        int  max     = size - 1;
        bool changed = true;

        while (changed)
        {
            changed = false;

            for (int i = start; i < max; ++i)
            {
                // Compare the two values
                if (comparer(buffer[i], buffer[i + 1]) > 0)
                {
                    // Swap the values
                    T temp = buffer[i];
                    buffer[i]     = buffer[i + 1];
                    buffer[i + 1] = temp;
                    changed       = true;
                }
                else if (!changed)
                {
                    // Nothing has changed -- we can start here next time
                    start = (i == 0) ? 0 : i - 1;
                }
            }
        }
    }
예제 #4
0
    public void Sort(CompareFunc comparer)
    {
        int  num  = 0;
        int  num2 = size - 1;
        bool flag = true;

        while (flag)
        {
            flag = false;
            for (int i = num; i < num2; i++)
            {
                if (comparer(buffer[i], buffer[i + 1]) > 0)
                {
                    T val = buffer[i];
                    buffer[i]     = buffer[i + 1];
                    buffer[i + 1] = val;
                    flag          = true;
                }
                else if (!flag)
                {
                    num = ((i != 0) ? (i - 1) : 0);
                }
            }
        }
    }
예제 #5
0
    public void Sort(CompareFunc comparer)
    {
        int  start   = 0;
        int  max     = size - 1;
        bool changed = true;

        while (changed)
        {
            changed = false;

            for (int i = start; i < max; ++i)
            {
                if (comparer(buffer[i], buffer[i + 1]) > 0)
                {
                    T temp = buffer[i];
                    buffer[i]     = buffer[i + 1];
                    buffer[i + 1] = temp;
                    changed       = true;
                }
                else if (!changed)
                {
                    start = (i == 0) ? 0 : i - 1;
                }
            }
        }
    }
예제 #6
0
        public static SharpVulkan.CompareOperation GetVKCompareOp(CompareFunc func)
        {
            switch (func)
            {
            case CompareFunc.Always:
                return(SharpVulkan.CompareOperation.Always);

            case CompareFunc.Never:
                return(SharpVulkan.CompareOperation.Never);

            case CompareFunc.Less:
                return(SharpVulkan.CompareOperation.Less);

            case CompareFunc.LessEqual:
                return(SharpVulkan.CompareOperation.LessOrEqual);

            case CompareFunc.Greater:
                return(SharpVulkan.CompareOperation.Greater);

            case CompareFunc.GreaterEqual:
                return(SharpVulkan.CompareOperation.GreaterOrEqual);

            case CompareFunc.Equal:
                return(SharpVulkan.CompareOperation.Equal);

            case CompareFunc.NotEqual:
                return(SharpVulkan.CompareOperation.NotEqual);

            default:
                throw new ArgumentException(nameof(func));
            }
        }
예제 #7
0
    public void Sort(CompareFunc comparer)
    {
        int  start   = 0;
        int  end     = size - 1;
        bool changed = true;

        while (changed)
        {
            changed = false;

            for (int i = start; i < end; i++)
            {
                if (comparer(array[i], array[i + 1]) > 0)
                {
                    T temp = array[i];
                    array[i]     = array[i + 1];
                    array[i + 1] = temp;
                    changed      = true;
                }
                else if (!changed)
                {
                    start = (i == 0) ? 0 : i - 1;
                }
            }
        }
    }
예제 #8
0
        public static StencilFunction ToGLStencilFunction(this CompareFunc value)
        {
            switch (value)
            {
            case CompareFunc.Always:
                return(StencilFunction.Always);

            case CompareFunc.Never:
                return(StencilFunction.Never);

            case CompareFunc.Less:
                return(StencilFunction.Less);

            case CompareFunc.LessEqual:
                return(StencilFunction.Lequal);

            case CompareFunc.Greater:
                return(StencilFunction.Greater);

            case CompareFunc.GreaterEqual:
                return(StencilFunction.Gequal);

            case CompareFunc.Equal:
                return(StencilFunction.Equal);

            case CompareFunc.NotEqual:
                return(StencilFunction.Notequal);

            default:
                throw new NotSupportedException();
            }
        }
        private IEnumerable <int> FindLongestSeq(CompareFunc compareFunc)
        {
            Initialize();

            for (var currentInputIndex = 0; currentInputIndex < _X.Count; currentInputIndex++)
            {
                // After searching, newL is 1 greater than the
                // length of the longest prefix of X[i]
                var newL = BinarySearchLargestValue(compareFunc, currentInputIndex);

                // The predecessor of X[i] is the last index of
                // the subsequence of length newL-1
                _P[currentInputIndex] = _M[newL - 1];
                _M[newL] = currentInputIndex;

                // If we found a subsequence longer than any we've
                // found yet, update L
                if (newL > _L)
                {
                    _L = newL;
                }
            }

            return(ReconstructLongestSeq());
        }
예제 #10
0
        public static All GetGLCompareFunc(CompareFunc func)
        {
            switch (func)
            {
            case CompareFunc.Always:
                return(All.Always);

            case CompareFunc.Never:
                return(All.Never);

            case CompareFunc.Less:
                return(All.Less);

            case CompareFunc.LessEqual:
                return(All.Lequal);

            case CompareFunc.Greater:
                return(All.Greater);

            case CompareFunc.GreaterEqual:
                return(All.Gequal);

            case CompareFunc.Equal:
                return(All.Equal);

            case CompareFunc.NotEqual:
                return(All.Notequal);

            default:
                throw new ArgumentException(nameof(func));
            }
        }
예제 #11
0
        private void ShowMessage(string msg)
        {
            //sp.CloseRec();
            t.Abort();
            int    loc     = -1;
            double maxrate = 0;

            for (int i = 0; i < 4; i++)
            {
                double tmp = CompareFunc.CompareString(msg, wd.refers[i]);
                if (tmp > maxrate)
                {
                    loc     = i;
                    maxrate = tmp;
                }
            }
            if (loc == -1)
            {
                Speak("抱歉我没有听清楚,请再说一遍吧");
            }
            else
            {
                cur = wd.refers[loc];
            }
            judgeReturn(loc);
        }
예제 #12
0
 public override void AlphaTestFunc(CompareFunc func, float value)
 {
     alphaTestFunc = compareFuncs[(int)func];
     device.SetRenderState(RenderState.AlphaFunc, (int)alphaTestFunc);
     alphaTestRef = (int)(value * 255);
     device.SetRenderState(RenderState.AlphaRef, alphaTestRef);
 }
 public SensitiveIntValue(CompareMode compareMode, int value, int triggerValue)
 {
     this.value        = value;
     this.triggerValue = triggerValue;
     compareFunc       = CompareFunc.GetCompareIntFunc(compareMode);
     Triggered         = new UnityEvent();
 }
예제 #14
0
        static void Main(string[] args)
        {
            CompareFunc compare     = new CompareFunc(Person.Compare);
            CompareFunc compare_age = Person.Compare_Age;

            object[] list = new object[5];
            list[0] = new Person("Nguyen Van A", 14);
            list[1] = new Person("Ngo Van C", 19);
            list[2] = new Person("Nguyen Van D", 13);
            list[3] = new Person("Pham Van A", 16);
            list[4] = new Person("Do Van E", 20);
            Sort(list, compare);

            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine(list[i].ToString());
            }

            Console.WriteLine();

            Sort(list, compare_age);

            for (int i = 0; i < list.Length; i++)
            {
                Console.WriteLine(list[i].ToString());
            }

            Console.ReadKey();
        }
예제 #15
0
 public void SetCompareFunc(CompareFunc func)
 {
     if (compareFunc == func)
     {
         return;
     }
     GL.SamplerParameter(handle, (int)All.TextureCompareFunc, (int)func);
     compareFunc = func;
 }
예제 #16
0
        public static void AreEqual <T>(this Assert assert, T expected, T actual, CompareFunc <T> compareFunc)
        {
            var comparer = new LambdaComparer <T>(compareFunc);

            CollectionAssert.AreEqual(
                new[] { expected },
                new[] { actual }, comparer,
                $"\nExpected: <{expected}>.\nActual: <{actual}>.");
        }
예제 #17
0
 public static void quickSort <T>(T[] values, int length, CompareFunc <T> comparator)
 {
     if (length > 1)
     {
         int high = length - 1;
         quickSortImpl(values, 0, high, comparator);
         insertionSort(values, 0, high, comparator);
     }
 }
예제 #18
0
 public void InsertionSort(CompareFunc comparer) {
     for (int i = 1; i < size; i++) {
         T curr = array[i];
         int j = i;
         while (j > 0 && comparer(array[j - 1], curr) > 0) {
             array[j] = array[j-1];
             j--;
         }
         array[j] = curr;
     }
 }
예제 #19
0
 public void InsertionSort(CompareFunc comparer) {
     for (int i = 1: i < size: i++) {
         T curr = array[i]:
         int j = i:
         while (j > 0 && comparer(array[j - 1], curr) > 0) {
             array[j] = array[j-1]:
             j--:
         }
         array[j] = curr:
     }
 }
예제 #20
0
 public static void Sort(object[] list, CompareFunc cmpfunc)
 {
     for (int i = 0; i < list.Length - 1; i++)
     {
         for (int j = i + 1; j < list.Length; j++)
         {
             if (cmpfunc(list[i], list[j]) == false)
             {
                 Swap(ref list[i], ref (list[j]));
             }
         }
     }
 }
예제 #21
0
        //使用委托改造
        static object GetMax(object[] nums, CompareFunc func)
        {
            object max = nums[0];

            for (int i = 0; i < nums.Length; i++)
            {
                if (func(nums[i], max))
                {
                    max = nums[i];
                }
            }
            return(max);
        }
예제 #22
0
        /// <summary>
        /// Sets the comparison function
        /// </summary>
        /// <remarks>
        /// This method wraps the native ham_set_compare_func function.<br />
        /// <br />
        /// The <see cref="CompareFunc" /> delegate compares two index keys.
        /// It returns -1 if the first key is smaller, +1 if the second key
        /// is smaller or 0 if both keys are equal.<br />
        /// <br />
        /// If <paramref name="foo"/> is null, hamsterdb will use the default
        /// compare function (which is based on memcmp(3)).<br />
        /// <br />
        /// Note that if you use a custom compare function routine in combination
        /// with extended keys, it might be useful to disable the prefix
        /// comparison, which is based on memcmp(3). See
        /// <see cref="SetPrefixCompareFunc" /> for details.
        /// </remarks>
        /// <param name="foo">The compare delegate, or null</param>
        public void SetCompareFunc(CompareFunc foo)
        {
            int st;

            lock (this) {
                st = NativeMethods.SetCompareFunc(handle, pinnedCompareFunc);
            }
            if (st != 0)
            {
                throw new DatabaseException(st);
            }
            CompareFoo = foo;
        }
예제 #23
0
        public List <Student> FindStudents(CompareFunc compareFunc, SearchType searchType, string keyword)
        {
            var students = new List <Student>();

            foreach (var student in _students)
            {
                if (compareFunc(student, searchType, keyword))
                {
                    students.Add(student);
                }
            }

            return(students);
        }
예제 #24
0
        //Tìm Sinh viên
        public List <SinhVien> FindStudents(CompareFunc compare, KieuTim kt, string keyword)
        {
            List <SinhVien> listsv = new List <SinhVien>();

            foreach (var item in lsv)
            {
                if (compare(item, kt, keyword))
                {
                    listsv.Add(item);
                }
            }

            return(listsv);
        }
예제 #25
0
        /// <summary>
        /// Sets the comparison function
        /// </summary>
        /// <remarks>
        /// This method wraps the native ups_db_set_compare_func function.<br />
        /// <br />
        /// The <see cref="CompareFunc" /> delegate compares two index keys.
        /// It returns -1 if the first key is smaller, +1 if the second key
        /// is smaller or 0 if both keys are equal.<br />
        /// <br />
        /// If <paramref name="foo"/> is null, upscaledb will use the default
        /// compare function (which is based on memcmp(3)).<br />
        /// </remarks>
        /// <param name="foo">The compare delegate, or null</param>
        public void SetCompareFunc(CompareFunc foo)
        {
            int st;

            lock (this) {
                CompareFunc pinned = new CompareFunc(foo);
                callbacks.Add(pinned);
                st = NativeMethods.SetCompareFunc(handle, pinned);
            }
            if (st != 0)
            {
                throw new DatabaseException(st);
            }
        }
예제 #26
0
 // MySort()自定函式
 static void MySort(int[] obj, CompareFunc CompareMethod)
 {
     for (int i = 0; i <= obj.Length - 2; i++)
     {
         for (int j = i + 1; j <= obj.Length - 1; j++)
         {
             if (CompareMethod(obj[j], obj[i]))
             {
                 int tmp = obj[j];
                 obj[j] = obj[i];
                 obj[i] = tmp;
             }
         }
     }
 }
예제 #27
0
        static void Main(string[] args)
        {
            object[]    nums  = new object[] { 1, 2, 4, 14 };
            CompareFunc func1 = delegate(object o1, object o2)
            {
                int i1 = (int)o1;
                int i2 = (int)o2;
                return(i1 > i2);
            };

            object maxVal = GetMax(nums, func1);

            Console.WriteLine($"最大值为{maxVal}");
            Console.ReadKey();
        }
예제 #28
0
        static T GetMax <T>(T[] nums, CompareFunc <T> func)
        //GetMax<int>
        // static int GetMax<int>(int[] nums, CompareFunc<int> func)
        {
            T max = nums[0];

            for (int i = 0; i < nums.Length; i++)
            {
                if (func(nums[i], max))
                {
                    max = nums[i];
                }
            }
            return(max);
        }
예제 #29
0
        static object GetMax(object[] nums, CompareFunc func)
        {
            object max = nums[0];

            for (int i = 1; i < nums.Length; i++)
            {
                //调用func指向的方法,判断谁大
                //写这段代码的人也不知道func指向那个方法,
                //只知道func指向的方法,有两个object参数,一个bool返回值
                if (func(nums[i], max))
                {
                    max = nums[i];
                }
            }
            return(max);
        }
예제 #30
0
 private void BubbleSort(List <Animal> arr, CompareFunc cmp)
 {
     for (int pass = 0; pass < arr.Count; pass++)
     {
         for (int i = 0; i < arr.Count - 1; i++)
         {
             if (cmp(arr[i], arr[i + 1]))
             {
                 Animal temp;
                 temp       = arr[i];
                 arr[i]     = arr[i + 1];
                 arr[i + 1] = temp;
             }
         }
     }
 }
예제 #31
0
 public static Compare Map(CompareFunc compareFunc)
 {
     switch (compareFunc)
      {
          case CompareFunc.Always:
              return Compare.Always;
          case CompareFunc.Equal:
              return Compare.Equal;
          case CompareFunc.Greater:
              return Compare.Greater;
          case CompareFunc.GreaterEqual:
              return Compare.GreaterEqual;
          case CompareFunc.Less:
              return Compare.Less;
          case CompareFunc.LessEqual:
              return Compare.LessEqual;
          case CompareFunc.Never:
              return Compare.Never;
          case CompareFunc.NotEqual:
              return Compare.NotEqual;
          default:
              throw new ArgumentOutOfRangeException("compareFunc");
      }
 }
예제 #32
0
 public static AlphaFunction Map(CompareFunc value)
 {
     switch (value)
     {
         case CompareFunc.Always:
             return AlphaFunction.Always;
         case CompareFunc.Equal:
             return AlphaFunction.Equal;
         case CompareFunc.Greater:
             return AlphaFunction.Gequal;
         case CompareFunc.GreaterEqual:
             return AlphaFunction.Gequal;
         case CompareFunc.Less:
             return AlphaFunction.Less;
         case CompareFunc.LessEqual:
             return AlphaFunction.Lequal;
         case CompareFunc.Never:
             return AlphaFunction.Never;
         case CompareFunc.NotEqual:
             return AlphaFunction.Notequal;
         default:
             throw new ArgumentOutOfRangeException("value");
     }
 }
예제 #33
0
 /// <summary>
 /// Sets the comparison function
 /// </summary>
 /// <remarks>
 /// This method wraps the native ups_db_set_compare_func function.<br />
 /// <br />
 /// The <see cref="CompareFunc" /> delegate compares two index keys.
 /// It returns -1 if the first key is smaller, +1 if the second key
 /// is smaller or 0 if both keys are equal.<br />
 /// <br />
 /// If <paramref name="foo"/> is null, upscaledb will use the default
 /// compare function (which is based on memcmp(3)).<br />
 /// </remarks>
 /// <param name="foo">The compare delegate, or null</param>
 public void SetCompareFunc(CompareFunc foo)
 {
     int st;
       lock (this) {
     CompareFunc pinned = new CompareFunc(foo);
     callbacks.Add(pinned);
     st = NativeMethods.SetCompareFunc(handle, pinned);
       }
       if (st != 0)
     throw new DatabaseException(st);
 }
예제 #34
0
 /// <summary>
 /// Sets the comparison function
 /// </summary>
 /// <remarks>
 /// This method wraps the native ups_db_set_compare_func function.<br />
 /// <br />
 /// The <see cref="CompareFunc" /> delegate compares two index keys.
 /// It returns -1 if the first key is smaller, +1 if the second key
 /// is smaller or 0 if both keys are equal.<br />
 /// <br />
 /// If <paramref name="foo"/> is null, upscaledb will use the default
 /// compare function (which is based on memcmp(3)).<br />
 /// </remarks>
 /// <param name="foo">The compare delegate, or null</param>
 public void SetCompareFunc(CompareFunc foo)
 {
     int st;
       lock (this) {
     st = NativeMethods.SetCompareFunc(handle, pinnedCompareFunc);
       }
       if (st != 0)
     throw new DatabaseException(st);
       CompareFoo = foo;
 }
예제 #35
0
파일: Sampler.cs 프로젝트: Zulkir/ObjectGL
 public void SetCompareFunc(CompareFunc func)
 {
     if (compareFunc == func) return;
     GL.SamplerParameter(handle, (int)All.TextureCompareFunc, (int)func);
     compareFunc = func;
 }
예제 #36
0
 public static extern int RegisterCompare(String name,
 CompareFunc foo);
예제 #37
0
 /// <summary>
 /// Registers a global compare function.
 /// </summary>
 /// <remarks>
 /// This method wraps the native ups_register_compare function.
 /// </remarks>
 /// <param name="name">Descriptive name of the compare function</param>
 /// <param name="foo">Delegate object</param>
 public static void RegisterCompare(String name, CompareFunc foo)
 {
     CompareFunc pinned = new CompareFunc(foo);
       callbacks.Add(pinned);
       NativeMethods.RegisterCompare(name, pinned);
 }
예제 #38
0
 public static void StencilFunc(CompareFunc func, byte reference, byte mask)
 {
     GDTransport.cmd32((10 << 24) | ((byte)func << 16) | ((reference & 255) << 8) | (mask & 255));
 }
예제 #39
0
 public static extern int SetCompareFunc(IntPtr handle,
 CompareFunc foo);