SetCompareFunc() public method

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
return void
Exemplo n.º 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);
        }
Exemplo n.º 2
0
        private Database OpenDatabase(string file)
        {
            List<Parameter> list = new List<Parameter>();

            Parameter param1 = new Parameter();
            param1.name = UpsConst.UPS_PARAM_CACHESIZE;
            param1.value = 768 * 1024 * 1024;
            list.Add(param1);

            Upscaledb.Environment env = new Upscaledb.Environment();
            Database db = new Database();
            env.Open(file, 0, list.ToArray());
            db = env.OpenDatabase(1);
            db.SetCompareFunc(new CompareFunc(NumericalCompareFunc));
            return db;
        }