From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: chen bin Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] add 'string-distance' to calculate Levenshtein distance Date: Fri, 20 Apr 2018 14:37:26 +1000 Message-ID: References: <87vacuecrn.fsf@gmail.com> <83po3246ah.fsf@gnu.org> <87lgdq831h.fsf@gmail.com> <83muy553ae.fsf@gnu.org> <87o9ilhhcd.fsf@gmail.com> <83d0z14sws.fsf@gnu.org> <87o9il0wka.fsf@gmail.com> <83bmek4jdn.fsf@gnu.org> <83k1t72b2o.fsf@gnu.org> <83bmei36dw.fsf@gnu.org> <83wox3zkm7.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1524198967 28281 195.159.176.226 (20 Apr 2018 04:36:07 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 20 Apr 2018 04:36:07 +0000 (UTC) Cc: emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Apr 20 06:36:03 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1f9NmF-0007Gn-48 for ged-emacs-devel@m.gmane.org; Fri, 20 Apr 2018 06:36:03 +0200 Original-Received: from localhost ([::1]:50656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9NoL-0002oJ-Ji for ged-emacs-devel@m.gmane.org; Fri, 20 Apr 2018 00:38:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51716) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f9Nnf-0002no-Gp for emacs-devel@gnu.org; Fri, 20 Apr 2018 00:37:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f9Nne-0002Vg-Aj for emacs-devel@gnu.org; Fri, 20 Apr 2018 00:37:31 -0400 Original-Received: from mail-lf0-x22d.google.com ([2a00:1450:4010:c07::22d]:35244) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1f9Nnc-0002RH-FF; Fri, 20 Apr 2018 00:37:28 -0400 Original-Received: by mail-lf0-x22d.google.com with SMTP id r125-v6so3251289lfe.2; Thu, 19 Apr 2018 21:37:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=qi/wX6uEjhaGBp2O7bELVhtxufmp0lQQ3s5QwJglG38=; b=PoUYC5FwR89ElsGn7zADI2J/kfpSUwr124qlyI6Z8JIs9w+1h7idXqtVSodFeGupJ3 DMKdfG/oRRIkTXc/o6mvAcfK7m0D0YQ4nQ6Gj7KLUn6DMGm06HdyWKc6Zpn2Id/UfmT5 7nHa6jF50pI4y0G59GHgkAfDQV0PXwbbmQlreYejbpqLeUVuIRS3uojK08qjQMJ7fDbJ ALjJB/1Ww9cvv4XASVBDfrhTrth/4LTvGCs8MBxbBzCeczyrTA1ighHBmjcNk8CPIlEf eam0rp/rwNW9kz9UxnSIJdcKQib2cAecEybRW/MAMP8YoSqlAixtecMcBCt5A8hVAnVK AWLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=qi/wX6uEjhaGBp2O7bELVhtxufmp0lQQ3s5QwJglG38=; b=ibI7xK/7IZ1cggv2GnvRSHhDujzebP8UAuoT8IP/js2+ZJPM2lDAGF1y9ZyCDzBo97 3J0D4rGX1DWe+Zt5VgbKxBLq1pOA5sibQC6S+Ka/AICeGgFPgr1gUrK+s5Xvo4wbXfDp i2ALJoFWbAXhT20bnAz/W1v31LdJJDdBj7PIMyMN8GDDq9wU8jrVW9ZTHSyQM55wBkNt Llpe3XwYHN4t6c+RKcgx4eNbO4712ZJUy8ZLglm5WqgJAhzcGnDcauDtWwjACPmbpClW Jye1AbUTS4GYTm+p8rhPRQ0Hy3aLW2zE4O4vaTU7kqCbptjYtVgawfyEkeSJKbyTFkFR 9Bnw== X-Gm-Message-State: ALQs6tCZtMER46ElVBo7bSM+4lQLcchyqXEG1MfkpDUk02/Le2EXHRJZ KoHxCpmSJsnYAXuHzIECFxqHgL6QnrZqIoujprs= X-Google-Smtp-Source: AIpwx4+rFE+HPv92hv3VJqNlyQSQbfDQkeLVr5ARd4BIFcO5GhU8qKd6WiaezPxqL3D7ghoFbdOmVDl3Aw/ei28kjaQ= X-Received: by 10.46.83.14 with SMTP id h14mr2814815ljb.108.1524199046747; Thu, 19 Apr 2018 21:37:26 -0700 (PDT) Original-Received: by 10.46.20.93 with HTTP; Thu, 19 Apr 2018 21:37:26 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4010:c07::22d X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:224732 Archived-At: Please hold on, I will send you a new patch tonight. On Fri, Apr 20, 2018 at 12:55 AM, chen bin wrote: > Hi, Eli, > I attached the new patch. > > A software project usually contains nomal directory and file names. > Linux kernel source, for example. > > My package `counsel-etags` will use byte compare version. > > Regards, > Chen > > On Thu, Apr 19, 2018 at 6:05 PM, Eli Zaretskii wrote: >>> From: chen bin >>> Date: Tue, 17 Apr 2018 22:31:20 +1000 >>> Cc: emacs-devel@gnu.org >>> >>> As you suggested, I re-write the code using 'FETCH_STRING_CHAR_ADVANCE'. >> >> Thanks. >> >>> I also implemented the byte comparing version. It's 4 times as fast. And I do >>> need use it to compare file path in my package 'counsel-etags'. >> >> File names are just strings for this purpose, and they can potentially >> include any non-zero characters. So I don't see why they are special. >> >>> The fille path couldn't contain any funny characters (emoji). so >>> it'sperfectly fine >>> to use byte comparing version. >> >> File names can very well include emoji and other "funny" characters, >> Emacs supports that on all modern systems (including even MS-Windows). >> >>> diff --git a/etc/NEWS b/etc/NEWS >>> index 5aa92e2991..3cce2c48c7 100644 >>> --- a/etc/NEWS >>> +++ b/etc/NEWS >>> @@ -490,6 +490,8 @@ x-lost-selection-hooks, x-sent-selection-hooks >>> +++ >>> ** New function assoc-delete-all. >>> >>> +** New function string-distance to calculate Levenshtein distance between two strings. >> >> This long line should be filled using the fill-column setting we use >> in NEWS. Even better, make the header a short summary, like >> >> ** New function 'string-distance' >> >> and then describe its functionality in a separate sentence that starts >> immediately below that header. >> >>> +DEFUN ("string-distance", Fstring_distance, Sstring_distance, 2, 3, 0, >>> + doc: /* Return Levenshtein distance between STRING1 and STRING2. >>> +If BYTECOMPARE is nil, we compare character of strings. >>> +If BYTECOMPARE is t, we compare byte of strings. >> >> Please lose the "we" part, it's inappropriate in documentation, >> because it describes what Emacs does. >> >>> +Comparing by byte is faster and non-ascii characters has weighted distance. >> >> I would delete this sentence, it is IMO confusing more than anything >> else. (And I still think the bytewise comparison is not needed.) >> >>> + bool use_bytecompare = !NILP(bytecompare); >> ^^ >> Space between these 2 characters. >> >>> + else >>> + { >>> + int c1, c2; >>> + ptrdiff_t i1, i1_byte, i2, i2_byte; >>> + i2 = i2_byte = 0; >>> + for (x = 1; x <= len2; x++) >> >> Please move the initialization of i2 and i2_byte into the for-loop >> initializer (suing the comma operator). >> >>> + i1 = i1_byte = 0; >>> + for (y = 1, lastdiag = x - 1; y <= len1; y++) >> >> Likewise here with i1 and i1_byte. >> >> Thanks. > > > > -- > help me, help you. -- help me, help you.