From d244c1f6a59c78ff57756998292002407bcac0e5 Mon Sep 17 00:00:00 2001 From: Christien Rioux Date: Sat, 24 Feb 2024 11:43:00 -0500 Subject: [PATCH] fix overzealous gitignore and organize flutter a bit --- .gitignore | 167 +---------------- veilid-flutter/lib/routing_context.dart | 53 ------ .../lib/routing_context.freezed.dart | 154 ---------------- veilid-flutter/lib/routing_context.g.dart | 12 -- veilid-flutter/lib/value_subkey_range.dart | 110 ++++++++++++ .../lib/value_subkey_range.freezed.dart | 169 ++++++++++++++++++ veilid-flutter/lib/value_subkey_range.g.dart | 19 ++ veilid-flutter/lib/veilid.dart | 1 + veilid-python/.gitignore | 1 + 9 files changed, 301 insertions(+), 385 deletions(-) create mode 100644 veilid-flutter/lib/value_subkey_range.dart create mode 100644 veilid-flutter/lib/value_subkey_range.freezed.dart create mode 100644 veilid-flutter/lib/value_subkey_range.g.dart diff --git a/.gitignore b/.gitignore index 19f747b6..e1c9c94a 100644 --- a/.gitignore +++ b/.gitignore @@ -66,172 +66,7 @@ flamegraph.svg perf.data perf.data.old -############################################################################## -### Python - -# Byte-compiled / optimized / DLL files -__pycache__/ -*.py[cod] -*$py.class - -# C extensions -*.so - -# Distribution / packaging -.Python -build/ -develop-eggs/ -dist/ -downloads/ -eggs/ -.eggs/ -lib/ -lib64/ -parts/ -sdist/ -var/ -wheels/ -share/python-wheels/ -*.egg-info/ -.installed.cfg -*.egg -MANIFEST - -# PyInstaller -# Usually these files are written by a python script from a template -# before PyInstaller builds the exe, so as to inject date/other infos into it. -*.manifest -*.spec - -# Installer logs -pip-log.txt -pip-delete-this-directory.txt - -# Unit test / coverage reports -htmlcov/ -.tox/ -.nox/ -.coverage -.coverage.* -.cache -nosetests.xml -coverage.xml -*.cover -*.py,cover -.hypothesis/ -.pytest_cache/ -cover/ - -# Translations -*.mo -*.pot - -# Django stuff: -*.log -local_settings.py -db.sqlite3 -db.sqlite3-journal - -# Flask stuff: -instance/ -.webassets-cache - -# Scrapy stuff: -.scrapy - -# Sphinx documentation -docs/_build/ - -# PyBuilder -.pybuilder/ -target/ - -# Jupyter Notebook -.ipynb_checkpoints - -# IPython -profile_default/ -ipython_config.py - -# pyenv -# For a library or package, you might want to ignore these files since the code is -# intended to run in multiple environments; otherwise, check them in: -# .python-version - -# pipenv -# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. -# However, in case of collaboration, if having platform-specific dependencies or dependencies -# having no cross-platform support, pipenv may install dependencies that don't work, or not -# install all needed dependencies. -#Pipfile.lock - -# poetry -# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. -# This is especially recommended for binary packages to ensure reproducibility, and is more -# commonly ignored for libraries. -# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control -#poetry.lock - -# pdm -# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. -#pdm.lock -# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it -# in version control. -# https://pdm.fming.dev/#use-with-ide -.pdm.toml - -# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm -__pypackages__/ - -# Celery stuff -celerybeat-schedule -celerybeat.pid - -# SageMath parsed files -*.sage.py - -# Environments -.env -.venv -env/ -venv/ -ENV/ -env.bak/ -venv.bak/ - -# Spyder project settings -.spyderproject -.spyproject - -# Rope project settings -.ropeproject - -# mkdocs documentation -/site - -# mypy -.mypy_cache/ -.dmypy.json -dmypy.json - -# Pyre type checker -.pyre/ - -# pytype static type analyzer -.pytype/ - -# Cython debug symbols -cython_debug/ - -# PyCharm -# JetBrains specific template is maintained in a separate JetBrains.gitignore that can -# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore -# and can be added to the global gitignore or merged into this file. For a more nuclear -# option (not recommended) you can uncomment the following to ignore the entire idea folder. -#.idea/ - -## Custom for veilid-python -veilid-python/demo/.demokeys +################################### .vscode/ .idea/ diff --git a/veilid-flutter/lib/routing_context.dart b/veilid-flutter/lib/routing_context.dart index 996408ac..92a9818f 100644 --- a/veilid-flutter/lib/routing_context.dart +++ b/veilid-flutter/lib/routing_context.dart @@ -123,59 +123,6 @@ extension DHTRecordDescriptorExt on DHTRecordDescriptor { } } -////////////////////////////////////// -/// ValueSubkeyRange - -@freezed -class ValueSubkeyRange with _$ValueSubkeyRange { - @Assert('low >= 0 && low <= high', 'range is invalid') - const factory ValueSubkeyRange({ - required int low, - required int high, - }) = _ValueSubkeyRange; - - factory ValueSubkeyRange.single(int val) => - ValueSubkeyRange(low: val, high: val); - - factory ValueSubkeyRange.fromJson(dynamic json) => - _$ValueSubkeyRangeFromJson(json as Map); -} - -extension ValueSubkeyRangeExt on ValueSubkeyRange { - bool contains(int v) => low <= v && v <= high; - List remove(int v) { - if (v < low || v > high) { - return [this]; - } - if (v == low) { - if (v == high) { - return []; - } else { - return [ValueSubkeyRange(low: v + 1, high: high)]; - } - } else if (v == high) { - return [ValueSubkeyRange(low: low, high: v - 1)]; - } else { - return [ - ValueSubkeyRange(low: low, high: v - 1), - ValueSubkeyRange(low: v + 1, high: high) - ]; - } - } -} - -extension ListValueSubkeyRangeExt on List { - bool containsSubkey(int v) => indexWhere((e) => e.contains(v)) != -1; - List removeSubkey(int v) { - for (var i = 0; i < length; i++) { - if (this[i].contains(v)) { - return [...sublist(0, i), ...this[i].remove(v), ...sublist(i + 1)]; - } - } - return this; - } -} - ////////////////////////////////////// /// ValueData diff --git a/veilid-flutter/lib/routing_context.freezed.dart b/veilid-flutter/lib/routing_context.freezed.dart index 2640f0e3..ff438784 100644 --- a/veilid-flutter/lib/routing_context.freezed.dart +++ b/veilid-flutter/lib/routing_context.freezed.dart @@ -807,160 +807,6 @@ abstract class _DHTRecordDescriptor implements DHTRecordDescriptor { throw _privateConstructorUsedError; } -ValueSubkeyRange _$ValueSubkeyRangeFromJson(Map json) { - return _ValueSubkeyRange.fromJson(json); -} - -/// @nodoc -mixin _$ValueSubkeyRange { - int get low => throw _privateConstructorUsedError; - int get high => throw _privateConstructorUsedError; - - Map toJson() => throw _privateConstructorUsedError; - @JsonKey(ignore: true) - $ValueSubkeyRangeCopyWith get copyWith => - throw _privateConstructorUsedError; -} - -/// @nodoc -abstract class $ValueSubkeyRangeCopyWith<$Res> { - factory $ValueSubkeyRangeCopyWith( - ValueSubkeyRange value, $Res Function(ValueSubkeyRange) then) = - _$ValueSubkeyRangeCopyWithImpl<$Res, ValueSubkeyRange>; - @useResult - $Res call({int low, int high}); -} - -/// @nodoc -class _$ValueSubkeyRangeCopyWithImpl<$Res, $Val extends ValueSubkeyRange> - implements $ValueSubkeyRangeCopyWith<$Res> { - _$ValueSubkeyRangeCopyWithImpl(this._value, this._then); - - // ignore: unused_field - final $Val _value; - // ignore: unused_field - final $Res Function($Val) _then; - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? low = null, - Object? high = null, - }) { - return _then(_value.copyWith( - low: null == low - ? _value.low - : low // ignore: cast_nullable_to_non_nullable - as int, - high: null == high - ? _value.high - : high // ignore: cast_nullable_to_non_nullable - as int, - ) as $Val); - } -} - -/// @nodoc -abstract class _$$_ValueSubkeyRangeCopyWith<$Res> - implements $ValueSubkeyRangeCopyWith<$Res> { - factory _$$_ValueSubkeyRangeCopyWith( - _$_ValueSubkeyRange value, $Res Function(_$_ValueSubkeyRange) then) = - __$$_ValueSubkeyRangeCopyWithImpl<$Res>; - @override - @useResult - $Res call({int low, int high}); -} - -/// @nodoc -class __$$_ValueSubkeyRangeCopyWithImpl<$Res> - extends _$ValueSubkeyRangeCopyWithImpl<$Res, _$_ValueSubkeyRange> - implements _$$_ValueSubkeyRangeCopyWith<$Res> { - __$$_ValueSubkeyRangeCopyWithImpl( - _$_ValueSubkeyRange _value, $Res Function(_$_ValueSubkeyRange) _then) - : super(_value, _then); - - @pragma('vm:prefer-inline') - @override - $Res call({ - Object? low = null, - Object? high = null, - }) { - return _then(_$_ValueSubkeyRange( - low: null == low - ? _value.low - : low // ignore: cast_nullable_to_non_nullable - as int, - high: null == high - ? _value.high - : high // ignore: cast_nullable_to_non_nullable - as int, - )); - } -} - -/// @nodoc -@JsonSerializable() -class _$_ValueSubkeyRange implements _ValueSubkeyRange { - const _$_ValueSubkeyRange({required this.low, required this.high}) - : assert(low >= 0 && low <= high, 'range is invalid'); - - factory _$_ValueSubkeyRange.fromJson(Map json) => - _$$_ValueSubkeyRangeFromJson(json); - - @override - final int low; - @override - final int high; - - @override - String toString() { - return 'ValueSubkeyRange(low: $low, high: $high)'; - } - - @override - bool operator ==(dynamic other) { - return identical(this, other) || - (other.runtimeType == runtimeType && - other is _$_ValueSubkeyRange && - (identical(other.low, low) || other.low == low) && - (identical(other.high, high) || other.high == high)); - } - - @JsonKey(ignore: true) - @override - int get hashCode => Object.hash(runtimeType, low, high); - - @JsonKey(ignore: true) - @override - @pragma('vm:prefer-inline') - _$$_ValueSubkeyRangeCopyWith<_$_ValueSubkeyRange> get copyWith => - __$$_ValueSubkeyRangeCopyWithImpl<_$_ValueSubkeyRange>(this, _$identity); - - @override - Map toJson() { - return _$$_ValueSubkeyRangeToJson( - this, - ); - } -} - -abstract class _ValueSubkeyRange implements ValueSubkeyRange { - const factory _ValueSubkeyRange( - {required final int low, required final int high}) = _$_ValueSubkeyRange; - - factory _ValueSubkeyRange.fromJson(Map json) = - _$_ValueSubkeyRange.fromJson; - - @override - int get low; - @override - int get high; - @override - @JsonKey(ignore: true) - _$$_ValueSubkeyRangeCopyWith<_$_ValueSubkeyRange> get copyWith => - throw _privateConstructorUsedError; -} - ValueData _$ValueDataFromJson(Map json) { return _ValueData.fromJson(json); } diff --git a/veilid-flutter/lib/routing_context.g.dart b/veilid-flutter/lib/routing_context.g.dart index d76ff703..2b540a4c 100644 --- a/veilid-flutter/lib/routing_context.g.dart +++ b/veilid-flutter/lib/routing_context.g.dart @@ -66,18 +66,6 @@ Map _$$_DHTRecordDescriptorToJson( 'owner_secret': instance.ownerSecret?.toJson(), }; -_$_ValueSubkeyRange _$$_ValueSubkeyRangeFromJson(Map json) => - _$_ValueSubkeyRange( - low: json['low'] as int, - high: json['high'] as int, - ); - -Map _$$_ValueSubkeyRangeToJson(_$_ValueSubkeyRange instance) => - { - 'low': instance.low, - 'high': instance.high, - }; - _$_ValueData _$$_ValueDataFromJson(Map json) => _$_ValueData( seq: json['seq'] as int, data: const Uint8ListJsonConverter.jsIsArray().fromJson(json['data']), diff --git a/veilid-flutter/lib/value_subkey_range.dart b/veilid-flutter/lib/value_subkey_range.dart new file mode 100644 index 00000000..510034cd --- /dev/null +++ b/veilid-flutter/lib/value_subkey_range.dart @@ -0,0 +1,110 @@ +import 'dart:math'; + +import 'package:freezed_annotation/freezed_annotation.dart'; + +part 'value_subkey_range.freezed.dart'; +part 'value_subkey_range.g.dart'; + +@freezed +class ValueSubkeyRange with _$ValueSubkeyRange { + @Assert('low >= 0 && low <= high', 'range is invalid') + const factory ValueSubkeyRange({ + required int low, + required int high, + }) = _ValueSubkeyRange; + + factory ValueSubkeyRange.single(int val) => + ValueSubkeyRange(low: val, high: val); + + factory ValueSubkeyRange.fromJson(dynamic json) => + _$ValueSubkeyRangeFromJson(json as Map); +} + +extension ValueSubkeyRangeExt on ValueSubkeyRange { + bool contains(int v) => low <= v && v <= high; + List remove(int v) { + if (v < low || v > high) { + return [ValueSubkeyRange(low: low, high: high)]; + } + if (v == low) { + if (v == high) { + return []; + } else { + return [ValueSubkeyRange(low: v + 1, high: high)]; + } + } else if (v == high) { + return [ValueSubkeyRange(low: low, high: v - 1)]; + } else { + return [ + ValueSubkeyRange(low: low, high: v - 1), + ValueSubkeyRange(low: v + 1, high: high) + ]; + } + } + + ValueSubkeyRange? intersect(ValueSubkeyRange other) { + if (high < other.low || low > other.high) { + return null; + } + return ValueSubkeyRange( + low: max(low, other.low), high: min(high, other.high)); + } +} + +extension ListValueSubkeyRangeExt on List { + void validate() { + int? lastHigh; + for (final r in this) { + assert(lastHigh == null || r.low > lastHigh, + 'subrange not in order or disjoint'); + lastHigh = r.high; + } + } + + bool containsSubkey(int v) => indexWhere((e) => e.contains(v)) != -1; + List removeSubkey(int v) { + for (var i = 0; i < length; i++) { + if (this[i].contains(v)) { + return [...sublist(0, i), ...this[i].remove(v), ...sublist(i + 1)]; + } + } + return toList(); + } + + int? get firstSubkey => isNotEmpty ? first.low : null; + + List intersectSubkeys(List other) { + final out = []; + for (var i = 0, j = 0; i < length && j < other.length;) { + final vsrThis = this[i]; + final vsrOther = other[j]; + if (vsrThis.high < vsrOther.low) { + i++; + continue; + } + if (vsrOther.high < vsrThis.low) { + j++; + continue; + } + + // Otherwise we intersect + out.add(vsrThis.intersect(vsrOther)!); + + // Iterate whichever has a lower high + // If they both have the same high then both ranges are exhausted + // and should be iterated + if (vsrThis.high < vsrOther.high) { + // Iterate this because other could still have some overlaps + i++; + } else if (vsrThis.high == vsrOther.high) { + // Iterate both because both ranges are exhausted + i++; + j++; + } else { + // Iterate other because this could still have some overlaps + j++; + } + } + return out; + } +} diff --git a/veilid-flutter/lib/value_subkey_range.freezed.dart b/veilid-flutter/lib/value_subkey_range.freezed.dart new file mode 100644 index 00000000..549220a8 --- /dev/null +++ b/veilid-flutter/lib/value_subkey_range.freezed.dart @@ -0,0 +1,169 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'value_subkey_range.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +ValueSubkeyRange _$ValueSubkeyRangeFromJson(Map json) { + return _ValueSubkeyRange.fromJson(json); +} + +/// @nodoc +mixin _$ValueSubkeyRange { + int get low => throw _privateConstructorUsedError; + int get high => throw _privateConstructorUsedError; + + Map toJson() => throw _privateConstructorUsedError; + @JsonKey(ignore: true) + $ValueSubkeyRangeCopyWith get copyWith => + throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $ValueSubkeyRangeCopyWith<$Res> { + factory $ValueSubkeyRangeCopyWith( + ValueSubkeyRange value, $Res Function(ValueSubkeyRange) then) = + _$ValueSubkeyRangeCopyWithImpl<$Res, ValueSubkeyRange>; + @useResult + $Res call({int low, int high}); +} + +/// @nodoc +class _$ValueSubkeyRangeCopyWithImpl<$Res, $Val extends ValueSubkeyRange> + implements $ValueSubkeyRangeCopyWith<$Res> { + _$ValueSubkeyRangeCopyWithImpl(this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? low = null, + Object? high = null, + }) { + return _then(_value.copyWith( + low: null == low + ? _value.low + : low // ignore: cast_nullable_to_non_nullable + as int, + high: null == high + ? _value.high + : high // ignore: cast_nullable_to_non_nullable + as int, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$_ValueSubkeyRangeCopyWith<$Res> + implements $ValueSubkeyRangeCopyWith<$Res> { + factory _$$_ValueSubkeyRangeCopyWith( + _$_ValueSubkeyRange value, $Res Function(_$_ValueSubkeyRange) then) = + __$$_ValueSubkeyRangeCopyWithImpl<$Res>; + @override + @useResult + $Res call({int low, int high}); +} + +/// @nodoc +class __$$_ValueSubkeyRangeCopyWithImpl<$Res> + extends _$ValueSubkeyRangeCopyWithImpl<$Res, _$_ValueSubkeyRange> + implements _$$_ValueSubkeyRangeCopyWith<$Res> { + __$$_ValueSubkeyRangeCopyWithImpl( + _$_ValueSubkeyRange _value, $Res Function(_$_ValueSubkeyRange) _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? low = null, + Object? high = null, + }) { + return _then(_$_ValueSubkeyRange( + low: null == low + ? _value.low + : low // ignore: cast_nullable_to_non_nullable + as int, + high: null == high + ? _value.high + : high // ignore: cast_nullable_to_non_nullable + as int, + )); + } +} + +/// @nodoc +@JsonSerializable() +class _$_ValueSubkeyRange implements _ValueSubkeyRange { + const _$_ValueSubkeyRange({required this.low, required this.high}) + : assert(low >= 0 && low <= high, 'range is invalid'); + + factory _$_ValueSubkeyRange.fromJson(Map json) => + _$$_ValueSubkeyRangeFromJson(json); + + @override + final int low; + @override + final int high; + + @override + String toString() { + return 'ValueSubkeyRange(low: $low, high: $high)'; + } + + @override + bool operator ==(dynamic other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other is _$_ValueSubkeyRange && + (identical(other.low, low) || other.low == low) && + (identical(other.high, high) || other.high == high)); + } + + @JsonKey(ignore: true) + @override + int get hashCode => Object.hash(runtimeType, low, high); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$_ValueSubkeyRangeCopyWith<_$_ValueSubkeyRange> get copyWith => + __$$_ValueSubkeyRangeCopyWithImpl<_$_ValueSubkeyRange>(this, _$identity); + + @override + Map toJson() { + return _$$_ValueSubkeyRangeToJson( + this, + ); + } +} + +abstract class _ValueSubkeyRange implements ValueSubkeyRange { + const factory _ValueSubkeyRange( + {required final int low, required final int high}) = _$_ValueSubkeyRange; + + factory _ValueSubkeyRange.fromJson(Map json) = + _$_ValueSubkeyRange.fromJson; + + @override + int get low; + @override + int get high; + @override + @JsonKey(ignore: true) + _$$_ValueSubkeyRangeCopyWith<_$_ValueSubkeyRange> get copyWith => + throw _privateConstructorUsedError; +} diff --git a/veilid-flutter/lib/value_subkey_range.g.dart b/veilid-flutter/lib/value_subkey_range.g.dart new file mode 100644 index 00000000..1b9e7384 --- /dev/null +++ b/veilid-flutter/lib/value_subkey_range.g.dart @@ -0,0 +1,19 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'value_subkey_range.dart'; + +// ************************************************************************** +// JsonSerializableGenerator +// ************************************************************************** + +_$_ValueSubkeyRange _$$_ValueSubkeyRangeFromJson(Map json) => + _$_ValueSubkeyRange( + low: json['low'] as int, + high: json['high'] as int, + ); + +Map _$$_ValueSubkeyRangeToJson(_$_ValueSubkeyRange instance) => + { + 'low': instance.low, + 'high': instance.high, + }; diff --git a/veilid-flutter/lib/veilid.dart b/veilid-flutter/lib/veilid.dart index e17ec7e9..0d600c5d 100644 --- a/veilid-flutter/lib/veilid.dart +++ b/veilid-flutter/lib/veilid.dart @@ -18,6 +18,7 @@ import 'veilid_table_db.dart'; export 'default_config.dart'; export 'routing_context.dart'; +export 'value_subkey_range.dart'; export 'veilid.dart'; export 'veilid_api_exception.dart'; export 'veilid_config.dart'; diff --git a/veilid-python/.gitignore b/veilid-python/.gitignore index 4b069ebc..7b0b9462 100644 --- a/veilid-python/.gitignore +++ b/veilid-python/.gitignore @@ -158,3 +158,4 @@ cython_debug/ # and can be added to the global gitignore or merged into this file. For a more nuclear # option (not recommended) you can uncomment the following to ignore the entire idea folder. #.idea/ +