标签: search

查找元素是否存在于未排序数组中的最快方法?

是搜索未排序数组以进行元素线性搜索的最快算法吗?我的意思是我猜合并排序 + 二进制搜索的组合会更慢。还有其他选择吗?(在不涉及多线程的算法方面)?

arrays sorting algorithm search

-1
推荐指数
1
解决办法
4772
查看次数

通过订单ID获取订单详情

我需要通过 Magento 检索订单id
如何加载特定订单id

search magento magento-1.9

-1
推荐指数
1
解决办法
8244
查看次数

波束搜索的时间复杂度和空间复杂度

我正在研究使用 Trie 进行重复数据删除。在 Trie 中,存储算法的哈希值(例如-SHA1)并通过波束搜索(例如波束宽度 n=2)完成查找。现在我的问题是波束搜索的时间和空间复杂度是多少,以及我应该根据什么因素使用启发式函数来选择节点。由于我是所有这些主题的基本学习者,请为我的疑问提供您的解决方案。

提前致谢。

algorithm search duplicates

-1
推荐指数
1
解决办法
2582
查看次数

如何在Python中前后跟空格的文件中搜索单词?

我想逐行搜索一个特定单词的文件,但我想确保这个特定的单词前面跟着一个空格.

我知道我必须使用正则表达式来做到这一点.我一直在阅读这本指南,但令我感到困惑的是如何在同一个声明中同时应用前瞻和后瞻.

我怎样才能做到这一点?

counter = 0
out = open('out.txt', 'w')
with open(original_db, 'r') as db:
    for line in db:
        if re.search(word, line, re.IGNORECASE):
            counter += 1
            out.write(line)
print("Entries found for word: " + str(counter))
Run Code Online (Sandbox Code Playgroud)

python regex search python-3.x

-1
推荐指数
1
解决办法
67
查看次数

在代码中使Lucene.Net线程安全

我正在使用Lucene.Net进行搜索,并想知道如何处理这个线程问题.

我有一个类Test的实例,但搜索器在这种情况下不是线程安全的,因为定时器线程可以在提供请求的同时更新索引,并且我确实看到了异常.关于如何使其线程安全的任何指针.

public class Test 
{
    private static object syncObj = new object();

    private System.Threading.Timer timer;

    private Searcher searcher;

    private RAMDirectory idx = new RAMDirectory();

    public Test()
    {
        this.timer = new System.Threading.Timer(this.Timer_Elapsed, null, TimeSpan.Zero, TimeSpan.FromMinutes(3));
    }


    private Searcher ESearcher
    {
        get
        {
            return this.searcher;
        }

        set
        {
            lock (syncObj)
            {
                this.searcher = value;
            }
        }
    }

    public Document CreateDocument(string title, string content)
    {
        Document doc = new Document();
        doc.Add(new Field("A", title, Field.Store.YES, Field.Index.NO));
        doc.Add(new Field("B", content, Field.Store.YES, Field.Index.ANALYZED));
        return doc; …
Run Code Online (Sandbox Code Playgroud)

c# search multithreading lucene.net

-1
推荐指数
1
解决办法
918
查看次数

了解神秘工作的递归二进制搜索算法

在赋值时,我必须使用递归二进制搜索算法输出索引而不是True/False而不修改参数.我度过了一段非常艰难的时期,但在诉诸半试错之后,我偶然发现了这个烂摊子:

#include <iostream>
#include <math.h>
#include <climits>

using namespace std;


int BinarySearch(int arr[], int len, int target) {

    int temp = 0;
    int mid = len/2;

    if (len <= 0) return INT_MIN;  // not found
    if (target == arr[mid]){
        return mid; // found
    }

    if (target < arr[mid]){
        temp = BinarySearch(arr, mid, target);
    }

    else {
        temp = mid+1 + BinarySearch(arr+mid+1, len-mid-1, target);              
    }
}
Run Code Online (Sandbox Code Playgroud)

即使在通过可视化工具运行之后,我也完全不知道它为什么会起作用.它对更改的代码非常敏感,当它无法找到目标时我无法输出-1,所以我至少总是输出一个负数.

我真的不需要它固定,我只是想知道它是如何工作的,因为看起来甚至没有使用递归调用的输出.谢谢.

c++ algorithm search binary-search c++11

-1
推荐指数
1
解决办法
127
查看次数

搜索机制包括整个单词

我创建了一个搜索机制,搜索字符串数组以获得精确的字符串匹配,但我希望它更直观一些.

我也可以让它在字符串中搜索一个字符串(例如chickengrilled chicken- 但问题是这允许用户键入kenill返回grilled chicken.

如果我输入chicken或者我希望它返回grilled.

有没有人对如何拥有更直观的搜索机制有任何建议?

编辑:

键入1个单词时,下面的正确答案有效,它会搜索字符串中的所有单个单词.但是,当你用2个单词搜索时,我意识到它失败了(因为它只搜索每个字符串单词).

我通过添加|| search == stringif包括不仅单独的单词匹配而是整个字符串匹配来解决这个问题.

但是我仍然遇到问题,要么搜索:

整个字符串匹配或匹配单个单词.

这意味着当search = green cup和时它失败了string = big green cup.有没有办法通过剪切集合来搜索内部?也许类似于:

string.split(' ')但也要包括big green, green cup阵列呢?

javascript arrays string search node.js

-1
推荐指数
1
解决办法
75
查看次数

分页库过滤器/搜索 PageList&lt;T&gt;

我正在使用 Android 分页库,如下所述:https : //developer.android.com/topic/libraries/architecture/paging.html

但我也有一个 EditText 用于按名称搜索国家/地区。

如何过滤 Paging 库中的结果以仅显示匹配的国家/地区?

public final LiveData> countriesPagedList;

public AllCountriesViewModel(@NonNull Application application) {
    super(application);
    appRepository = new AppRepository(application);


PagedList.Config config = new PagedList.Config.Builder()
        .setEnablePlaceholders(true)
        .setPageSize(30)
        .setInitialLoadSizeHint(10)
        .setPrefetchDistance(50)
        .build();

    countriesPagedList = new LivePagedListBuilder(appRepository.getAllCountries(),config).build();
}
Run Code Online (Sandbox Code Playgroud)

search android android-jetpack android-paging

-1
推荐指数
1
解决办法
3130
查看次数

我正在尝试创建自己的(elem)函数

myElement [] = []
myElement [h] = [h]
myElement (h:t)
| h == myElement t  = True
| otherwise         = False
Run Code Online (Sandbox Code Playgroud)

大家好,我正在努力创建自己的elem函数,因为我不允许在 Haskell 中使用任何预定义的函数来做作业。我敢打赌我的代码实际上不起作用,但我想不出其他方式。

search haskell list

-1
推荐指数
1
解决办法
63
查看次数

如何在c ++中搜索另一个字符串中的字符串?

int main(){
string s1="gandalf";
string s2="dal";
function(s1,s2);
return 0;

}
Run Code Online (Sandbox Code Playgroud)

在函数中,如果字符串s1中有"dal",则返回1. else返回0

c++ string search char

-2
推荐指数
1
解决办法
64
查看次数