source: trunk/src/adlib.erl @ 90

Revision 90, 1.1 KB checked in by dom, 3 years ago (diff)

Removed all bootstrapping code and the directory_tester is now run during install to test itself. Removed obsolete files.

Line 
1%%% Copyright (C) Dominic Williams
2%%% All rights reserved.
3%%% See file COPYING.
4
5-module (adlib).
6-export ([compare_dict/2]).
7
8compare_dict (Modified, Original) ->
9    Init_fun = fun (Key, Dict) -> dict: store (Key, dict: new (), Dict) end,
10    Init = lists: foldl (Init_fun, dict: new (), [lost, changed, same]),
11    {Intermediate, New} = dict: fold (fun compare_dict/3, {Init, Modified}, Original),
12    dict: store (new, New, Intermediate).
13
14compare_dict (Key, Value, {Result, Modified}) ->
15    compare_dict (dict: find (Key, Modified), Key, Value, Result, Modified).
16
17compare_dict (error, Key, Value, Result, Modified) ->
18    Lost = dict: store (Key, Value, dict: fetch (lost, Result)),
19    {dict: store (lost, Lost, Result), Modified};
20compare_dict ({ok, Value}, Key, Value, Result, Modified) ->
21    Same = dict: store (Key, Value, dict: fetch (same, Result)),
22    {dict: store (same, Same, Result), dict: erase (Key, Modified)};
23compare_dict ({ok, New_value}, Key, Value, Result, Modified) ->
24    Changed = dict: store (Key, {New_value, Value}, dict: fetch (changed, Result)),
25    {dict: store (changed, Changed, Result), dict: erase (Key, Modified)}.
Note: See TracBrowser for help on using the repository browser.