@@ -4,17 +4,23 @@ import {
4
4
KeyedCollection ,
5
5
SetCollection ,
6
6
} from './Collection' ;
7
- import { hash } from './Hash' ;
7
+ import {
8
+ defaultNegComparator ,
9
+ entryMapper ,
10
+ keyMapper ,
11
+ neg ,
12
+ not ,
13
+ reduce ,
14
+ } from './CollectionHelperMethods' ;
8
15
import {
9
16
ITERATE_ENTRIES ,
10
17
ITERATE_KEYS ,
11
18
ITERATE_VALUES ,
12
- ITERATOR_SYMBOL ,
13
19
Iterator ,
20
+ ITERATOR_SYMBOL ,
14
21
} from './Iterator' ;
15
22
import { List } from './List' ;
16
23
import { Map } from './Map' ;
17
- import { imul , smi } from './Math' ;
18
24
import {
19
25
FromEntriesSequence ,
20
26
ToIndexedSequence ,
@@ -59,11 +65,12 @@ import { toObject } from './methods/toObject';
59
65
import { IS_COLLECTION_SYMBOL } from './predicates/isCollection' ;
60
66
import { isIndexed , IS_INDEXED_SYMBOL } from './predicates/isIndexed' ;
61
67
import { isKeyed , IS_KEYED_SYMBOL } from './predicates/isKeyed' ;
62
- import { isOrdered , IS_ORDERED_SYMBOL } from './predicates/isOrdered' ;
68
+ import { IS_ORDERED_SYMBOL } from './predicates/isOrdered' ;
63
69
import { toJS } from './toJS' ;
64
70
import arrCopy from './utils/arrCopy' ;
65
71
import assertNotInfinite from './utils/assertNotInfinite' ;
66
72
import deepEqual from './utils/deepEqual' ;
73
+ import { hashCollection } from './utils/hasCollection' ;
67
74
import mixin from './utils/mixin' ;
68
75
import quoteString from './utils/quoteString' ;
69
76
@@ -701,87 +708,6 @@ mixin(SetSeq, SetCollectionPrototype);
701
708
702
709
// #pragma Helper functions
703
710
704
- function reduce ( collection , reducer , reduction , context , useFirst , reverse ) {
705
- assertNotInfinite ( collection . size ) ;
706
- collection . __iterate ( ( v , k , c ) => {
707
- if ( useFirst ) {
708
- useFirst = false ;
709
- reduction = v ;
710
- } else {
711
- reduction = reducer . call ( context , reduction , v , k , c ) ;
712
- }
713
- } , reverse ) ;
714
- return reduction ;
715
- }
716
-
717
- function keyMapper ( v , k ) {
718
- return k ;
719
- }
720
-
721
- function entryMapper ( v , k ) {
722
- return [ k , v ] ;
723
- }
724
-
725
- function not ( predicate ) {
726
- return function ( ) {
727
- return ! predicate . apply ( this , arguments ) ;
728
- } ;
729
- }
730
-
731
- function neg ( predicate ) {
732
- return function ( ) {
733
- return - predicate . apply ( this , arguments ) ;
734
- } ;
735
- }
736
-
737
711
function defaultZipper ( ) {
738
712
return arrCopy ( arguments ) ;
739
713
}
740
-
741
- function defaultNegComparator ( a , b ) {
742
- return a < b ? 1 : a > b ? - 1 : 0 ;
743
- }
744
-
745
- function hashCollection ( collection ) {
746
- if ( collection . size === Infinity ) {
747
- return 0 ;
748
- }
749
- const ordered = isOrdered ( collection ) ;
750
- const keyed = isKeyed ( collection ) ;
751
- let h = ordered ? 1 : 0 ;
752
-
753
- collection . __iterate (
754
- keyed
755
- ? ordered
756
- ? ( v , k ) => {
757
- h = ( 31 * h + hashMerge ( hash ( v ) , hash ( k ) ) ) | 0 ;
758
- }
759
- : ( v , k ) => {
760
- h = ( h + hashMerge ( hash ( v ) , hash ( k ) ) ) | 0 ;
761
- }
762
- : ordered
763
- ? ( v ) => {
764
- h = ( 31 * h + hash ( v ) ) | 0 ;
765
- }
766
- : ( v ) => {
767
- h = ( h + hash ( v ) ) | 0 ;
768
- }
769
- ) ;
770
-
771
- return murmurHashOfSize ( collection . size , h ) ;
772
- }
773
-
774
- function murmurHashOfSize ( size , h ) {
775
- h = imul ( h , 0xcc9e2d51 ) ;
776
- h = imul ( ( h << 15 ) | ( h >>> - 15 ) , 0x1b873593 ) ;
777
- h = imul ( ( h << 13 ) | ( h >>> - 13 ) , 5 ) ;
778
- h = ( ( h + 0xe6546b64 ) | 0 ) ^ size ;
779
- h = imul ( h ^ ( h >>> 16 ) , 0x85ebca6b ) ;
780
- h = imul ( h ^ ( h >>> 13 ) , 0xc2b2ae35 ) ;
781
- h = smi ( h ^ ( h >>> 16 ) ) ;
782
- return h ;
783
- }
784
-
785
- function hashMerge ( a , b ) {
786
- return ( a ^ ( b + 0x9e3779b9 + ( a << 6 ) + ( a >> 2 ) ) ) | 0 ; // int
787
- }
0 commit comments