LCOV - code coverage report
Current view: top level - util - hashable.dart (source / functions) Hit Total Coverage
Test: Folly Fields Lines: 8 21 38.1 %
Date: 2023-04-01 18:13:35 Functions: 0 0 -

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

Generated by: LCOV version 1.14