OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 library kernel.type_propagation.canonicalizer; | 4 library kernel.type_propagation.canonicalizer; |
5 | 5 |
6 import 'dart:collection'; | 6 import 'dart:collection'; |
7 | 7 |
8 /// Generates unique consecutive integer IDs for tuples of variable length. | 8 /// Generates unique consecutive integer IDs for tuples of variable length. |
9 class TupleCanonicalizer { | 9 class TupleCanonicalizer { |
10 final HashMap<List<Object>, int> _table = new HashMap<List<Object>, int>( | 10 final HashMap<List<Object>, int> _table = new HashMap<List<Object>, int>( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 | 93 |
94 /// Associates [value] with the pair previously queried using [lookup]. | 94 /// Associates [value] with the pair previously queried using [lookup]. |
95 void put(T value) { | 95 void put(T value) { |
96 _table[_key] = value; | 96 _table[_key] = value; |
97 } | 97 } |
98 | 98 |
99 Iterable<T> get values => _table.values; | 99 Iterable<T> get values => _table.values; |
100 | 100 |
101 static int _bigintHash(int bigint) { | 101 static int _bigintHash(int bigint) { |
102 » int x = 0x3fffffff & (bigint >> 31); | 102 int x = 0x3fffffff & (bigint >> 31); |
103 » int y = 0x3fffffff & bigint; | 103 int y = 0x3fffffff & bigint; |
104 int hash = 0x3fffffff & (x * 1367); | 104 int hash = 0x3fffffff & (x * 1367); |
105 hash = 0x3fffffff & (y * 31 + hash ^ y); | 105 hash = 0x3fffffff & (y * 31 + hash ^ y); |
106 hash = 0x3fffffff & ((x ^ y) * 31 + hash ^ y); | 106 hash = 0x3fffffff & ((x ^ y) * 31 + hash ^ y); |
107 return hash; | 107 return hash; |
108 } | 108 } |
109 } | 109 } |
OLD | NEW |