Skip to content

Commit 8ed74d8

Browse files
committed
Hide field accessor
1 parent 25bbe36 commit 8ed74d8

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/Data/DVV.hs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ module Data.DVV (
1818
-- * Core Types
1919
Count,
2020
Dot (..),
21-
VersionVector (..),
21+
VersionVector,
22+
mkVersionVector,
23+
getVersionVectorCounts,
2224
DVV (..),
2325

2426
-- * Operations
@@ -31,15 +33,15 @@ module Data.DVV (
3133
lww,
3234

3335
-- * Analysis
34-
mkVersionVector,
3536
size,
37+
extractComponents,
3638
)
3739
where
3840

3941
import Algebra.PartialOrd (PartialOrd (..))
4042
import Data.HashMap.Strict (HashMap)
4143
import qualified Data.HashMap.Strict as Map
42-
import Data.Hashable (Hashable (hashWithSalt))
44+
import Data.Hashable (Hashable (..))
4345
import Data.List (foldl', foldl1', sortBy)
4446
import Data.Maybe (fromMaybe)
4547
import Data.Word (Word64)
@@ -93,6 +95,10 @@ mkVersionVector m =
9395
where
9496
sortDesc keyFn = sortBy (\x y -> compare (keyFn y) (keyFn x))
9597

98+
-- | Helper to extract the map of counts from a VersionVector, we hide the other field accessors
99+
getVersionVectorCounts :: VersionVector actorID -> HashMap actorID Count
100+
getVersionVectorCounts (VersionVector m _) = m
101+
96102
{- | A Dotted Version Vector (DVV) consisting of a Causal History (Version Vector)
97103
and a set of concurrent values associated with Dots.
98104

test/Spec.hs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,16 @@ main = hspec $ do
194194
let ctx1 = context d1
195195
ctxSync = context (sync d1 d2)
196196
in all
197-
(\(k, v) -> Map.lookup k (vvMap ctxSync) >= Just v)
198-
(Map.toList (vvMap ctx1))
197+
(\(k, v) -> Map.lookup k (getVersionVectorCounts ctxSync) >= Just v)
198+
(Map.toList (getVersionVectorCounts ctx1))
199199

200200
it "event increases context counter for the actor" $
201201
property $ \(d :: DVV ID Value) (actor :: ID) (val :: Value) ->
202202
let ctx = context d
203203
d' = event d (Just ctx) actor val
204204
ctx' = context d'
205-
oldCount = Map.findWithDefault 0 actor (vvMap ctx)
206-
newCount = Map.findWithDefault 0 actor (vvMap ctx')
205+
oldCount = Map.findWithDefault 0 actor (getVersionVectorCounts ctx)
206+
newCount = Map.findWithDefault 0 actor (getVersionVectorCounts ctx')
207207
in newCount `shouldBe` (oldCount + 1)
208208

209209
it "event with full context produces exactly one value" $
@@ -236,9 +236,9 @@ main = hspec $ do
236236
property $ \(d :: DVV ID Value) ->
237237
case d of
238238
EmptyDVV -> True
239-
SingletonDVV actor _ -> Map.member actor (vvMap (context d))
239+
SingletonDVV actor _ -> Map.member actor (getVersionVectorCounts (context d))
240240
DVV _ vals ->
241-
let ctx = vvMap (context d)
241+
let ctx = getVersionVectorCounts (context d)
242242
actors = [actor | Dot actor _ <- Map.keys vals]
243243
in all (`Map.member` ctx) actors
244244

0 commit comments

Comments
 (0)