1
%%%----------------------------------------------------------------------
2
%%% File : hipe_adj_set.erl
3
%%% Author : Andreas Wallin <d96awa@ida.dis.uu.se>
4
%%% Purpose : Used to represent nodes that are connected with edges.
5
%%% This is a much faster way to check if to nodes are
6
%%% connected than checking with the adj_list
8
%%% Created : 03 Feb 2000 by Andreas Wallin <d96awa@ida.dis.uu.se>
9
%%%----------------------------------------------------------------------
11
-module(hipe_adj_set).
12
-author("Andreas Wallin").
21
%%%----------------------------------------------------------------------
24
% Description: Creates a new adj_set data structure. It is used to
25
% represent all edges that are connected in an
32
% A new adj_set data structure.
33
%%%----------------------------------------------------------------------
37
%%%----------------------------------------------------------------------
40
% Description: Adds a new edge between U and V
45
% Set -- An adj_set data-structure
48
% An updated adj_set data structure
49
%%%----------------------------------------------------------------------
50
add_edge(U, U, Set) -> Set;
51
add_edge(U, V, Set) ->
52
case adjacent(U, V, Set) of
53
true -> Set; % Ok, do nothing. It was already in set
54
false -> Set1 = hipe_hash:insert({U, V}, interfere, Set),
55
hipe_hash:insert({V, U}, interfere, Set1);
56
_ -> error_logger:error_msg("[~w:add_edge] Could not happen situation",[?MODULE])
59
%%%----------------------------------------------------------------------
62
% Description: Adds edges between the node From to a number of other
66
% From -- A node that you which to connect to a number of
68
% [T|Ts] -- A list of nodes that you which to connect with
70
% Set -- An adj_set datastructure
73
% An updated adj_set data structure
74
%%%----------------------------------------------------------------------
75
add_edges(_, [], Set) -> Set;
76
add_edges(From, [T|Ts], Set) ->
77
add_edges(From, Ts, add_edge(From, T, Set)).
79
%%%----------------------------------------------------------------------
80
% Function: remove_edge
82
% Description: Removes the edge between U and V
87
% Set -- An adj_set datastructure
90
% If the edge exists -- An updated adj_set data structure
91
% Otherwise -- Throws an exception
92
%%%----------------------------------------------------------------------
93
remove_edge(U, U, Set) -> Set;
94
remove_edge(U, V, Set) ->
95
case adjacent(U, V, Set) of
96
true -> Set1 = hipe_hash:delete({U, V}, Set),
97
hipe_hash:delete({V, U}, Set1);
98
false -> throw({adj_set, remove_directed_edge, "Edge does not exist"})
102
%%%----------------------------------------------------------------------
103
% Function: remove_edges
105
% Description: Removes edges between the node From and a number of other
109
% From -- A node that you which to remove edges to from
110
% [T|Ts] -- A list of nodes that you don't want to have an
111
% edge to the From node any more.
112
% Set -- An adj_set datastructure
115
% If all edges exists -- An updated adj_set data structure
116
% Otherwise -- Throws an exception
117
%%%----------------------------------------------------------------------
118
remove_edges(_, [], Set) -> Set;
119
remove_edges(From, [T|Ts], Set) ->
120
remove_edges(From, Ts, remove_edge(From, T, Set)).
123
%%%----------------------------------------------------------------------
126
% Description: Tells if an edge exists between U and V
131
% Set -- An adj_set datastructure
134
% true -- If there exists an edge between U and V
136
%%%----------------------------------------------------------------------
137
adjacent(U, V, Set) ->
138
case hipe_hash:lookup({U, V}, Set) of
141
_ -> exit({adj_set, adjacent, "Could not happend"})