blob: 122536d51772ea1e62eacde248809bbe9309f4ee (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/federated_learning/floc_id.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "components/federated_learning/floc_constants.h"
#include "components/federated_learning/sim_hash.h"
namespace federated_learning {
namespace {
// Domain one-hot + sim hash + sorting-lsh (behind a feature flag)
const uint32_t kChromeFlocIdVersion = 1;
} // namespace
// static
uint64_t FlocId::SimHashHistory(
const std::unordered_set<std::string>& domains) {
return SimHashStrings(domains, kMaxNumberOfBitsInFloc);
}
FlocId::FlocId() = default;
FlocId::FlocId(uint64_t id,
base::Time history_begin_time,
base::Time history_end_time,
uint32_t sorting_lsh_version)
: id_(id),
history_begin_time_(history_begin_time),
history_end_time_(history_end_time),
sorting_lsh_version_(sorting_lsh_version) {}
FlocId::FlocId(const FlocId& id) = default;
FlocId::~FlocId() = default;
FlocId& FlocId::operator=(const FlocId& id) = default;
FlocId& FlocId::operator=(FlocId&& id) = default;
bool FlocId::IsValid() const {
return id_.has_value();
}
bool FlocId::operator==(const FlocId& other) const {
return id_ == other.id_ && history_begin_time_ == other.history_begin_time_ &&
history_end_time_ == other.history_end_time_ &&
sorting_lsh_version_ == other.sorting_lsh_version_;
}
bool FlocId::operator!=(const FlocId& other) const {
return !(*this == other);
}
std::string FlocId::ToStringForJsApi() const {
DCHECK(id_.has_value());
return base::StrCat({base::NumberToString(id_.value()), ".",
base::NumberToString(kChromeFlocIdVersion), ".",
base::NumberToString(sorting_lsh_version_)});
}
} // namespace federated_learning
|