Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flattenSCC1 :: SCC a -> NonEmpty a #987

Merged
merged 4 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions containers/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
`Data.IntSet.splitMember` are now strict in the key. Previously, the key was
ignored for an empty map or set. (Soumik Sarkar)

## Unreleased with `@since` annotation for 0.7.1:

### Additions

* Add `Data.Graph.flattenSCC1`. (Andreas Abel)

## 0.7

### Breaking changes
Expand Down Expand Up @@ -319,13 +325,13 @@ modules.

* Rewrite the `IsString` instance head for sequences, improving compatibility
with the list instance and also improving type inference. We used to have

```haskell
instance IsString (Seq Char)
```

Now we commit more eagerly with

```haskell
instance a ~ Char => IsString (Seq a)
```
Expand Down Expand Up @@ -399,7 +405,7 @@ modules.
* Fix completely incorrect implementations of `Data.IntMap.restrictKeys` and
`Data.IntMap.withoutKeys`. Make the tests for these actually run. (Thanks
to Tom Smalley for reporting this.)

* Fix a minor bug in the `Show1` instance of `Data.Tree`. This produced valid
output, but with fewer parentheses than `Show`. (Thanks, Ryan Scott.)

Expand Down Expand Up @@ -454,7 +460,7 @@ performance improvements overall.
before 7.0.

* Integrate benchmarks with Cabal. (Thanks, Gabriel Gonzalez!)

* Make Cabal report required extensions properly, and stop using
default extensions. Note that we do *not* report extensions conditionally enabled
based on GHC version, as doing so would lead to a maintenance nightmare
Expand Down Expand Up @@ -504,7 +510,7 @@ performance improvements overall.
it returned a lazy pair.

* Fix completely erroneous definition of `length` for `Data.Sequence.ViewR`.

* Make `Data.Map.Strict.traverseWithKey` force result values before
installing them in the new map.

Expand Down
16 changes: 14 additions & 2 deletions containers/src/Data/Graph.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ module Data.Graph (

-- ** Conversion
, flattenSCC
, flattenSCC1
, flattenSCCs

-- * Trees
Expand Down Expand Up @@ -246,9 +247,20 @@ flattenSCCs :: [SCC a] -> [a]
flattenSCCs = concatMap flattenSCC
meooow25 marked this conversation as resolved.
Show resolved Hide resolved

-- | The vertices of a strongly connected component.
--
-- @flattenSCC = 'Data.List.NonEmpty.toList' . 'flattenSCC1'@.
--
-- This function is retained for backward compatibility,
-- 'flattenSCC1' has the more precise type.
flattenSCC :: SCC vertex -> [vertex]
flattenSCC (AcyclicSCC v) = [v]
flattenSCC (NECyclicSCC vs) = NE.toList vs
flattenSCC = NE.toList . flattenSCC1

-- | The vertices of a strongly connected component.
--
-- @since 0.7.1
flattenSCC1 :: SCC vertex -> NonEmpty vertex
meooow25 marked this conversation as resolved.
Show resolved Hide resolved
flattenSCC1 (AcyclicSCC v) = v :| []
flattenSCC1 (NECyclicSCC vs) = vs

-- | \(O((V+E) \log V)\). The strongly connected components of a directed graph,
-- reverse topologically sorted.
Expand Down