File tree Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Expand file tree Collapse file tree 3 files changed +14
-14
lines changed Original file line number Diff line number Diff line change @@ -10,12 +10,12 @@ class Counter {
10
10
this . #id = id ;
11
11
}
12
12
13
- inc ( delta = 1 ) {
14
- this . #update( delta ) ;
13
+ inc ( x = 1 ) {
14
+ this . #update( x ) ;
15
15
}
16
16
17
- dec ( delta = 1 ) {
18
- this . #update( - delta ) ;
17
+ dec ( x = 1 ) {
18
+ this . #update( - x ) ;
19
19
}
20
20
21
21
#update( delta ) {
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ class GCounter {
11
11
this . #counts = counts ? structuredClone ( counts ) : new Array ( size ) . fill ( 0 ) ;
12
12
}
13
13
14
- increment ( delta = 1 ) {
14
+ inc ( delta = 1 ) {
15
15
if ( delta < 0 ) throw new Error ( 'Negative increment is not allowed' ) ;
16
16
this . #counts[ this . #id] += delta ;
17
17
}
@@ -38,13 +38,13 @@ const size = 2;
38
38
39
39
console . log ( 'Replica 0' ) ;
40
40
const counter0 = new GCounter ( 0 , { size } ) ;
41
- counter0 . increment ( ) ;
42
- counter0 . increment ( ) ;
41
+ counter0 . inc ( ) ;
42
+ counter0 . inc ( ) ;
43
43
console . log ( { id0 : counter0 . counts } ) ;
44
44
45
45
console . log ( 'Replica 1' ) ;
46
46
const counter1 = new GCounter ( 1 , { size } ) ;
47
- counter1 . increment ( ) ;
47
+ counter1 . inc ( ) ;
48
48
console . log ( { id1 : counter1 . counts } ) ;
49
49
50
50
console . log ( 'Sync' ) ;
Original file line number Diff line number Diff line change @@ -13,14 +13,14 @@ class PNCounter {
13
13
this . #nc = nCounts ? structuredClone ( nCounts ) : new Array ( size ) . fill ( 0 ) ;
14
14
}
15
15
16
- inc ( delta = 1 ) {
17
- if ( delta < 0 ) throw new Error ( 'Negative increment is not allowed' ) ;
18
- this . #pc[ this . #id] += delta ;
16
+ inc ( x = 1 ) {
17
+ if ( x < 0 ) throw new Error ( 'Negative increment is not allowed' ) ;
18
+ this . #pc[ this . #id] += x ;
19
19
}
20
20
21
- dec ( delta = 1 ) {
22
- if ( delta < 0 ) throw new Error ( 'Negative decrement is not allowed' ) ;
23
- this . #nc[ this . #id] += delta ;
21
+ dec ( x = 1 ) {
22
+ if ( x < 0 ) throw new Error ( 'Negative decrement is not allowed' ) ;
23
+ this . #nc[ this . #id] += x ;
24
24
}
25
25
26
26
merge ( { pCounts, nCounts } ) {
You can’t perform that action at this time.
0 commit comments