LCOV - code coverage report
Current view: top level - lib/util - hashable.dart (source / functions) Hit Total Coverage
Test: Folly Fields Lines: 18 18 100.0 %
Date: 2023-05-18 02:05:34 Functions: 0 0 -

          Line data    Source code
       1             : // ignore_for_file: binary-expression-operand-order
       2             : 
       3             : ///
       4             : ///
       5             : ///
       6             : mixin Hashable {
       7             :   ///
       8             :   ///
       9             :   ///
      10           6 :   int hashIterable(
      11             :     Iterable<dynamic> iterable,
      12             :     // { int deep = 1,
      13             :     // bool debug = false,}
      14             :   ) {
      15           6 :     int iterated = iterable.fold(
      16             :       0,
      17           6 :       (int h, dynamic i) {
      18             :         int hash;
      19           6 :         if (i is List) {
      20             :           // hash = hashIterable(i, deep: deep + 1, debug: debug);
      21           1 :           hash = hashIterable(i);
      22           6 :         } else if (i is Map) {
      23             :           // hash = hashIterable(i.values, deep: deep + 1, debug: debug);
      24           2 :           hash = hashIterable(i.values);
      25             :         } else if (i == null) {
      26             :           hash = 0;
      27             :         } else {
      28           6 :           hash = i.hashCode;
      29             :         }
      30             : 
      31             :         // int comb = combine(h, hash);
      32             :         //
      33             :         // if (debug) {
      34             :         //   if (kDebugMode) {
      35             :         //     print('${' ' * deep * 2}h: $h => '
      36             :         //         '(${i.runtimeType}) $i: $hash => comb: $comb');
      37             :         //   }
      38             :         // }
      39             :         //
      40             :         // return comb;
      41             : 
      42           6 :         return combine(h, hash);
      43             :       },
      44             :     );
      45             : 
      46             :     // int finished = finish(iterated);
      47             :     //
      48             :     // if (debug) {
      49             :     //   if (kDebugMode) {
      50             :     //     print('finish: $finished');
      51             :     //   }
      52             :     // }
      53             :     //
      54             :     // return finished;
      55           6 :     return finish(iterated);
      56             :   }
      57             : 
      58             :   ///
      59             :   ///
      60             :   ///
      61          11 :   int combine(int hash, int value) {
      62          22 :     hash = 0x1fffffff & (hash + value);
      63          44 :     hash = 0x1fffffff & (hash + ((0x0007ffff & hash) << 10));
      64             : 
      65          22 :     return hash ^ (hash >> 6);
      66             :   }
      67             : 
      68             :   ///
      69             :   ///
      70             :   ///
      71          11 :   int finish(int hash) {
      72          44 :     hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
      73          22 :     hash = hash ^ (hash >> 11);
      74             : 
      75          44 :     return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
      76             :   }
      77             : }

Generated by: LCOV version 1.14