我有一个用例,我需要对来自多个文件的数百万条记录进行模糊匹配.我确定了两种算法:Jaro-Winkler和Levenshtein编辑距离.
当我开始探索两者时,我无法理解两者之间的确切差异.似乎Levenshtein给出了两个字符串之间的编辑数量,而Jaro-Winkler给出了0.0到1.0之间的匹配分数.我不明白算法.由于我需要使用任何一种算法,我需要知道算法性能的确切差异.
string[] strArray = new string[10] { "21.65", "30.90", "20.42", "10.00", "14.87", "72.19", "36.00", "45.11", "18.66", "22.22" };
float temp = 0.0f;
Int32 resConvert = 0;
Int32 resCast = 0;
for (int i = 0; i < strArray.Length; i++)
{
float.TryParse(strArray[i], out temp);
resConvert = Convert.ToInt32(temp * 100);
resCast = (Int32)(temp * 100);
Console.WriteLine("Convert: " + resConvert + " ExplCast: " + resCast);
}
Run Code Online (Sandbox Code Playgroud)
答案:
Convert: 2165 ExplCast: 2164 // ??
Convert: 3090 ExplCast: 3089 // ??
Convert: 2042 ExplCast: 2042 …Run Code Online (Sandbox Code Playgroud) 使用Reflector或DotPeek,等于运算符重载的System.Linq.Data.Binary实现如下所示:
[Serializable, DataContract]
public sealed class Binary : IEquatable<Binary>
{
...
public static bool operator ==(Binary binary1, Binary binary2)
{
return ((binary1 == binary2) || (((binary1 == null) && (binary2 == null)) || (((binary1 != null) && (binary2 != null)) && binary1.EqualsTo(binary2))));
}
Run Code Online (Sandbox Code Playgroud)
我必须遗漏一些明显的东西,或者有一种我不知道的机制(例如在体内隐式调用object ==?).我承认,我很少需要重载标准运算符.
为什么这个实现不会导致无限递归(一个简单的测试显示它无法无限递归)?第一个条件表达式是binary1 == binary2,在运算符重载的实现中,如果你在实现之外使用了binary1 == binary2,那么它会被调用,我也会想到.
根据维基百科:"通常不可能确定最确切的最坏情况.相反,情景被认为至少与最坏情况一样糟糕".我不明白那一部分.搜索列表中的数字是否是最后一个索引时的最坏情况?这不是最坏的情况吗?
这可能是一个愚蠢的问题.但是,当我从Live SDK示例修改一个示例时,遇到了一个奇怪的问题.
我在想根本原因是异步函数GetAll()是同步使用的.
下面是代码片段,我把问题作为评论.提前致谢!
class SkyeDriveViewModel: INotifyPropertyChanged
{
private List<SkyDriveItem> folderList = null;
public List<SkyDriveItem> FolderList
{
get { return folderList; }
private set
{
if (value != folderList)
{
folderList = value;
NotifyPropertyChanged("FolderList");
}
}
}
private async void GetAll(string desiredPath)
{
FolderList = new List<SkyDriveItem>();
this.liveClient = new LiveConnectClient(SkyDrivePage.Session);
try
{
LiveOperationResult operationResult = await this.liveClient.GetAsync(desiredPath);
dynamic result = operationResult.Result;
dynamic items = result.data;
foreach (dynamic item in items)
{
SkyDriveItem newItem = new SkyDriveItem(item);
if (newItem.IsFolder)
{ …Run Code Online (Sandbox Code Playgroud) 我正在开发一个在隐藏模式下调用.net控制台应用程序的Delphi应用程序,但问题是:当我关闭我的delphi应用程序时,控制台应用程序也会关闭,即使使用ShellExecute而没有指定等待SingleObject.
我尝试了同样的Shell调用Windows Calc,所以现在即使我关闭我的应用程序,Calc仍然打开,这是我正在寻找的行为.
有人知道是否可以调用控制台应用程序并使其独立于父进程以及如何执行此操作,因此在主应用程序关闭时它不会关闭?
c# ×4
algorithm ×2
.net ×1
analysis ×1
asynchronous ×1
average ×1
delphi ×1
int ×1
jaro-winkler ×1
performance ×1
sync ×1