


## picklehash.pkg
# Compiled by:
# src/lib/compiler/front/basics/basics.sublib# We use pickle hashes to provide portable, abstract,
# filesystem-independent identifiers for pickles
# (compiled files).
#
stipulate
package err = error_message; # error_message is from src/lib/compiler/front/basics/errormsg/error-message.pkg package ns = number_string; # number_string is from src/lib/std/src/number-string.pkgherein
package picklehash
: Picklehash # Picklehash is from src/lib/compiler/front/basics/map/picklehash.api {
Picklehash = PICKLEHASH vector_of_one_byte_unts::Vector; # vector_of_one_byte_unts is from src/lib/std/src/vector-of-one-byte-unts.pkg pickle_hash_size = 16;
fun compare (PICKLEHASH v1, PICKLEHASH v2)
=
string::compare
(
byte::bytes_to_string v1,
byte::bytes_to_string v2
);
# string is from src/lib/std/string.pkg fun to_bytes (PICKLEHASH x)
=
x;
fun from_bytes v
=
if (vector_of_one_byte_unts::length v == pickle_hash_size)
PICKLEHASH v;
else err::impossible "picklehash::stringToStamp";
fi;
# Convert the Picklehash to a printable representation (hex digits)
fun to_hex (PICKLEHASH pid)
=
{ fun cvt_byte b
=
ns::pad_left '0' 2 (one_byte_unt::to_string b);
fun f (b, l)
=
cvt_byte b ! l;
string::cat (vector_of_one_byte_unts::fold_right f [] pid);
};
fun from_hex s
=
{ fun onebyte i
=
{ i2 = 2 * i;
c1 = string::get (s, i2);
c2 = string::get (s, i2 + 1);
the (one_byte_unt::from_string (implode [c1, c2]));
};
THE (PICKLEHASH (vector_of_one_byte_unts::tabulate (pickle_hash_size, onebyte)));
}
except _
=
NULL;
};
end;
## Copyright (c) 2004 by The Fellowship of SML/NJ
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2012,
## released under Gnu Public Licence version 3.


