RopeHash.mesa
Copyright (C) 1984, Xerox Corporation. All rights reserved.
Michael Plass, January 18, 1985 12:48:44 pm PST
Russ Atkinson (RRA) January 31, 1985 5:12:06 pm PST
Doug Wyatt, February 22, 1985 11:44:18 am PST
DIRECTORY
Rope USING [ROPE];
RopeHash: CEDAR DEFINITIONS
= BEGIN
ROPE: TYPE = Rope.ROPE;
PureText: TYPE = REF READONLY TEXT;
defaultSeed: CARDINAL = 31415;
FromRefText:
PROC[text: PureText, seed:
CARDINAL ← defaultSeed]
RETURNS[hash:
CARDINAL];
Computes a hash code given a REF TEXT object and an initial seed. Every character contributes to the hash. There is no case option (if one is needed, use FromRope).
FromRope:
PROC[rope:
ROPE, case:
BOOL ←
TRUE, start:
INT ← 0, len:
INT ←
LAST[
INT],
seed:
CARDINAL ← defaultSeed]
RETURNS[hash:
CARDINAL];
Computes a hash code given a range of characters in a rope, a case indicator, and an initial seed. Every character contributes to the hash. If case, then case of characters matters, otherwise upper case and lower case characters hash to the same value (case = TRUE is faster). A BoundsFault is raised if start NOT IN [0..Rope.Length[rope]]. The hash returned will be the initialSeed if Length[rope] <= 0.
END.