File: KeyNoteTokenFreqPerFileTableImpl.mesa
Copyright Ó 1985, 1987 by Xerox Corporation. All rights reserved.
Jack Kent January 14, 1988 5:12:04 pm PST
Contents: Implementation of KeyNoteTokenFreqPerFileTable
DIRECTORY
RedBlackTree,
Rope,
KeyNoteTokenFreqPerFileTable;
KeyNoteTokenFreqPerFileTableImpl: CEDAR PROGRAM
IMPORTS RedBlackTree, Rope
EXPORTS KeyNoteTokenFreqPerFileTable = {
ROPE: TYPE = Rope.ROPE;
types
Compare: RedBlackTree.Compare = {
RETURN [ Rope.Compare[s1: NARROW[k, ROPE], s2: NARROW[data, KeyNoteTokenFreqPerFileTable.UserData].token, case: FALSE]];
};
GetKey: RedBlackTree.GetKey = {
RETURN [NARROW[data, KeyNoteTokenFreqPerFileTable.UserData].token];
};
procedures
Create: PUBLIC PROCEDURE [] RETURNS [table: KeyNoteTokenFreqPerFileTable.Table] = {
table ← RedBlackTree.Create[getKey: GetKey, compare: Compare]
};
DestroyTable: PUBLIC PROCEDURE [table: KeyNoteTokenFreqPerFileTable.Table] = {
RedBlackTree.DestroyTable[self: table];
};
InsertAndBumpFrequncy: PUBLIC PROCEDURE [table: KeyNoteTokenFreqPerFileTable.Table, tokenName: ROPE] = {
node: KeyNoteTokenFreqPerFileTable.Node ← RedBlackTree.LookupNode[self: table, lookupKey: tokenName];
if node not nil then must create it.
IF node=NIL THEN {
dataToInsert: KeyNoteTokenFreqPerFileTable.UserData ← NEW[KeyNoteTokenFreqPerFileTable.UserDataObject ← [token: tokenName, frequency: 1]];
RedBlackTree.Insert[self: table, dataToInsert: dataToInsert, insertKey: tokenName]
}
ELSE {
WITH node.data SELECT FROM
n: KeyNoteTokenFreqPerFileTable.UserData => {
n.frequency ← n.frequency +1;
};
ENDCASE => NULL;
}
};
EnumerateDecreasing: PUBLIC PROCEDURE [table: KeyNoteTokenFreqPerFileTable.Table, procToApply: KeyNoteTokenFreqPerFileTable.EachNode] = {
RedBlackTree.EnumerateDecreasing[self: table, procToApply: procToApply];
};
LookupNextLarger: PUBLIC PROC [self: KeyNoteTokenFreqPerFileTable.Table, tokenName: ROPE] RETURNS [data: KeyNoteTokenFreqPerFileTable.UserData] = {
data ← NARROW[RedBlackTree.LookupNextLarger[self: self, lookupKey: tokenName]];
};
Lookup: PUBLIC PROC [self: KeyNoteTokenFreqPerFileTable.Table, tokenName: ROPE] RETURNS [data: KeyNoteTokenFreqPerFileTable.UserData] = {
data ← NARROW[RedBlackTree.Lookup[self: self, lookupKey: tokenName]];
};
}.