erluuid
erluuid is a port driver for the UUID library.
Documentation
--[ Warning ]--
Makefiles are BSD, not GNU.
Debian/Ubuntu -> sudo aptitude install freebsd5-buildutils
then use 'freebsd-make' instead of 'make'
--[ Requirements ]--
Debian -> deb: libossp-uuid-dev
FreeBSD -> port: misc/ossp-uuid
NetBSD -> pkg: FIXME
--[ Compilation ]--
Debian users: remember to use freebsd-make instead of make
~/code/C/erluuid$ make clean && make
===> lib (clean)
rm -f uuid.So uuid_lib.So uuid.so uuid_lib.so uuid.So.tmp uuid_lib.So.tmp
rm -f libuuid.so
erlc *.erl
===> lib (all)
cc -fpic -DPIC -I/usr/local/lib/erlang/usr/include -c uuid.c -o uuid.So
cc -fpic -DPIC -I/usr/local/lib/erlang/usr/include -c uuid_lib.c -o uuid_lib.So
building shared library libuuid.so
--[ Usage ]--
~/code/C/erluuid$ erl
Erlang (BEAM) emulator version 5.4.3 [source] [hipe] [threads:0]
Eshell V5.4.3 (abort with ^G)
% start the library wrapper
> uuid:start().
<0.33.0>
% create a v1 UUID (time and node based)
> uuid:make(v1).
<<142,150,204,86,119,186,17,217,189,232,0,80,186,198,247,101>>
% create another one and assign to a variable,
% then pretty print it
> U=uuid:make(v1).
<<148,114,153,162,119,186,17,217,189,233,0,80,186,198,247,101>>
> uuid:format(U).
["947299a2-77ba-11d9-bde9-0050bac6f765"]
% create a v1 UUID (random multicast mac address based)
> uuid:format(uuid:make(v1, random)).
["8412e660-77bb-11d9-95e0-9fc6273bac6d"]
% create a v3 UUID in different namespaces
% (ns:URL) as an example here
> uuid:format(uuid:make_url("http://labs.biniou.info/")).
["5444363d-a17a-3f19-ae27-88bc15b64e7e"]
% create v4 UUIDs (random)
> uuid:format(uuid:make(v4)).
["b3040412-93f0-4185-8b4f-10d04a88e6de"]
> uuid:format(uuid:make(v4)).
["f06d694b-6c18-4cfb-a03c-1396840eebe7"]
> uuid:format(uuid:make(v4)).
["41ded4f0-2703-4e5b-9129-cb226486291e"]
> uuid:format(uuid:make(v4)).
["1e880f9a-b7fc-4b12-b868-9395823eac18"]
> uuid:format(uuid:make(v4)).
["9d68f278-0619-43ac-80da-f2a860240ad7"]
% run this test:
% ---------------------------------------------
% test() ->
% URL = "http://www.ossp.org/",
% UUID = make_url(URL),
% io:format("~s has URL UUID: ~s~n", [URL, format(UUID)]),
% ok.
> uuid:test().
http://www.ossp.org/ has URL UUID: 02d9e6d5-9467-382e-8f9b-9300a64ac3cd
ok
% run this test:
% ---------------------------------------------
% test2() ->
% [U1, U2] = [uuid:make(v1), uuid:make(v1)],
% io:format("U1: ~s~n", [uuid:export(U1, str)]),
% io:format("U2: ~s~n", [uuid:export(U2, str)]),
% io:format("equal(U1, U2) -> ~p~n", [equal(U1, U2)]),
% io:format("equal(U1, U1) -> ~p~n", [equal(U1, U1)]),
% io:format("smaller(U1, U2) -> ~p~n", [smaller(U1, U2)]),
% io:format("greater(U1, U2) -> ~p~n", [greater(U1, U2)]).
> uuid:test2().
U1: bba010a2-77bc-11d9-8f9c-0050bac6f765
U2: bba0117e-77bc-11d9-8f9d-0050bac6f765
equal(U1, U2) -> false
equal(U1, U1) -> true
smaller(U1, U2) -> true
greater(U1, U2) -> false
ok
% benchmark creation of 100000 v1 UUIDs:
> uuid:bench(100000).
Computing 100000 UUID
done in 1129096 microseconds.
that's 88566.428364 UUID/s
ok
% that's all for the demo
> uuid:stop().
stop
> q().
ok
~/code/C/erluuid$
Changelog
- 20050314: changed return value in stop/0
- 20050314: UUIDs are encoded as binary terms
- 20050227: added uuid:import(UUID)
- 20050218: added uuid:is_uuid(UUID) to check validity
- 20050212: UUIDs are encoded as tuples