CacheSim/src/CacheSim/Update.elm

80 lines
2.7 KiB
Elm

module CacheSim.Update exposing (..)
import CacheSim.Model exposing (..)
import CacheSim.Hierarchy exposing (..)
import CacheSim.Raw exposing (..)
import CacheSim.IntMap exposing (..)
import CacheSim.AccessView exposing (..)
updateChangeRawModel : Int -> (RawCacheModel -> RawCacheModel) -> Model -> (Model, Cmd Msg)
updateChangeRawModel l f m =
let
newModel = { m | rawHierarchy = intMapUpdate l f m.rawHierarchy }
cmd = Cmd.none
in
(newModel, cmd)
updateCreateRawModel : Model -> (Model, Cmd Msg)
updateCreateRawModel m =
let
freshRawModel = { blockSize = "4", setCount = "4", setSize = "3" }
newModel = { m | rawHierarchy = m.rawHierarchy ++ [ freshRawModel ] }
cmd = Cmd.none
in
(newModel, cmd)
updateDeleteRawModel : Int -> Model -> (Model, Cmd Msg)
updateDeleteRawModel l m =
let
newModel = { m | rawHierarchy = intMapDelete l m.rawHierarchy }
cmd = Cmd.none
in
(newModel, cmd)
updateUseHierarchy : Maybe CacheModelHierarchy -> Model -> (Model, Cmd Msg)
updateUseHierarchy cmh m =
let
newModel = { m | hierarchy = Maybe.map freshCacheHierarchy cmh }
cmd = Cmd.none
in
(newModel, cmd)
updateAccess : List Int -> Model -> (Model, Cmd Msg)
updateAccess li m =
let
process c xs =
case xs of
[] -> Ok []
(i::t) ->
case accessCacheHierarchy i c of
Ok av -> Result.map ((::) (av, Down 0)) <| process (finalCacheHierarchy c (av, Done)) t
Err s -> Err s
accessResult = Maybe.andThen (\h -> Result.toMaybe <| process h li) m.hierarchy
newModel = { m | accessView = accessResult }
cmd = Cmd.none
in
(newModel, cmd)
updateAccessViewForward : Model -> (Model, Cmd Msg)
updateAccessViewForward m =
let
afterStep = Maybe.map (intMapUpdate 0 accessViewForward) m.accessView
(newHierarchy, newAccessView) =
case afterStep of
Just ((avs, Done)::[]) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Nothing)
Just ((avs, Done)::xs) -> (Maybe.map (\h -> finalCacheHierarchy h (avs, Done)) m.hierarchy, Just xs)
as_ -> (m.hierarchy, as_)
newModel = { m | accessView = newAccessView, hierarchy = newHierarchy }
cmd = Cmd.none
in
(newModel, cmd)
updateAccessViewBack : Model -> (Model, Cmd Msg)
updateAccessViewBack m =
let
afterStep = Maybe.map (intMapUpdate 0 accessViewBack) m.accessView
newModel = { m | accessView = afterStep }
cmd = Cmd.none
in
(newModel, cmd)