- contrib/hbct/doc/en/ct.txt
* contrib/hbct/doc/en/ctc.txt
* contrib/hbct/doc/en/strdiff.txt
* contrib/hbct/doc/en/token2.txt
* contrib/hbgt/doc/en/hbgt.txt
* contrib/hbmisc/doc/en/dates2.txt
* contrib/hbmisc/doc/en/ht_class.txt
* contrib/hbmisc/doc/en/ht_str.txt
* contrib/hbnf/doc/en/aavg.txt
* contrib/hbnf/doc/en/acctadj.txt
* contrib/hbnf/doc/en/acctmnth.txt
* contrib/hbnf/doc/en/acctqtr.txt
* contrib/hbnf/doc/en/acctweek.txt
* contrib/hbnf/doc/en/acctyear.txt
* contrib/hbnf/doc/en/adapter.txt
* contrib/hbnf/doc/en/aemaxlen.txt
* contrib/hbnf/doc/en/aeminlen.txt
* contrib/hbnf/doc/en/alt.txt
* contrib/hbnf/doc/en/amedian.txt
* contrib/hbnf/doc/en/anomatch.txt
* contrib/hbnf/doc/en/any2any.txt
* contrib/hbnf/doc/en/aredit.txt
* contrib/hbnf/doc/en/asum.txt
* contrib/hbnf/doc/en/at2.txt
* contrib/hbnf/doc/en/bitclr.txt
* contrib/hbnf/doc/en/byt2bit.txt
* contrib/hbnf/doc/en/byt2hex.txt
* contrib/hbnf/doc/en/calendar.txt
* contrib/hbnf/doc/en/chdir.txt
* contrib/hbnf/doc/en/cint86.txt
* contrib/hbnf/doc/en/clrsel.txt
* contrib/hbnf/doc/en/cntryset.txt
* contrib/hbnf/doc/en/ctrl.txt
* contrib/hbnf/doc/en/d2e.txt
* contrib/hbnf/doc/en/datecnfg.txt
* contrib/hbnf/doc/en/default.txt
* contrib/hbnf/doc/en/dosver.txt
* contrib/hbnf/doc/en/easter.txt
* contrib/hbnf/doc/en/elapmil.txt
* contrib/hbnf/doc/en/elapsed.txt
* contrib/hbnf/doc/en/eltime.txt
* contrib/hbnf/doc/en/findith.txt
* contrib/hbnf/doc/en/firstday.txt
* contrib/hbnf/doc/en/floptst.txt
* contrib/hbnf/doc/en/fttext.txt
* contrib/hbnf/doc/en/getenvrn.txt
* contrib/hbnf/doc/en/hex2dec.txt
* contrib/hbnf/doc/en/iamidle.txt
* contrib/hbnf/doc/en/idle.txt
* contrib/hbnf/doc/en/inp.txt
* contrib/hbnf/doc/en/invclr.txt
* contrib/hbnf/doc/en/isprint.txt
* contrib/hbnf/doc/en/lastday.txt
* contrib/hbnf/doc/en/linked.txt
* contrib/hbnf/doc/en/madd.txt
* contrib/hbnf/doc/en/menu1.txt
* contrib/hbnf/doc/en/menutonf.txt
* contrib/hbnf/doc/en/metaph.txt
* contrib/hbnf/doc/en/miltime.txt
* contrib/hbnf/doc/en/min2dhm.txt
* contrib/hbnf/doc/en/mkdir.txt
* contrib/hbnf/doc/en/month.txt
* contrib/hbnf/doc/en/mouse1.txt
* contrib/hbnf/doc/en/n2color.txt
* contrib/hbnf/doc/en/netpv.txt
* contrib/hbnf/doc/en/nooccur.txt
* contrib/hbnf/doc/en/ntow.txt
* contrib/hbnf/doc/en/nwlstat.txt
* contrib/hbnf/doc/en/nwsem.txt
* contrib/hbnf/doc/en/nwuid.txt
* contrib/hbnf/doc/en/origin.txt
* contrib/hbnf/doc/en/outp.txt
* contrib/hbnf/doc/en/page.txt
* contrib/hbnf/doc/en/peek.txt
* contrib/hbnf/doc/en/pickday.txt
* contrib/hbnf/doc/en/popadder.txt
* contrib/hbnf/doc/en/proper.txt
* contrib/hbnf/doc/en/putkey.txt
* contrib/hbnf/doc/en/qtr.txt
* contrib/hbnf/doc/en/rand1.txt
* contrib/hbnf/doc/en/reboot.txt
* contrib/hbnf/doc/en/rmdir.txt
* contrib/hbnf/doc/en/round.txt
* contrib/hbnf/doc/en/savearr.txt
* contrib/hbnf/doc/en/scancode.txt
* contrib/hbnf/doc/en/setdate.txt
* contrib/hbnf/doc/en/settime.txt
* contrib/hbnf/doc/en/shift.txt
* contrib/hbnf/doc/en/sinkey.txt
* contrib/hbnf/doc/en/sleep.txt
* contrib/hbnf/doc/en/sqzn.txt
* contrib/hbnf/doc/en/stod.txt
* contrib/hbnf/doc/en/sysmem.txt
* contrib/hbnf/doc/en/tbwhile.txt
* contrib/hbnf/doc/en/tempfile.txt
* contrib/hbnf/doc/en/vertmenu.txt
* contrib/hbnf/doc/en/vidcur.txt
* contrib/hbnf/doc/en/vidmode.txt
* contrib/hbnf/doc/en/wda.txt
* contrib/hbnf/doc/en/week.txt
* contrib/hbnf/doc/en/year.txt
* contrib/hbziparc/doc/en/hbziparc.txt
* contrib/rddads/doc/en/adsfuncs.txt
* contrib/rddads/doc/en/readme.txt
* doc/en/1stread.txt
* doc/en/array.txt
* doc/en/binnum.txt
* doc/en/browse.txt
* doc/en/command.txt
* doc/en/compiler.txt
* doc/en/datetime.txt
* doc/en/dbdelim.txt
* doc/en/dbsdf.txt
* doc/en/dbstrux.txt
* doc/en/dir.txt
* doc/en/diskspac.txt
* doc/en/errsys.txt
* doc/en/eval.txt
* doc/en/file.txt
* doc/en/garbage.txt
* doc/en/harbext.txt
* doc/en/hashes.txt
* doc/en/hb_set.txt
* doc/en/hbinet.txt
* doc/en/hvm.txt
* doc/en/idle.txt
* doc/en/input.txt
* doc/en/lang.txt
* doc/en/macro.txt
* doc/en/math.txt
* doc/en/memo.txt
* doc/en/memvar.txt
* doc/en/menu.txt
* doc/en/misc.txt
* doc/en/nation.txt
* doc/en/objfunc.txt
* doc/en/rdd.txt
* doc/en/rdddb.txt
* doc/en/rddmisc.txt
* doc/en/rddord.txt
* doc/en/set.txt
* doc/en/setmode.txt
* doc/en/string.txt
* doc/en/tclass.txt
* doc/en/terminal.txt
* doc/en/tgetlist.txt
* doc/en/tlabel.txt
* doc/en/treport.txt
* doc/en/var.txt
* sync with fixes/updates from 3.4 fork
61 lines
3.2 KiB
Plaintext
61 lines
3.2 KiB
Plaintext
/* $DOC$
|
|
$NAME$
|
|
StrDiff()
|
|
$CATEGORY$
|
|
CT3 string functions
|
|
$ONELINER$
|
|
Evaluate the "Edit (Levensthein) Distance" of two strings
|
|
$SYNTAX$
|
|
StrDiff( <cString1>, <cString2>, [<nReplacementPenalty>], [<nDeletionPenalty>],
|
|
[<nInsertionPenalty>] ) -> <nDistance>
|
|
$ARGUMENTS$
|
|
<cString1> string at the "starting point" of the transformation process, default is ""
|
|
<cString2> string at the "end point" of the transformation process, default is ""
|
|
<nReplacementPenalty> penalty points for a replacement of one character, default is 3
|
|
<nDeletionPenalty> penalty points for a deletion of one character, default is 6
|
|
<nInsertionPenalty> penalty points for an insertion of one character, default is 1
|
|
$RETURNS$
|
|
<nDistance> penalty point sum of all operations needed to transform <cString1> to <cString2>
|
|
$DESCRIPTION$
|
|
The StrDiff() functions calculates the so called "Edit" or "Levensthein" distance of two strings.
|
|
This distance is a measure for the number of single character replace/insert/delete operations (so called
|
|
"point mutations") required to transform <cString1> into <cString2> and its value will be the smallest sum of
|
|
the penalty points of the required operations.
|
|
|
|
Be aware that this function is both quite time - O(Len(cString1)*Len(cString2)) - and memory consuming -
|
|
O((Len(cString1)+1)*(Len(cString2)+1)*sizeof(int)) - so keep the strings as short as possible.
|
|
E.g., on common 32-bit systems (sizeof(int) == 4), calling StrDiff() with two strings of 1024 bytes
|
|
in length will consume 4 MiB of memory. To not impose unneeded restrictions, the function will only check if
|
|
(Len(cString1)+1)*(Len(cString2)+1)*sizeof(int) <= UINT_MAX, although allocing UINT_MAX bytes will not
|
|
work on most systems. If this simple check fails, -1 is returned.
|
|
|
|
Also, be aware that there can be an overflow when the penalty points are summed up: Assuming that the
|
|
number of transformation operations is in the order of Max(Len(cString1), Len(cString2)), the penalty point
|
|
sum, that is internally stored in an "int" variable, is in the order of
|
|
(Max(Len(cString1), Len(cString2))*Max(nReplacementPenalty, nDeletionPenalty, nInsertionPentaly).
|
|
The StrDiff() does not do an overflow check due to time performance reasons. Future versions of StrDiff()
|
|
could use a type different to "int" to store the penalty point sum to save memory or to avoid overflows.
|
|
|
|
The function is aware of the settings done by SetAtLike(), that means that the wildchar character
|
|
is considered equal to ALL characters.
|
|
|
|
$EXAMPLES$
|
|
? StrDiff( "ABC", "ADC" ) // 3, one character replaced
|
|
? StrDiff( "ABC", "AEC" ) // 3, dito
|
|
? StrDiff( "CBA", "ABC" ) // 6, two characters replaced
|
|
? StrDiff( "ABC", "AXBC" ) // 1, one character inserted
|
|
? StrDiff( "AXBC", "ABC" ) // 6, one character removed
|
|
? StrDiff( "AXBC", "ADC" ) // 9, one character removed and one replaced
|
|
$STATUS$
|
|
Ready
|
|
$COMPLIANCE$
|
|
StrDiff() is compatible with CT3's StrDiff().
|
|
$PLATFORMS$
|
|
All
|
|
$FILES$
|
|
Library is hbct.
|
|
$SEEALSO$
|
|
SetAtLike()
|
|
$END$
|
|
*/
|