diff --git a/sugar/lib/crdt.dart b/sugar/lib/crdt.dart index 18bcebe5..481411e8 100644 --- a/sugar/lib/crdt.dart +++ b/sugar/lib/crdt.dart @@ -1,2 +1 @@ export 'src/crdt/string_index.dart'; -export 'src/crdt/string_indexed_list.dart'; diff --git a/sugar/lib/src/crdt/string_index.dart b/sugar/lib/src/crdt/string_index.dart index 9a09d4d5..8fd7a804 100644 --- a/sugar/lib/src/crdt/string_index.dart +++ b/sugar/lib/src/crdt/string_index.dart @@ -19,12 +19,6 @@ import 'package:sugar/sugar.dart'; /// /// It is still possible for two equivalent indexes without any empty space in-between to be generated concurrently. It /// is impossible for the functions in [StringIndex] to prevent that. Such situations should be handled during merging instead. -/// -/// ## The `strict` flag -/// In the original closed-source implementation, the allowed character set contained `/` instead of `-`. To maintain -/// backwards-compatibility, most functions accept a `strict` flag which disables index format validation. -/// -/// External users are discouraged from enabling the `lenient` flag. extension StringIndex on Never { /// A regular expression that denotes a string index's expected format. @@ -36,7 +30,6 @@ extension StringIndex on Never { static const max = 'z'; /// The allow character set in a SIL index. static const ascii = [ - // The original implementation used / instead of -, however this made working with URLs/escaping troublesome. 43, 45, // +, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, // 0 - 9 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, // A - Z @@ -48,17 +41,11 @@ extension StringIndex on Never { /// Generates a new SIL index between the given [min], inclusive, and [max], exclusive. /// - /// ## The `strict` flag - /// In the original closed-source implementation, the allowed character set contained `/` instead of `-`. To maintain - /// backwards-compatibility, [between] ] accept a [strict] flag which disables index format validation. - /// /// ## Contract - /// An [ArgumentError] is thrown if - /// * [max] <= [min] - /// * [strict] is true and either [min] or [max] is not a valid SIL index + /// An [ArgumentError] is thrown if [max] <= [min]. @Possible({ArgumentError}) - static String between({String min = min, String max = max, bool strict = true}) { - _validate(min, max, strict: strict); + static String between({String min = min, String max = max}) { + _validate(min, max); final index = StringBuffer(); for (var i = 0; ; i++) { @@ -81,12 +68,12 @@ extension StringIndex on Never { } } - static void _validate(String min, String max, {required bool strict}) { - if (strict && !min.matches(format)) { + static void _validate(String min, String max) { + if (!min.matches(format)) { throw ArgumentError('Invalid minimum string index: $min, should follow the format: ${format.pattern}.'); } - if (strict && !max.matches(format)) { + if (!max.matches(format)) { throw ArgumentError('Invalid maximum string index: $max, should follow the format: ${format.pattern}.'); } diff --git a/sugar/lib/src/crdt/string_indexed_list.dart b/sugar/lib/src/crdt/string_indexed_list.dart deleted file mode 100644 index 490e1615..00000000 --- a/sugar/lib/src/crdt/string_indexed_list.dart +++ /dev/null @@ -1,78 +0,0 @@ -import 'dart:collection'; - -import 'package:sugar/sugar.dart'; - -class Sil extends Iterable { - - /// Whether to strictly validate a string index's format. True by default. - final bool strict; - - final SplayTreeMap _map; - final HashMap _inverse; - final List _list; - final bool Function(E, E) _equals; - final int Function(E) _hash; - - Sil._( - this._map, - this._inverse, - this._list, - this._equals, - this._hash, { - required this.strict, - }); - - - bool put(String index, E element) { - if (_inverse.containsKey(element)) { - return false; - } - - final old = _map[index]; - if (old == null) { - if (_map.firstValueAfter(index) case final after?) { - _list.insert(_list.indexWhere((e) => _equals(e, after)), element); - - } else { - _list.add(element); - } - - _map[index] = element; - _inverse[element] = index; - - } else { - _map[index] = element; - _inverse.remove(old); - _inverse[element] = index; - _list[_list.indexWhere((e) => _equals(e, old))] = element; - } - - return true; - } - - - int indexOf(E element) => _list.indexOf(element); - - String? stringIndexOf(E element) => _inverse[element]; - - - void operator []= (int index, E element) { - if (_inverse.containsKey(element)) { - return; - } - - final old = _list[index]; - final string = _inverse.remove(old)!; - - _map[string] = element; - _inverse[element] = string; - _list[index] = element; - } - - E operator [] (int index) => _list[index]; - - - @override - Iterator get iterator => _list.iterator; - -}