diff --git a/src/Algebra/Graph/NonEmpty/AdjacencyIntMap.hs b/src/Algebra/Graph/NonEmpty/AdjacencyIntMap.hs index f7758118..19f8af9b 100644 --- a/src/Algebra/Graph/NonEmpty/AdjacencyIntMap.hs +++ b/src/Algebra/Graph/NonEmpty/AdjacencyIntMap.hs @@ -55,15 +55,12 @@ import Prelude hiding (reverse) import Control.DeepSeq import Data.Coerce import Data.List ((\\)) -import Data.List.NonEmpty (NonEmpty (..), nonEmpty, toList, reverse) -import Data.Maybe +import Data.List.NonEmpty (NonEmpty (..), toList, reverse, fromList) import Data.IntSet (IntSet) import Data.Set (Set) import Data.Tree import GHC.Generics -import Algebra.Graph.Internal - import qualified Algebra.Graph.AdjacencyIntMap as AIM import qualified Data.IntSet as IntSet @@ -378,7 +375,7 @@ edgeCount = coerce AIM.edgeCount -- vertexList1 . 'vertices1' == 'Data.List.NonEmpty.nub' . 'Data.List.NonEmpty.sort' -- @ vertexList1 :: AdjacencyIntMap -> NonEmpty Int -vertexList1 = unsafeNonEmpty . coerce AIM.vertexList +vertexList1 = fromList . coerce AIM.vertexList -- | The sorted list of edges of a graph. -- Complexity: /O(n + m)/ time and /O(m)/ memory. diff --git a/src/Algebra/Graph/NonEmpty/AdjacencyMap.hs b/src/Algebra/Graph/NonEmpty/AdjacencyMap.hs index 1c1dcd50..f7b39dfb 100644 --- a/src/Algebra/Graph/NonEmpty/AdjacencyMap.hs +++ b/src/Algebra/Graph/NonEmpty/AdjacencyMap.hs @@ -54,15 +54,12 @@ import Prelude hiding (reverse) import Control.DeepSeq import Data.Coerce import Data.List ((\\)) -import Data.List.NonEmpty (NonEmpty (..), nonEmpty, toList, reverse) -import Data.Maybe +import Data.List.NonEmpty (NonEmpty (..), toList, reverse, fromList) import Data.Set (Set) import Data.String import Data.Tree import GHC.Generics -import Algebra.Graph.Internal - import qualified Algebra.Graph.AdjacencyMap as AM import qualified Data.Set as Set @@ -375,7 +372,7 @@ edgeCount = coerce AM.edgeCount -- vertexList1 . 'vertices1' == 'Data.List.NonEmpty.nub' . 'Data.List.NonEmpty.sort' -- @ vertexList1 :: AdjacencyMap a -> NonEmpty a -vertexList1 = unsafeNonEmpty . coerce AM.vertexList +vertexList1 = fromList . coerce AM.vertexList -- | The sorted list of edges of a graph. -- Complexity: /O(n + m)/ time and /O(m)/ memory. diff --git a/test/Algebra/Graph/Test/API.hs b/test/Algebra/Graph/Test/API.hs index 8eabf3c0..07014188 100644 --- a/test/Algebra/Graph/Test/API.hs +++ b/test/Algebra/Graph/Test/API.hs @@ -55,7 +55,19 @@ instance Show g => Show (Mono g a) where toIntAPI :: API g Ord -> API g ((~) Int) toIntAPI API{..} = API{..} --- TODO: Add missing API entries for Acyclic, NonEmpty and Symmetric graphs. +-- TODO: Add missing API entries for Acyclic, NonEmpty and Symmetric +-- graphs. Here is a blueprint initially discussed in +-- https://github.com/snowleopard/alga/pull/250 (adding nonempty +-- aims): +-- 1. Extend data API g c with new fields that correspond to +-- missing methods (most of them end with the suffix 1). +-- 2. Add tests for missing methods to Test.Generic or +-- Test.Generic.NonEmpty -- whichever turns out to be +-- clearer/more convenient. +-- 3. Consider/decide whether or not ToGraph are useful or needed +-- 4. Tests for non-empty modules would need to import API, +-- Generic and perhaps also Generic.NonEmpty (if it turns out to +-- be convenient). -- | The complete graph API dictionary. A graph data type, such as 'G.Graph', -- typically implements only a part of the whole API. data API g c where