diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3c8a157 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Files and directories created by pub. +.dart_tool/ +.packages + +# Conventional directory for build output. +build/ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..effe43c --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +## 1.0.0 + +- Initial version. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a307539 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +A simple command-line application. diff --git a/analysis_options.yaml b/analysis_options.yaml new file mode 100644 index 0000000..dee8927 --- /dev/null +++ b/analysis_options.yaml @@ -0,0 +1,30 @@ +# This file configures the static analysis results for your project (errors, +# warnings, and lints). +# +# This enables the 'recommended' set of lints from `package:lints`. +# This set helps identify many issues that may lead to problems when running +# or consuming Dart code, and enforces writing Dart using a single, idiomatic +# style and format. +# +# If you want a smaller set of lints you can change this to specify +# 'package:lints/core.yaml'. These are just the most critical lints +# (the recommended set includes the core lints). +# The core lints are also what is used by pub.dev for scoring packages. + +include: package:lints/recommended.yaml + +# Uncomment the following section to specify additional rules. + +# linter: +# rules: +# - camel_case_types + +# analyzer: +# exclude: +# - path/to/excluded/files/** + +# For more information about the core and recommended set of lints, see +# https://dart.dev/go/core-lints + +# For additional information about configuring this file, see +# https://dart.dev/guides/language/analysis-options diff --git a/bin/graphs0.dart b/bin/graphs0.dart new file mode 100644 index 0000000..10f90fc --- /dev/null +++ b/bin/graphs0.dart @@ -0,0 +1,17 @@ +import 'src/graph.dart'; + +void main(List arguments) { + Map x = {}; + x[1] = 5; + x[2] = 10; + var p = Dot.fromMap("Точка 1", 1, x); + p.addPath(3, 20); + var x1 = Graphs([p], true); + x1.printG(); + p.delPath(4); + x1.printG(); + /*var p2 = Dot("Точка 2", 2, x); + x1.addDot(p2); + x1.printG(); + x1.checkDots();*/ +} diff --git a/bin/src/graph.dart b/bin/src/graph.dart new file mode 100644 index 0000000..47804f2 --- /dev/null +++ b/bin/src/graph.dart @@ -0,0 +1,138 @@ +import 'dart:io'; + +class Point { + int i = -1; + int length = 0; +} + +class Dot { + // ignore: prefer_final_fields + String _name = ""; + int num = -1; + Map ln = {}; + + String getName() => _name; + void setName(String n) => _name = n; + bool hasConnection(int n) => ln.containsKey(n); + void addPath(int inp, int length) => ln[inp] = length; + void delPath(int n) => ln.removeWhere((key, value) => key == n); + void printD() { + stdout.write("$_name: №$num => "); + for (var i in ln.keys) { + stdout.write("$i|${ln[i]} "); + } + stdout.write("\n"); + } + + Dot(String name, int n, List num, List length) { + _name = name; + Map nw = {}; + if (num.length != length.length) { + print("Error in lists"); + } else { + for (var i = 0; i <= num.length; i++) { + nw[num[i]] = length[i]; + ln = nw; + } + } + } + + // Привязка к памяти + Dot.fromMap(String name, int n, Map l) { + _name = name; + num = n; + ln = l; + } + + // Копирование + Dot.clone(Dot a) { + _name = a._name; + num = a.num; + ln = a.ln; + } +} + +class Graphs { + int _amount = 0; + List _dots = []; + // ignore: prefer_final_fields + Map _nameTable = {}; + bool useLength = false; + bool doubleSided = false; + + Graphs(List d, bool useL) { + _dots = d; + useLength = useL; + _amount = _dots.length; + _syncNameTable(); + } + + void _syncNameTable() { + for (var i in _dots) { + _nameTable[i.num] = i.getName(); + } + } + + void _fixPathAfterInsert(Dot a) { + for (var i in a.ln.keys) { + if (!_dots[i].ln.containsKey(a.num)) _dots[i].addPath(i, a.ln[i]!); + } + } + + bool addDot(Dot a) { + if (getNumByName(a.getName()) != null) { + print("Dot name already in use. Change name or use addPath"); + return false; + } + _amount++; + a.num = _amount; + _dots.add(a); + _syncNameTable(); + if (doubleSided) _fixPathAfterInsert(a); + return true; + } + + bool checkDots() { + for (var a in _dots) { + for (var i in a.ln.keys) { + try { + if (!_dots[i].ln.containsKey(a.num)) { + print("Can't find $i"); + return false; + } + } catch (e) { + print( + "Can't find Dot ${i + 1} for path ${a.num}->${i + 1}. Exception $e"); + return false; + } + } + } + return true; + } + + //Getters + String? getNameByNum(int n) => _nameTable[n]; + int? getNumByName(String n) { + for (var i in _nameTable.keys) { + if (_nameTable[i] == n) return i; + } + return null; + } + + //Print info + void printG() { + if (doubleSided) { + print("Не ориентированный"); + } else { + print("Ориентированный"); + } + if (useLength) { + print("Взвешенный"); + } else { + print("Не взвешенный"); + } + for (var i in _dots) { + i.printD(); + } + } +} diff --git a/pubspec.lock b/pubspec.lock new file mode 100644 index 0000000..06a8eb1 --- /dev/null +++ b/pubspec.lock @@ -0,0 +1,12 @@ +# Generated by pub +# See https://dart.dev/tools/pub/glossary#lockfile +packages: + lints: + dependency: "direct dev" + description: + name: lints + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" +sdks: + dart: ">=2.15.0-178.0.dev <3.0.0" diff --git a/pubspec.yaml b/pubspec.yaml new file mode 100644 index 0000000..68d13da --- /dev/null +++ b/pubspec.yaml @@ -0,0 +1,14 @@ +name: graphs0 +description: A simple command-line application. +version: 1.0.0 +# homepage: https://www.example.com + +environment: + sdk: '>=2.15.0-178.0.dev <3.0.0' + + +# dependencies: +# path: ^1.8.0 + +dev_dependencies: + lints: ^1.0.0