CacheSim/src/CacheSim/Update.elm

72 lines
2.3 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 = "", setCount = "", setSize = "" }
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 : Int -> Model -> (Model, Cmd Msg)
updateAccess i m =
let
accessResult = Maybe.andThen (Result.toMaybe << accessCacheHierarchy i) m.hierarchy
newModel = { m | accessView = Maybe.map (\ar -> (ar, Down 0)) accessResult }
cmd = Cmd.none
in
(newModel, cmd)
updateAccessViewForward : Model -> (Model, Cmd Msg)
updateAccessViewForward m =
let
afterStep = Maybe.map accessViewForward m.accessView
replaceHierarchy avs h = List.map .output avs ++ List.drop (List.length avs) h
(newHierarchy, newAccessView) =
case afterStep of
Just (avs, Done) -> (Maybe.map (replaceHierarchy avs) m.hierarchy, Nothing)
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 accessViewBack m.accessView
newModel = { m | accessView = afterStep }
cmd = Cmd.none
in
(newModel, cmd)