Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
fix: working topological sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
prescientmoon committed Apr 27, 2020
1 parent ec3f979 commit 3c5baab
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
11 changes: 2 additions & 9 deletions src/Component/Editor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import Data.Lens (over, preview, set, view)
import Data.List.Lazy as List
import Data.Map as Map
import Data.Maybe (Maybe(..), fromMaybe, maybe)
import Data.Newtype (unwrap)
import Data.Set as Set
import Data.Symbol (SProxy(..))
import Data.Tuple (Tuple(..), uncurry)
Expand All @@ -32,7 +31,7 @@ import Lunarbox.Component.Editor.Tree as TreeC
import Lunarbox.Component.Icon (icon)
import Lunarbox.Component.Utils (container)
import Lunarbox.Config (Config)
import Lunarbox.Control.Monad.Effect (print, printString)
import Lunarbox.Control.Monad.Effect (printString)
import Lunarbox.Data.Dataflow.Expression (printSource)
import Lunarbox.Data.Dataflow.Native.Prelude (loadPrelude)
import Lunarbox.Data.Dataflow.Type (numberOfInputs)
Expand All @@ -44,7 +43,7 @@ import Lunarbox.Data.Editor.Node.NodeDescriptor (onlyEditable)
import Lunarbox.Data.Editor.Node.NodeId (NodeId(..))
import Lunarbox.Data.Editor.Node.PinLocation (Pin(..))
import Lunarbox.Data.Editor.Project (_projectNodeGroup, emptyProject)
import Lunarbox.Data.Editor.State (State, Tab(..), _atColorMap, _atNode, _atNodeData, _currentFunction, _currentNodeGroup, _currentNodes, _currentTab, _expression, _function, _functions, _isSelected, _lastMousePosition, _nextId, _nodeData, _panelIsOpen, _partialFrom, _partialTo, _typeMap, _valueMap, compile, getSceneMousePosition, initializeFunction, removeConnection, setCurrentFunction, tabIcon, tryConnecting)
import Lunarbox.Data.Editor.State (State, Tab(..), _atColorMap, _atNode, _atNodeData, _currentFunction, _currentTab, _expression, _function, _functions, _isSelected, _lastMousePosition, _nextId, _nodeData, _panelIsOpen, _partialFrom, _partialTo, _typeMap, compile, getSceneMousePosition, initializeFunction, removeConnection, setCurrentFunction, tabIcon, tryConnecting)
import Lunarbox.Data.Graph as G
import Lunarbox.Data.Vector (Vec2)
import Lunarbox.Page.Editor.EmptyEditor (emptyEditor)
Expand Down Expand Up @@ -146,8 +145,6 @@ component =
state'''' = over _functions (G.insertEdge name currentFunction) state'''
void $ put $ compile $ setId state''''
ChangeTab newTab -> do
s <- gets $ view _valueMap
print s
oldTab <- gets $ view _currentTab
modify_
if (oldTab == newTab) then
Expand Down Expand Up @@ -193,10 +190,6 @@ component =
modify_ $ tryConnecting <<< setFrom
e <- gets $ view _expression
printString $ printSource e
a <- gets $ view _currentNodeGroup
b <- gets $ preview _currentNodes
print b
(print :: Maybe (Array _) -> _) $ G.edges <$> _.nodes <$> unwrap <$> a
RemoveConnection from to -> do
modify_ $ removeConnection from to

Expand Down
1 change: 0 additions & 1 deletion src/Data/Editor/Project.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ module Lunarbox.Data.Editor.Project
import Prelude
import Data.Lens (Lens', Traversal', _Just, set, view)
import Data.Lens.At (at)
import Data.Lens.Index (ix)
import Data.Lens.Record (prop)
import Data.Maybe (Maybe(..))
import Data.Newtype (class Newtype)
Expand Down
5 changes: 2 additions & 3 deletions src/Data/Editor/State.purs
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,11 @@ tryConnecting state =
currentNodeGroup <- preview _currentNodeGroup state
currentFunction <- view _currentFunction state
let
state' = over (_nodes currentFunction) (G.insertEdge toId from) state
state' = over _currentNodes (G.insertEdge from toId) state

state'' =
set
( _atNode currentFunction toId
<<< _Just
( _atCurrentNode toId
<<< _nodeInput toIndex
)
(Just from)
Expand Down
4 changes: 2 additions & 2 deletions src/Data/Graph.purs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Data.Lens.At (class At)
import Data.Lens.Index (class Index)
import Data.List (List)
import Data.Map as Map
import Data.Maybe (Maybe, maybe)
import Data.Maybe (Maybe(..), maybe)
import Data.Newtype (class Newtype, over, unwrap)
import Data.Set (Set)
import Data.Set as Set
Expand Down Expand Up @@ -88,7 +88,7 @@ singleton :: forall k v. Ord k => k -> v -> Graph k v
singleton k v = Graph $ Map.singleton k $ Tuple v Set.empty

insert :: forall k v. Ord k => k -> v -> Graph k v -> Graph k v
insert k v (Graph m) = Graph $ Map.insert k (Tuple v Set.empty) m
insert key value (Graph m) = Graph $ Map.alter (Just <<< (maybe (Tuple value Set.empty) $ lmap $ const value)) key m

lookup :: forall k v. Ord k => k -> Graph k v -> Maybe v
lookup k = map fst <<< Map.lookup k <<< unwrap
Expand Down

0 comments on commit 3c5baab

Please sign in to comment.