Skip to content

Commit

Permalink
convert Data.Map to use a Dict
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Dec 11, 2024
1 parent 03a6c67 commit c05ae0d
Show file tree
Hide file tree
Showing 74 changed files with 1,429 additions and 1,522 deletions.
178 changes: 89 additions & 89 deletions src/Builder/Build.elm

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions src/Builder/Deps/Diff.elm
Original file line number Diff line number Diff line change
Expand Up @@ -30,25 +30,25 @@ import Utils.Main as Utils


type PackageChanges
= PackageChanges (List ModuleName.Raw) (Dict ModuleName.Raw ModuleChanges) (List ModuleName.Raw)
= PackageChanges (List ModuleName.Raw) (Dict String ModuleName.Raw ModuleChanges) (List ModuleName.Raw)


type ModuleChanges
= ModuleChanges (Changes Name.Name Docs.Union) (Changes Name.Name Docs.Alias) (Changes Name.Name Docs.Value) (Changes Name.Name Docs.Binop)
= ModuleChanges (Changes String Name.Name Docs.Union) (Changes String Name.Name Docs.Alias) (Changes String Name.Name Docs.Value) (Changes String Name.Name Docs.Binop)


type Changes k v
= Changes (Dict k v) (Dict k ( v, v )) (Dict k v)
type Changes c k v
= Changes (Dict c k v) (Dict c k ( v, v )) (Dict c k v)


getChanges : (k -> k -> Order) -> (v -> v -> Bool) -> Dict k v -> Dict k v -> Changes k v
getChanges keyComparison isEquivalent old new =
getChanges : (k -> comparable) -> (k -> k -> Order) -> (v -> v -> Bool) -> Dict comparable k v -> Dict comparable k v -> Changes comparable k v
getChanges toComparable keyComparison isEquivalent old new =
let
overlap : Dict k ( v, v )
overlap : Dict comparable k ( v, v )
overlap =
Utils.mapIntersectionWith keyComparison Tuple.pair old new
Utils.mapIntersectionWith toComparable keyComparison Tuple.pair old new

changed : Dict k ( v, v )
changed : Dict comparable k ( v, v )
changed =
Dict.filter (\_ ( v1, v2 ) -> not (isEquivalent v1 v2)) overlap
in
Expand All @@ -65,26 +65,26 @@ getChanges keyComparison isEquivalent old new =
diff : Docs.Documentation -> Docs.Documentation -> PackageChanges
diff oldDocs newDocs =
let
filterOutPatches : Dict a ModuleChanges -> Dict a ModuleChanges
filterOutPatches : Dict comparable a ModuleChanges -> Dict comparable a ModuleChanges
filterOutPatches chngs =
Dict.filter (\_ chng -> moduleChangeMagnitude chng /= M.PATCH) chngs

(Changes added changed removed) =
getChanges compare (\_ _ -> False) oldDocs newDocs
getChanges identity compare (\_ _ -> False) oldDocs newDocs
in
PackageChanges
(Dict.keys added)
(Dict.keys compare added)
(filterOutPatches (Dict.map (\_ -> diffModule) changed))
(Dict.keys removed)
(Dict.keys compare removed)


diffModule : ( Docs.Module, Docs.Module ) -> ModuleChanges
diffModule ( Docs.Module _ _ u1 a1 v1 b1, Docs.Module _ _ u2 a2 v2 b2 ) =
ModuleChanges
(getChanges compare isEquivalentUnion u1 u2)
(getChanges compare isEquivalentAlias a1 a2)
(getChanges compare isEquivalentValue v1 v2)
(getChanges compare isEquivalentBinop b1 b2)
(getChanges identity compare isEquivalentUnion u1 u2)
(getChanges identity compare isEquivalentAlias a1 a2)
(getChanges identity compare isEquivalentValue v1 v2)
(getChanges identity compare isEquivalentBinop b1 b2)



Expand All @@ -109,7 +109,7 @@ isEquivalentUnion (Docs.Union oldComment oldVars oldCtors) (Docs.Union newCommen
in
(List.length oldCtors == List.length newCtors)
&& List.all identity (List.map2 (==) (List.map Tuple.first oldCtors) (List.map Tuple.first newCtors))
&& List.all identity (Dict.values (Utils.mapIntersectionWith compare equiv (Dict.fromList compare oldCtors) (Dict.fromList compare newCtors)))
&& List.all identity (Dict.values compare (Utils.mapIntersectionWith identity compare equiv (Dict.fromList identity oldCtors) (Dict.fromList identity newCtors)))


isEquivalentAlias : Docs.Alias -> Docs.Alias -> Bool
Expand Down Expand Up @@ -243,11 +243,11 @@ isEquivalentRenaming varPairs =
let
renamings : List ( Name.Name, List Name.Name )
renamings =
Dict.toList (List.foldr insert Dict.empty varPairs)
Dict.toList compare (List.foldr insert Dict.empty varPairs)

insert : ( Name.Name, Name.Name ) -> Dict Name.Name (List Name.Name) -> Dict Name.Name (List Name.Name)
insert : ( Name.Name, Name.Name ) -> Dict String Name.Name (List Name.Name) -> Dict String Name.Name (List Name.Name)
insert ( old, new ) dict =
Utils.mapInsertWith compare (++) old [ new ] dict
Utils.mapInsertWith identity (++) old [ new ] dict

verify : ( a, List b ) -> Maybe ( a, b )
verify ( old, news ) =
Expand All @@ -264,7 +264,7 @@ isEquivalentRenaming varPairs =

allUnique : List comparable -> Bool
allUnique list =
List.length list == EverySet.size (EverySet.fromList compare list)
List.length list == EverySet.size (EverySet.fromList identity list)
in
case Utils.maybeMapM verify renamings of
Nothing ->
Expand Down Expand Up @@ -364,7 +364,7 @@ toMagnitude (PackageChanges added changed removed) =

changeMags : List M.Magnitude
changeMags =
List.map moduleChangeMagnitude (Dict.values changed)
List.map moduleChangeMagnitude (Dict.values compare changed)
in
Utils.listMaximum M.compare (addMag :: removeMag :: changeMags)

Expand All @@ -379,7 +379,7 @@ moduleChangeMagnitude (ModuleChanges unions aliases values binops) =
]


changeMagnitude : Changes k v -> M.Magnitude
changeMagnitude : Changes comparable k v -> M.Magnitude
changeMagnitude (Changes added changed removed) =
if Dict.size removed > 0 || Dict.size changed > 0 then
M.MAJOR
Expand Down
24 changes: 12 additions & 12 deletions src/Builder/Deps/Registry.elm
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import System.IO as IO exposing (IO)


type Registry
= Registry Int (Dict Pkg.Name KnownVersions)
= Registry Int (Dict ( String, String ) Pkg.Name KnownVersions)


type KnownVersions
Expand Down Expand Up @@ -75,7 +75,7 @@ fetch manager cache =
let
size : Int
size =
Dict.foldr (\_ -> addEntry) 0 versions
Dict.foldr Pkg.compareName (\_ -> addEntry) 0 versions

registry : Registry
registry =
Expand All @@ -94,7 +94,7 @@ addEntry (KnownVersions _ vs) count =
count + 1 + List.length vs


allPkgsDecoder : D.Decoder () (Dict Pkg.Name KnownVersions)
allPkgsDecoder : D.Decoder () (Dict ( String, String ) Pkg.Name KnownVersions)
allPkgsDecoder =
let
keyDecoder : D.KeyDecoder () Pkg.Name
Expand All @@ -114,7 +114,7 @@ allPkgsDecoder =
[] ->
D.failure ()
in
D.dict Pkg.compareName keyDecoder (D.bind toKnownVersions versionsDecoder)
D.dict identity keyDecoder (D.bind toKnownVersions versionsDecoder)



Expand All @@ -135,7 +135,7 @@ update manager cache ((Registry size packages) as oldRegistry) =
newSize =
size + List.length news

newPkgs : Dict Pkg.Name KnownVersions
newPkgs : Dict ( String, String ) Pkg.Name KnownVersions
newPkgs =
List.foldr addNew packages news

Expand All @@ -147,7 +147,7 @@ update manager cache ((Registry size packages) as oldRegistry) =
|> IO.fmap (\_ -> newRegistry)


addNew : ( Pkg.Name, V.Version ) -> Dict Pkg.Name KnownVersions -> Dict Pkg.Name KnownVersions
addNew : ( Pkg.Name, V.Version ) -> Dict ( String, String ) Pkg.Name KnownVersions -> Dict ( String, String ) Pkg.Name KnownVersions
addNew ( name, version ) versions =
let
add : Maybe KnownVersions -> KnownVersions
Expand All @@ -159,7 +159,7 @@ addNew ( name, version ) versions =
Nothing ->
KnownVersions version []
in
Dict.update Pkg.compareName name (Just << add) versions
Dict.update identity name (Just << add) versions



Expand Down Expand Up @@ -211,17 +211,17 @@ latest manager cache =

getVersions : Pkg.Name -> Registry -> Maybe KnownVersions
getVersions name (Registry _ versions) =
Dict.get name versions
Dict.get identity name versions


getVersions_ : Pkg.Name -> Registry -> Result (List Pkg.Name) KnownVersions
getVersions_ name (Registry _ versions) =
case Dict.get name versions of
case Dict.get identity name versions of
Just kvs ->
Ok kvs

Nothing ->
Err (Pkg.nearbyNames name (Dict.keys versions))
Err (Pkg.nearbyNames name (Dict.keys compare versions))



Expand Down Expand Up @@ -253,12 +253,12 @@ registryDecoder : Decode.Decoder Registry
registryDecoder =
Decode.map2 Registry
(Decode.field "size" Decode.int)
(Decode.field "packages" (D.assocListDict Pkg.compareName Pkg.nameDecoder knownVersionsDecoder))
(Decode.field "packages" (D.assocListDict identity Pkg.nameDecoder knownVersionsDecoder))


registryEncoder : Registry -> Encode.Value
registryEncoder (Registry size versions) =
Encode.object
[ ( "size", Encode.int size )
, ( "packages", E.assocListDict Pkg.nameEncoder knownVersionsEncoder versions )
, ( "packages", E.assocListDict Pkg.compareName Pkg.nameEncoder knownVersionsEncoder versions )
]
Loading

0 comments on commit c05ae0d

Please sign in to comment.