| 1234567891011121314151617181920212223242526272829303132 |
- import 'package:isar/isar.dart';
- part 'cache_image.g.dart';
- @collection
- class CacheImage {
- String? md5;
- Id get isarId => fastHash(md5!);
- List<byte> image = List.empty();
- int? timestamp;
- List<byte> nonce = List.empty();
- String? ext;
- @Index()
- DateTime createTime = DateTime.now();
- /// 针对 Dart 字符串优化的 64 位哈希算法 FNV-1a
- static int fastHash(String string) {
- var hash = 0xcbf29ce484222325;
- var i = 0;
- while (i < string.length) {
- final codeUnit = string.codeUnitAt(i++);
- hash ^= codeUnit >> 8;
- hash *= 0x100000001b3;
- hash ^= codeUnit & 0xFF;
- hash *= 0x100000001b3;
- }
- return hash;
- }
- }
|