Skip to content

Commit 6185a0d

Browse files
committed
Improve naming
1 parent ac373c1 commit 6185a0d

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

OperationBased/1-counter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ class Counter {
1010
this.#id = id;
1111
}
1212

13-
inc(delta = 1) {
14-
this.#update(delta);
13+
inc(x = 1) {
14+
this.#update(x);
1515
}
1616

17-
dec(delta = 1) {
18-
this.#update(-delta);
17+
dec(x = 1) {
18+
this.#update(-x);
1919
}
2020

2121
#update(delta) {

StateBased/1-gcounter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class GCounter {
1111
this.#counts = counts ? structuredClone(counts) : new Array(size).fill(0);
1212
}
1313

14-
increment(delta = 1) {
14+
inc(delta = 1) {
1515
if (delta < 0) throw new Error('Negative increment is not allowed');
1616
this.#counts[this.#id] += delta;
1717
}
@@ -38,13 +38,13 @@ const size = 2;
3838

3939
console.log('Replica 0');
4040
const counter0 = new GCounter(0, { size });
41-
counter0.increment();
42-
counter0.increment();
41+
counter0.inc();
42+
counter0.inc();
4343
console.log({ id0: counter0.counts });
4444

4545
console.log('Replica 1');
4646
const counter1 = new GCounter(1, { size });
47-
counter1.increment();
47+
counter1.inc();
4848
console.log({ id1: counter1.counts });
4949

5050
console.log('Sync');

StateBased/2-pn-counter.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ class PNCounter {
1313
this.#nc = nCounts ? structuredClone(nCounts) : new Array(size).fill(0);
1414
}
1515

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;
1919
}
2020

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;
2424
}
2525

2626
merge({ pCounts, nCounts }) {

0 commit comments

Comments
 (0)