PROCEDURE Insert(db: Database;
address: Addresses.Address) : BOOLEAN;
(* insert address into db (if it is acceptable,
otherwise RETURN FALSE) by storing it into
db.hashByName (accessible by the primary key) and to
db.hashByPhone and hashByEmail if these fields are
non-empty and these keys are not yet used
*)
BEGIN
IF Hashes.Acceptable(db.hashByName, address) THEN
Hashes.Insert(db.hashByName, address);
IF (address.phone # "") &
Hashes.Acceptable(db.hashByPhone, address) THEN
Hashes.Insert(db.hashByPhone, address);
END;
IF (address.email # "") &
Hashes.Acceptable(db.hashByEmail, address) THEN
Hashes.Insert(db.hashByEmail, address);
END;
RETURN TRUE
ELSE
RETURN FALSE
END;
END Insert;
|