Arde Enchanter
Joined: 09 Sep 2007 Posts: 605
|
Posted: Wed Mar 11, 2009 7:31 pm
Patricia Tree package v1.1 |
-Version 1.1 is out with major fix in the regex generating function
-------------
I've uploaded my patricia tree package (Arde's Patricia Tree) into the library. Hope it works
Currently it only returns regexes surrounded with word boundary \b characters (\bregex\b), may be I'll add returning of "pure" regex later.
===================================================
Benchmarks:
pat_runLocalBenchmark - run a benchmark with embedded variable (database record variable with 1892 entries) (thanks, shalimar! )
pat_runBenchmark - run a benchmark with your variable
Until CMUD 3.05 or whenever %vartype get fixed to accept string parameter type, take the following steps:
1) Create variable that will hold regex pattern instead of your stringlist or database record variable.
#VAR varname
2) Generate patricia tree, supplying the full name of your stringlist or database record variable as a parameter.
2a) For a stringlist:
....Manually: #FORALL @stringlist {pat_addKey %i}
....Automatically: pat_newFromStringlist "//Module/Class/Variable"
2b) For a database record:
....Manually for keys: #FORALL %dbkeys(@dbrecord) {pat_addKey %i}
....Manually for values: #FORALL %dbvalues(@dbrecord) {pat_addKey %i}
....Automatically for keys: pat_newFromDBRecord "//Module/Class/Variable" 1
....Automatically for values: pat_newFromDBRecord "//Module/Class/Variable" 2
3) Get the regex.
varname = @pat_getRegEx()
Regex will be generated automatically in the form \bexpression\b
4) If you want to gain more control over the tree, use other settings:
pat_deleteTree - deletes a tree
pat_newTree - creates a new empty tree
pat_addKey - adds 1 string key to a tree
pat_viewTree - prints a tree on the screen
pat_buildRegEx - generates and stores regular expression in a tree
pat_viewRegEx - prints regular expression on the screen
5) Having more than 1 patricia tree.
You can specify numeric tree ID when calling settings from this package. By default, Patricia Tree package will use treeID==1 (default temporary tree). Trees with ID other than 1 will not get erased until you explicitly call`pat_deleteTree or pat_newTree (instance persistent tree).
You can use any positive number as tree identifier.
Example: pat_newFromDBRecord "//Module/Class/Variable" 1 12 will create patricia tree with ID = 12
User reference
==============
alias pat_newFromDBRecord strVarName dataSource treeID
alias pat_newFromStringlist strVarName treeID
alias pat_deleteTree treeID
alias pat_newTree treeID
alias pat_addKey strKey treeID
alias pat_viewTree treeID
alias pat_buildRegEx treeID
alias pat_viewRegEx treeID
function literal string @pat_getRegEx(treeID)
Additional functions available in this package:
===============================================
function integer @sharedChars(str1 str2) - counts number of shared characters (not case sensitive)
function int(0..1) @touch(varName) - checks if specified variable exist in a package
Stack class - for your Lua scripts
Usage:
Code: |
#PRINT @sharedChars("apE", "Apple")
|
Output:
2
Code: |
#IF (@touch("//untitled/testClass/myVar")
{
#PRINT "Found"
}
{
#PRINT "Not found"
}
|
Code: |
stack = Stack:new()
stack:push(65, 34)
stack:push(5)
stack:push("hrm", "hello", "test", 12)
print(stack:pop())
print(stack:pop())
print(stack:pop())
|
Output:
hrm hello test 12
5
65 34 |
|