cache_image.dart 679 B

1234567891011121314151617181920212223242526272829303132
  1. import 'package:isar/isar.dart';
  2. part 'cache_image.g.dart';
  3. @collection
  4. class CacheImage {
  5. String? md5;
  6. Id get isarId => fastHash(md5!);
  7. List<byte> image = List.empty();
  8. int? timestamp;
  9. List<byte> nonce = List.empty();
  10. String? ext;
  11. @Index()
  12. DateTime createTime = DateTime.now();
  13. /// 针对 Dart 字符串优化的 64 位哈希算法 FNV-1a
  14. static int fastHash(String string) {
  15. var hash = 0xcbf29ce484222325;
  16. var i = 0;
  17. while (i < string.length) {
  18. final codeUnit = string.codeUnitAt(i++);
  19. hash ^= codeUnit >> 8;
  20. hash *= 0x100000001b3;
  21. hash ^= codeUnit & 0xFF;
  22. hash *= 0x100000001b3;
  23. }
  24. return hash;
  25. }
  26. }