Skip to content

Commit 4ec3435

Browse files
committed
Extract single-epoch-vs-multi-epoch deduction computation
1 parent e3f147d commit 4ec3435

2 files changed

Lines changed: 8 additions & 13 deletions

File tree

api.bs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,9 +1235,10 @@ and a [=set=] of [=epoch indices=] |deductedGlobalBudgets|:
12351235
wait until the value becomes false,
12361236
then set the value to true.
12371237

1238+
1. Let |deduction| be |l1NormDeduction| if |isSingleEpoch| is true, |valueDeduction| otherwise.
1239+
12381240
1. If the result of invoking [=check for available privacy budget|checking for available privacy budget=]
1239-
with |key|, |l1NormDeduction|, |valueDeduction|,
1240-
|impressions|, and |isSingleEpoch|
1241+
with |key|, |deduction|, |valueDeduction|, and |impressions|
12411242
is false, perform the following steps:
12421243

12431244
1. Set [=attribution budget lock=] to false.
@@ -1246,7 +1247,6 @@ and a [=set=] of [=epoch indices=] |deductedGlobalBudgets|:
12461247

12471248
1. All budget checks passed, so perform the deductions:
12481249

1249-
1. If |isSingleEpoch| let |deduction| be |l1NormDeduction| else let |deduction| be |valueDeduction|.
12501250

12511251
1. Let |currentValue| be the result of [=map/get|getting the value=] of |key|
12521252
in the [=privacy budget store=]
@@ -1291,11 +1291,9 @@ and a [=set=] of [=epoch indices=] |deductedGlobalBudgets|:
12911291

12921292
<div algorithm>
12931293
To <dfn>check for available privacy budget</dfn>
1294-
given a [=privacy budget key=] |key|, integer |l1NormDeduction|,
1294+
given a [=privacy budget key=] |key|, integer |deduction|,
12951295
integer |valueDeduction|,
1296-
[=set=] of [=impressions=] |impressions| and boolean |isSingleEpoch|:
1297-
1298-
1. If |isSingleEpoch| let |deduction| be |l1NormDeduction| else let |deduction| be |valueDeduction|.
1296+
and [=set=] of [=impressions=] |impressions|:
12991297

13001298
1. Let |currentValue| be set to the value of [=map/get|getting the value=] of |key|
13011299
from [=privacy budget store=],

impl/src/backend.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ export class Backend {
548548
const valueDeductionFp = valueSensitivity / noiseScale;
549549
const l1NormDeduction = Math.ceil(l1NormDeductionFp * 1000000);
550550
const valueDeduction = Math.ceil(valueDeductionFp * 1000000);
551+
const deduction = isSingleEpoch ? l1NormDeduction : valueDeduction;
551552
if (
552553
!this.#checkForAvailablePrivacyBudget(
553554
key,
554-
l1NormDeduction,
555+
deduction,
555556
valueDeduction,
556557
impressions,
557-
isSingleEpoch,
558558
)
559559
) {
560560
return false;
@@ -564,7 +564,6 @@ export class Backend {
564564
key,
565565
this.#delegate.perSitePrivacyBudget,
566566
);
567-
const deduction = isSingleEpoch ? l1NormDeduction : valueDeduction;
568567
const currentValue = entry.value;
569568
entry.value = currentValue - deduction;
570569
const epoch = key.epoch;
@@ -593,12 +592,10 @@ export class Backend {
593592

594593
#checkForAvailablePrivacyBudget(
595594
key: PrivacyBudgetKey,
596-
l1NormDeduction: number,
595+
deduction: number,
597596
valueDeduction: number,
598597
impressions: ReadonlySet<Impression>,
599-
isSingleEpoch: boolean,
600598
): boolean {
601-
const deduction = isSingleEpoch ? l1NormDeduction : valueDeduction;
602599
const currentValue =
603600
getEntry(this.#privacyBudgetStore, key)?.value ??
604601
this.#delegate.perSitePrivacyBudget;

0 commit comments

Comments
 (0)