1 # Copyright 2015 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 6 import collections 7 8 9 def checksum_counts(checksums): 10 """ 11 @param checksums: list of checksums, each checksum in a 4-tuple of ints 12 @returns a dictionary of checksums as keys mapped to their respective 13 count of occurance in the list. 14 15 """ 16 counts = {} 17 18 for checksum in checksums: 19 if checksum in counts: 20 counts[checksum] += 1 21 else: 22 counts[checksum] = 1 23 24 return counts 25 26 27 def checksum_indices(checksums): 28 """ 29 @param checksums: list of checksums. 30 @returns an OrderedDict containing checksums as keys and their respective 31 first-occurance indices as values 32 33 """ 34 35 d = collections.OrderedDict() 36 37 for i, checksum in enumerate(checksums): 38 if checksum not in d: 39 d[checksum] = i 40 41 return d