【问题标题】:Volante c# database engine: How we can binary search (or lookup) in Volante index?Volante c# 数据库引擎:我们如何在 Volante 索引中进行二进制搜索(或查找)?
【发布时间】:2014-09-03 06:46:18
【问题描述】:

我将尝试在我的私人项目中使用 C# Volante 数据库引擎。但提供的示例(DirectoryScan)仅关于从开始或从结束读取整个索引。我需要先找到例如其他事件,例如。 g.:

// c# pseudocode
result = index.GetFirst("lookingforThisString")
while(result != null) {
    doProcess(result);
    result = index.GetNext();
}

有更多关于使用这个引擎和索引的例子吗?

【问题讨论】:

    标签: c# indexing


    【解决方案1】:

    非唯一索引可以使用范围参数将值数组返回给 Get(from, till) 命令。

    这是一个简单的例子:

    class MyPersistentClass : Persistent
    {
        public string Text { get; set; }
    }
    
    // Create the index. Must be non-unique to support duplicate keys
    dbRoot.MyIndex = db.CreateIndex<string, MyPersistentClass>(IndexType.NonUnique);
    
    // Put the data
    dbRoot.MyIndex.Put("my string", new MyPersistentClass { Text="some value" });
    dbRoot.MyIndex.Put("my string", new MyPersistentClass { Text="another value" });
    
    // query the index to get multiple values. The range from and till values are the same
    MyPersistentClass[] values = dbRoot.MyIndex.Get("my string", "my string");
    
    // process the first occurrence
    if (values.Length > 0)
    {
       DoProcess(values[0]);
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-03
      • 2014-04-14
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 2012-01-29
      • 1970-01-01
      • 2017-07-23
      相关资源
      最近更新 更多