Files
harbour-core/harbour/samples/cccppc/prtree.prg
1999-11-09 01:37:27 +00:00

70 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* $Id$
*/
//*******************************************************************
// prtree.prg: A PRTREE oszt ly implement ci¢ja.
// 1999, Csisz r Levente
//*******************************************************************
#include "objgen.ch"
//*******************************************************************
#define _PRTREE_PRG_
// #define _IMPLEMENT_ONEW_
#include "prtree.och"
//*******************************************************************
implement oinit()
super:oinit()
this:nWords:=0
this:tree:={}
return this
//*******************************************************************
static function addTPTree(tPTree,ctId,ctArray,ctI)
local t,i,node
if (len(ctArray)<ctI)
// Itt a vge.
node:={nil,ctId}
if (len(tPTree)==0)
aadd(tPTree,node)
return nil
endif
if (tpTree[1][1]==nil)
// M r van egy termin lisunk ugyanilyen tartalommal.
return "addTPTree: M r van ilyen token a f ban: "+toExprStr(ctArray)
endif
aunget(tPTree,node)
return nil
endif
t:=ctArray[ctI++]
for i:=1 to len(tPTree)
if (tPTree[i][1]==t)
return addTPTree(tPTree[i][2],ctId,ctArray,ctI)
endif
end for
// Hozz  kell venni.
node:={t,{}}
aadd(tPTree,node)
return addTPTree(node[2],ctId,ctArray,ctI)
//*******************************************************************
implement addWord(result,itemArray)
local w
if (nil==(w:=addTPTree(this:tree,result,itemArray,1)))
this:nWords++
endif
return w
//*******************************************************************