mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-13 21:04:00 +00:00
Update the code that throws exceptions.
Estimated hours taken: 0.1 Branches: main library/digraph.m: Update the code that throws exceptions.
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
%---------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
% vim: ft=mercury ts=4 sw=4 et
|
% vim: ft=mercury ts=4 sw=4 et
|
||||||
%---------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
% Copyright (C) 1995-1999,2002-2007, 2010-2011 The University of Melbourne.
|
% Copyright (C) 1995-1999,2002-2007,2010-2012 The University of Melbourne.
|
||||||
% This file may only be copied under the terms of the GNU Library General
|
% This file may only be copied under the terms of the GNU Library General
|
||||||
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
% Public License - see the file COPYING.LIB in the Mercury distribution.
|
||||||
%------------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
%
|
%
|
||||||
% File: digraph.m
|
% File: digraph.m
|
||||||
% Main author: bromage, petdr
|
% Main author: bromage, petdr
|
||||||
@@ -15,8 +15,8 @@
|
|||||||
% type T, and a set of edges of type pair(T). The endpoints of each edge
|
% type T, and a set of edges of type pair(T). The endpoints of each edge
|
||||||
% must be included in the set of vertices; cycles and loops are allowed.
|
% must be included in the set of vertices; cycles and loops are allowed.
|
||||||
%
|
%
|
||||||
%------------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
%------------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
|
|
||||||
:- module digraph.
|
:- module digraph.
|
||||||
:- interface.
|
:- interface.
|
||||||
@@ -29,7 +29,7 @@
|
|||||||
:- import_module set.
|
:- import_module set.
|
||||||
:- import_module sparse_bitset.
|
:- import_module sparse_bitset.
|
||||||
|
|
||||||
%------------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
|
|
||||||
% The type of directed graphs with vertices in T.
|
% The type of directed graphs with vertices in T.
|
||||||
%
|
%
|
||||||
@@ -51,20 +51,20 @@
|
|||||||
:- pred digraph.init(digraph(T)::out) is det.
|
:- pred digraph.init(digraph(T)::out) is det.
|
||||||
|
|
||||||
% digraph.add_vertex adds a vertex to the domain of a digraph.
|
% digraph.add_vertex adds a vertex to the domain of a digraph.
|
||||||
% Returns the old key if one already exists for this vertex, or
|
% Returns the old key if one already exists for this vertex,
|
||||||
% else allocates a new key.
|
% otherwise it allocates a new key.
|
||||||
%
|
%
|
||||||
:- pred digraph.add_vertex(T::in, digraph_key(T)::out,
|
:- pred digraph.add_vertex(T::in, digraph_key(T)::out,
|
||||||
digraph(T)::in, digraph(T)::out) is det.
|
digraph(T)::in, digraph(T)::out) is det.
|
||||||
|
|
||||||
% digraph.search_key returns the key associated with a vertex. Fails if
|
% digraph.search_key returns the key associated with a vertex.
|
||||||
% the vertex is not in the graph.
|
% Fails if the vertex is not in the graph.
|
||||||
%
|
%
|
||||||
:- pred digraph.search_key(digraph(T)::in, T::in, digraph_key(T)::out)
|
:- pred digraph.search_key(digraph(T)::in, T::in, digraph_key(T)::out)
|
||||||
is semidet.
|
is semidet.
|
||||||
|
|
||||||
% digraph.lookup_key returns the key associated with a vertex. Aborts if
|
% digraph.lookup_key returns the key associated with a vertex.
|
||||||
% the vertex is not in the graph.
|
% Aborts if the vertex is not in the graph.
|
||||||
%
|
%
|
||||||
:- func digraph.lookup_key(digraph(T), T) = digraph_key(T).
|
:- func digraph.lookup_key(digraph(T), T) = digraph_key(T).
|
||||||
:- pred digraph.lookup_key(digraph(T)::in, T::in, digraph_key(T)::out)
|
:- pred digraph.lookup_key(digraph(T)::in, T::in, digraph_key(T)::out)
|
||||||
@@ -437,7 +437,7 @@ digraph.lookup_key(G, Vertex, Key) :-
|
|||||||
( digraph.search_key(G, Vertex, Key0) ->
|
( digraph.search_key(G, Vertex, Key0) ->
|
||||||
Key = Key0
|
Key = Key0
|
||||||
;
|
;
|
||||||
error("digraph.lookup_key")
|
unexpected($module, $pred, "search for key failed")
|
||||||
).
|
).
|
||||||
|
|
||||||
digraph.lookup_vertex(G, Key) = Vertex :-
|
digraph.lookup_vertex(G, Key) = Vertex :-
|
||||||
@@ -447,7 +447,7 @@ digraph.lookup_vertex(G, Key, Vertex) :-
|
|||||||
( bimap.search(G ^ vertex_map, Vertex0, Key) ->
|
( bimap.search(G ^ vertex_map, Vertex0, Key) ->
|
||||||
Vertex = Vertex0
|
Vertex = Vertex0
|
||||||
;
|
;
|
||||||
error("digraph.lookup_vertex")
|
unexpected($module, $pred, "search for vertex failed")
|
||||||
).
|
).
|
||||||
|
|
||||||
%-----------------------------------------------------------------------------%
|
%-----------------------------------------------------------------------------%
|
||||||
@@ -957,8 +957,8 @@ digraph.atsort(G) = ATsort :-
|
|||||||
digraph.atsort(G, ATsort) :-
|
digraph.atsort(G, ATsort) :-
|
||||||
% digraph.atsort returns a topological sorting of the cliques in a digraph.
|
% digraph.atsort returns a topological sorting of the cliques in a digraph.
|
||||||
%
|
%
|
||||||
% The algorithm used is described in R. E. Tarjan, "Depth-first search
|
% The algorithm used is described in R.E. Tarjan, "Depth-first search
|
||||||
% and linear graph algorithms," SIAM Journal on Computing, 1, 2 (1972).
|
% and linear graph algorithms", SIAM Journal on Computing, 1, 2 (1972).
|
||||||
|
|
||||||
digraph.dfsrev(G, DfsRev),
|
digraph.dfsrev(G, DfsRev),
|
||||||
digraph.inverse(G, GInv),
|
digraph.inverse(G, GInv),
|
||||||
|
|||||||
Reference in New Issue
Block a user