Re: Can anyone suggest
- Posted by "Derek Parnell" <ddparnell at bigpond.com> Feb 13, 2004
- 491 views
----- Original Message ----- From: "I Mullins" <eugtk at yahoo.com> To: <EUforum at topica.com> Subject: Can anyone suggest > > > What sort of algoritm could be used to duplicate the following > behavior: > > Using a database of > 100,000 names and addresses, etc., we can type > into a search field 'MARK', for example, and get back a list of all > names which contain 'MARK': > > Mark Adams > Adam Markham > Jance Marks > Jane Marklin Dobbs > Markie Mark > ... > > Currently, we are using FileMaker Pro, and it returns such searches > in a fraction of a second. Is it possible to come up with something > in Euphoria which could do the same in some reasonable amount of time, > say 1 or 2 seconds? > This drop-dead-simple appraoch takes about 1.1 seconds over 200,000 records on my machine... It is run typing "ex qtest.ex -b -f MARK" where the -b means build a sample database, and -f means search for the next string. --------- include file.e include wildcard.e constant vCommandLine = command_line() constant Letters = "ABCDEFGHJKLMNOPQRSTVWXYZ" function RandWord() sequence lWord lWord = repeat(0, rand(12) + 3) for i = 1 to length(lWord) do lWord[i] = Letters[rand(length(Letters))] end for return lWord end function procedure BuildDB() -- Build test database! integer fh puts(1, "Building database...") fh = open("testdb.txt","w") for i = 1 to 200000 do printf(fh, "%s %s%d%s %s %s\n", {RandWord(), RandWord(),0,RandWord(),RandWord(),RandWord()}) end for close(fh) puts(1, "COMPLETED\n") end procedure procedure FindAll(sequence lWord) integer lCnt atom lDurn integer fh object lLine lDurn = time() lCnt = 0 printf(1, "Search for '%s' started...\n", {lWord}) fh = open("testdb.txt", "r") lLine = gets(fh) while sequence(lLine) do if match(lWord, lLine) then lCnt += 1 end if lLine = gets(fh) end while close(fh) lDurn = time() - lDurn printf(1, "%d found in %g seconds\n", {lCnt, lDurn}) end procedure procedure Main() integer lPos sequence lFind if match({"-b"}, vCommandLine) then BuildDB() end if lPos = match({"-f"}, vCommandLine) if lPos > 0 then lFind = vCommandLine[lPos+1] FindAll(lFind) end if end procedure Main() --------- Derek