diff options
author | Samuel Huang <huangs@chromium.org> | 2018-03-13 18:19:34 +0000 |
---|---|---|
committer | Edward Lesmes <ehmaldonado@google.com> | 2021-07-23 21:50:59 +0000 |
commit | 06f1ae9aaca969ee95ef840f22b6b461c304542d (patch) | |
tree | f1e5c6624e70628e81fbf38d6cd14b974abe5d93 /targets_affinity.h | |
download | zucchini-06f1ae9aaca969ee95ef840f22b6b461c304542d.tar.gz |
[Zucchini] Move Zucchini from /chrome/installer/ to /components/.
(Use "git log --follow" to see older revisions of files).
/components/ is the most logical place to put Zucchini, which only
depends on /base and /testing/gtest. This move also enables Zucchini to
be used by the Component Updater. Details:
- Move all files; run the following to change deps and guards:
sed 's/chrome\/installer/components/' *.cc *.h -i
sed 's/CHROME_INSTALLER/COMPONENTS/' *.cc *.h -i
- Sorting works out pretty well!
- Change all 'chrome/installer/zucchini' to 'components/zucchini'
throughout other parts of the repo; sort if necessary.
- Fix 6 'git cl lint' errors.
- Change 1 Bind() usage to BindRepeated().
- Update OWNER.
Bug: 729154
Change-Id: I50c5a7d411ea85f707b5994ab319dfb2a1acccf7
Reviewed-on: https://chromium-review.googlesource.com/954923
Reviewed-by: Greg Thompson <grt@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Samuel Huang <huangs@chromium.org>
Commit-Queue: Samuel Huang <huangs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#542857}
NOKEYCHECK=True
GitOrigin-RevId: 577ef6c435e8d43be6e3e60ccbcbd1881780f4ec
Diffstat (limited to 'targets_affinity.h')
-rw-r--r-- | targets_affinity.h | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/targets_affinity.h b/targets_affinity.h new file mode 100644 index 0000000..3a154e7 --- /dev/null +++ b/targets_affinity.h @@ -0,0 +1,74 @@ +// Copyright 2017 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. + +#ifndef COMPONENTS_ZUCCHINI_TARGETS_AFFINITY_H_ +#define COMPONENTS_ZUCCHINI_TARGETS_AFFINITY_H_ + +#include <stddef.h> +#include <stdint.h> + +#include <vector> + +#include "base/macros.h" +#include "components/zucchini/image_utils.h" + +namespace zucchini { + +class EquivalenceMap; + +// Computes and stores affinity between old and new targets for a single target +// pool. This is only used during patch generation. +class TargetsAffinity { + public: + TargetsAffinity(); + ~TargetsAffinity(); + + // Infers affinity between |old_targets| and |new_targets| using similarities + // described by |equivalence_map|, and updates internal state for retrieval of + // affinity scores. Both |old_targets| and |new_targets| are targets in the + // same pool and are sorted in ascending order. + void InferFromSimilarities(const EquivalenceMap& equivalence_map, + const std::vector<offset_t>& old_targets, + const std::vector<offset_t>& new_targets); + + // Assigns labels to targets based on associations previously inferred, using + // |min_affinity| to reject associations with weak |affinity|. Label 0 is + // assigned to unassociated targets. Labels for old targets are written to + // |old_labels| and labels for new targets are written to |new_labels|. + // Returns the upper bound on assigned labels (>= 1 since 0 is used). + uint32_t AssignLabels(double min_affinity, + std::vector<uint32_t>* old_labels, + std::vector<uint32_t>* new_labels); + + // Returns the affinity score between targets identified by |old_key| and + // |new_keys|. Affinity > 0 means an association is likely, < 0 means + // incompatible association, and 0 means neither targets have been associated. + double AffinityBetween(key_t old_key, key_t new_key) const; + + private: + struct Association { + key_t other = 0; + double affinity = 0.0; + }; + + // Forward and backward associations between old and new targets. For each + // Association element, if |affinity == 0.0| then no association is defined + // (and |other| is meaningless|. Otherwise |affinity > 0.0|, and the + // association between |old_labels[old_key]| and |new_labels[new_key]| is + // represented by: + // forward_association_[old_key].other == new_key; + // backward_association_[new_key].other == old_key; + // forward_association_[old_key].affinity == + // backward_association_[new_key].affinity; + // The two lists contain the same information, but having both enables quick + // lookup, given |old_key| or |new_key|. + std::vector<Association> forward_association_; + std::vector<Association> backward_association_; + + DISALLOW_COPY_AND_ASSIGN(TargetsAffinity); +}; + +} // namespace zucchini + +#endif // COMPONENTS_ZUCCHINI_TARGETS_AFFINITY_H_ |