fromJson static method
Reconstruct an LshIndex from toJson output.
Implementation
static LshIndex fromJson(Map<String, Object?> j) {
final dim = (j['dim'] as num).toInt();
final nbits = (j['nbits'] as num?)?.toInt() ?? 64;
final seed = (j['seed'] as num?)?.toInt() ?? 1234;
final idx = LshIndex(dim, nbits: nbits, seed: seed);
final ids = (j['ids'] as List).cast<Object?>();
final codes = base64.decode(j['codes'] as String);
if (codes.length != ids.length * idx.codeSize) {
throw FormatException(
'LshIndex.fromJson: codes length ${codes.length} '
'!= ids ${ids.length} * codeSize ${idx.codeSize}',
);
}
idx._codes = Uint8List.fromList(codes);
idx._ids.addAll(ids);
return idx;
}