diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /tools/build/src/util/sequence.py | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'tools/build/src/util/sequence.py')
-rw-r--r-- | tools/build/src/util/sequence.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/build/src/util/sequence.py b/tools/build/src/util/sequence.py new file mode 100644 index 0000000000..1d32efd2e3 --- /dev/null +++ b/tools/build/src/util/sequence.py @@ -0,0 +1,50 @@ +# (C) Copyright David Abrahams 2002. Permission to copy, use, modify, sell and +# distribute this software is granted provided this copyright notice appears in +# all copies. This software is provided "as is" without express or implied +# warranty, and with no claim as to its suitability for any purpose. + +import operator + +def unique (values, stable=False): + if stable: + s = set() + r = [] + for v in values: + if not v in s: + r.append(v) + s.add(v) + return r + else: + return list(set(values)) + +def max_element (elements, ordered = None): + """ Returns the maximum number in 'elements'. Uses 'ordered' for comparisons, + or '<' is none is provided. + """ + if not ordered: ordered = operator.lt + + max = elements [0] + for e in elements [1:]: + if ordered (max, e): + max = e + + return max + +def select_highest_ranked (elements, ranks): + """ Returns all of 'elements' for which corresponding element in parallel + list 'rank' is equal to the maximum value in 'rank'. + """ + if not elements: + return [] + + max_rank = max_element (ranks) + + result = [] + while elements: + if ranks [0] == max_rank: + result.append (elements [0]) + + elements = elements [1:] + ranks = ranks [1:] + + return result |