Upscaledb.Database.SetCompareFunc C# (CSharp) 메소드

SetCompareFunc() 공개 메소드

Sets the comparison function
This method wraps the native ups_db_set_compare_func function.

The 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.

If foo is null, upscaledb will use the default compare function (which is based on memcmp(3)).
public SetCompareFunc ( CompareFunc foo ) : void
foo CompareFunc The compare delegate, or null
리턴 void
        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);
        }

Usage Example

예제 #1
0
        private void SetComparator()
        {
            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            byte[] k = new byte[5];
            byte[] r = new byte[5];
            Parameter[] param = new Parameter[1];
            param[0] = new Parameter();
            param[0].name = UpsConst.UPS_PARAM_KEY_TYPE;
            param[0].value = UpsConst.UPS_TYPE_CUSTOM;

            compareCounter = 0;
            try {
                env.Create("ntest.db");
                db = env.CreateDatabase(1, 0, param);
                db.SetCompareFunc(new CompareFunc(MyCompareFunc));
                db.Insert(k, r);
                k[0] = 1;
                db.Insert(k, r);
                db.Close();
                env.Close();
            }
            catch (DatabaseException e) {
                Assert.Fail("unexpected exception " + e);
            }
            Assert.AreEqual(1, compareCounter);
        }
All Usage Examples Of Upscaledb.Database::SetCompareFunc