Compare commits

..

1 Commits
main ... rust

Author SHA1 Message Date
denis c9f6c25494 123 2024-01-06 00:16:58 +03:00
16 changed files with 101 additions and 513 deletions

6
.gitignore vendored
View File

@ -1,5 +1 @@
/target
dist
node_modules

5
.idea/.gitignore vendored
View File

@ -1,5 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/refdb.iml" filepath="$PROJECT_DIR$/.idea/refdb.iml" />
</modules>
</component>
</project>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

75
Cargo.lock generated Normal file
View File

@ -0,0 +1,75 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "getrandom"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe9006bed769170c11f845cf00c7c1e9092aeb3f268e007c3e760ac68008070f"
dependencies = [
"cfg-if",
"libc",
"wasi",
]
[[package]]
name = "libc"
version = "0.2.151"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "302d7ab3130588088d277783b1e2d2e10c9e9e4a16dd9050e6ec93fb3e7048f4"
[[package]]
name = "ppv-lite86"
version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "rand"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
dependencies = [
"libc",
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
dependencies = [
"getrandom",
]
[[package]]
name = "refdb"
version = "0.1.0"
dependencies = [
"rand",
]
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"

9
Cargo.toml Normal file
View File

@ -0,0 +1,9 @@
[package]
name = "refdb"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
rand = "0.8.5"

View File

@ -1,10 +0,0 @@
## Node
Узел, имеет атрибуты id, value, valueType
## Edge
Связь двух узлов, имеет атрибуты id, in_id, out_id
## Expression
Выражение

95
domain.d.ts vendored
View File

@ -1,95 +0,0 @@
type NodeValueType = {
Number: "number",
String: "string",
Map: "map",
Expression: "expression"
};
type ExpressionType = {
Count: "count",
Filter: "filter",
};
type Filter =
{
value: number,
predicate: "greatThat"
| "greatThatEqual"
| "lessThat"
| "lessThatEqual"
| "equal"
}
| {
value: string,
predicate: "include"
| "equal"
}
type CountWithExpression = {
type: ExpressionType["Count"],
expression: BaseNode["uuid"],
};
type CountWithSet = {
type: ExpressionType["Count"],
set: string,
};
type FilterWithExpression = {
type: ExpressionType["Filter"],
expression: BaseNode["uuid"],
filter: Filter,
};
type FilterWithSet = {
type: ExpressionType["Filter"],
set: string,
filter: Filter,
field: string,
};
type Expression =
CountWithExpression
| CountWithSet
| FilterWithExpression
| FilterWithSet;
type NumberNode = BaseNode & {
valueType: NodeValueType["Number"];
value: number;
};
type StringNode = BaseNode & {
valueType: NodeValueType["String"];
value: string;
};
type MapNode = BaseNode & {
valueType: NodeValueType["Map"];
value: { [key: string]: BaseNode["uuid"]; };
};
type ExpressionNode = BaseNode & {
valueType: NodeValueType["Expression"];
value: Expression;
id: string;
};
type BaseNode = {
uuid: string;
set: string;
};
type PrimitiveValue = string | number;
type MapValue = {
[key: string]: PrimitiveValue | MapValue;
}
type ExpressionResult = PrimitiveValue | MapValue | Array<PrimitiveValue | MapValue> | null;
type AddNodeParams = Omit<AnyNode, "uuid">;
type AnyNode = NumberNode | StringNode | MapNode | ExpressionNode;

109
package-lock.json generated
View File

@ -1,109 +0,0 @@
{
"name": "refdb",
"version": "1.0.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "refdb",
"version": "1.0.0",
"license": "ISC",
"dependencies": {
"dot-prop": "^8.0.2"
},
"devDependencies": {
"@types/node": "^20.10.6",
"typescript": "5.3.3"
}
},
"node_modules/@types/node": {
"version": "20.10.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz",
"integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==",
"dev": true,
"dependencies": {
"undici-types": "~5.26.4"
}
},
"node_modules/dot-prop": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-8.0.2.tgz",
"integrity": "sha512-xaBe6ZT4DHPkg0k4Ytbvn5xoxgpG0jOS1dYxSOwAHPuNLjP3/OzN0gH55SrLqpx8cBfSaVt91lXYkApjb+nYdQ==",
"dependencies": {
"type-fest": "^3.8.0"
},
"engines": {
"node": ">=16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/type-fest": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz",
"integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g==",
"engines": {
"node": ">=14.16"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/typescript": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
"dev": true,
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=14.17"
}
},
"node_modules/undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
"dev": true
}
},
"dependencies": {
"@types/node": {
"version": "20.10.6",
"resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz",
"integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==",
"dev": true,
"requires": {
"undici-types": "~5.26.4"
}
},
"dot-prop": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/dot-prop/-/dot-prop-8.0.2.tgz",
"integrity": "sha512-xaBe6ZT4DHPkg0k4Ytbvn5xoxgpG0jOS1dYxSOwAHPuNLjP3/OzN0gH55SrLqpx8cBfSaVt91lXYkApjb+nYdQ==",
"requires": {
"type-fest": "^3.8.0"
}
},
"type-fest": {
"version": "3.13.1",
"resolved": "https://registry.npmjs.org/type-fest/-/type-fest-3.13.1.tgz",
"integrity": "sha512-tLq3bSNx+xSpwvAJnzrK0Ep5CLNWjvFTOp71URMaAEWBfRb9nnJiBoUe0tF8bI4ZFO3omgBR6NvnbzVUT3Ly4g=="
},
"typescript": {
"version": "5.3.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.3.3.tgz",
"integrity": "sha512-pXWcraxM0uxAS+tN0AG/BF2TyqmHO014Z070UsJ+pFvYuRSq8KH8DmWpnbXe0pEPDHXZV3FcAbJkijJ5oNEnWw==",
"dev": true
},
"undici-types": {
"version": "5.26.5",
"resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz",
"integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==",
"dev": true
}
}
}

View File

@ -1,24 +0,0 @@
{
"name": "refdb",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"build": "tsc",
"watch": "tsc --watch",
"start": "node dist/index.js"
},
"repository": {
"type": "git",
"url": "https://git.ajusty.ru/denis/refdb.git"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.10.6",
"typescript": "5.3.3"
},
"dependencies": {
"dot-prop": "^8.0.2"
}
}

View File

@ -1,136 +0,0 @@
import { getProperty } from 'dot-prop';
import * as crypto from 'node:crypto';
import { filter } from './filter/filter';
const NOT_DEFINED_SET = "NOT_DEFINED";
export class DataBase {
nodeMap = new Map<BaseNode["uuid"], AnyNode>();
setMap = new Map<string, Set<BaseNode["uuid"]>>();
expressionMap = new Map<string, BaseNode["uuid"]>();
expressionCacheMap = new Map<BaseNode["uuid"], ExpressionResult>();
addNode(nodeParams: AddNodeParams): AnyNode {
const uuid = crypto.randomUUID();
const newNode = { ...nodeParams, uuid } as AnyNode;
this.nodeMap.set(uuid, newNode);
if (!nodeParams.set) {
nodeParams.set = NOT_DEFINED_SET;
}
if (!this.setMap.has(nodeParams.set)) {
this.setMap.set(nodeParams.set, new Set());
}
this.setMap.get(nodeParams.set)?.add(uuid);
switch (nodeParams.valueType) {
case "expression": {
const {id} = nodeParams as ExpressionNode;
this.expressionMap.set(id, uuid);
break;
}
}
return newNode;
}
get(uuid: BaseNode["uuid"]): PrimitiveValue | MapValue | undefined {
const node = this.nodeMap.get(uuid);
if (node == null) {
return node as undefined;
}
switch (node.valueType) {
case "number":
case "string": {
return node.value;
}
case "map": {
const result = {};
for (const key of Object.keys(node.value)) {
const value = this.get(node.value[key]);
result[key] = value;
}
return result;
}
}
}
getSet(set: string) {
const uuids = this.setMap.get(set) || new Set();
return Array.from(uuids).map(u => this.get(u));
}
getExpression(id: ExpressionNode["id"]): ExpressionResult {
const uuid = this.expressionMap.get(id);
if (uuid == null) {
return null;
}
const node = this.nodeMap.get(uuid);
if (node == null) {
return null;
}
const cache = this.expressionCacheMap.get(uuid);
if (cache != null) {
return cache;
}
const result = this.calculateExpression(node as ExpressionNode);
this.expressionCacheMap.set(node.uuid, result);
return result;
}
private calculateExpression(node: ExpressionNode): ExpressionResult {
switch (node.value.type) {
case "count": {
if (node.value.hasOwnProperty("set")) {
const set = this.getSet((node.value as CountWithSet).set);
return set.length;
}
if (node.value.hasOwnProperty("expression")) {
const exprNode: ExpressionNode | undefined = this.nodeMap.get((node.value as CountWithExpression).expression) as ExpressionNode;
if (exprNode == null) {
return null;
}
const expressionValue = this.getExpression(exprNode.id);
if (expressionValue instanceof Array) {
return expressionValue.length;
}
}
break;
}
case "filter": {
switch (typeof node.value.filter.value) {
case "number": {
if (node.value.hasOwnProperty("set")) {
const { set, field, filter: filterObj } = node.value as FilterWithSet;
const setValues = this.getSet(set);
return setValues.filter((it) => {
const candidate = getProperty(it, field) as PrimitiveValue;
return filter(
filterObj.predicate,
candidate,
filterObj.value
);
}) as ExpressionResult;
}
if (node.value.hasOwnProperty("expression")) {
const exprNode: ExpressionNode | undefined = this.nodeMap.get((node.value as FilterWithExpression).expression) as ExpressionNode;
if (!exprNode) {
return null;
}
const expressionValue = this.getExpression(exprNode.id);
if (expressionValue instanceof Array) {
return expressionValue.length;
}
}
}
}
break;
}
}
return null as ExpressionResult;
}
}

View File

@ -1,28 +0,0 @@
export function filter(
filterType: Filter["predicate"],
candidate: Filter["value"],
expect: Filter["value"],
): boolean {
switch (filterType) {
case "equal": {
return candidate === expect;
}
case "greatThat": {
return candidate > expect;
}
case "greatThatEqual": {
return candidate >= expect;
}
case "lessThat": {
return candidate < expect;
}
case "lessThatEqual": {
return candidate <= expect;
}
case "include": {
return (candidate as string).toUpperCase().includes((expect as string).toUpperCase());
}
}
}

View File

@ -1,48 +0,0 @@
import { DataBase } from "./DataBase";
const db = new DataBase();
const users = [
{ name: "Вася", age: 13, gender: "Male" },
{ name: "Лена", age: 31, gender: "Female" },
];
const usersUuids: string[] = [];
for (const user of users) {
const name = db.addNode({ set: "user_name", valueType: "string", value: user.name });
const age = db.addNode({ set: "user_age", valueType: "number", value: user.age });
const gender = db.addNode({ set: "user_gender", valueType: "string", value: user.gender });
const map = db.addNode({
set: "user",
valueType: "map",
value: {
name: name.uuid,
age: age.uuid,
gender: gender.uuid,
}
});
usersUuids.push(map.uuid);
}
const ageExp = db.addNode({
set: "users_exp",
valueType: "expression",
id: "userExp_gt_13",
value: {
type: "filter",
set: "user",
field: "age",
filter: {
predicate: "greatThat",
value: 13
}
}
} as ExpressionNode);
console.log(db.getSet("user"));
console.log(db.getExpression("userExp_gt_13"));

16
src/main.rs Normal file
View File

@ -0,0 +1,16 @@
use std::io;
use rand;
fn main() {
println!("Угадай число бля");
println!("Введи свой вариант чмо");
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Не удалось считать число пидр");
println!("Ты загадал {guess} еблан");
}

View File

@ -1,27 +0,0 @@
{
"compilerOptions": {
"target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"es6",
"es7",
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"module": "ES6", /* Specify what module code is generated. */
"rootDir": "./src", /* Specify the root folder within your source files. */
"resolveJsonModule": true, /* Enable importing .json files. */
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
"outDir": "./dist", /* Specify an output folder for all emitted files. */
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": false, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
"skipLibCheck": false, /* Skip type checking all .d.ts files. */
"moduleResolution": "Node",
},
"include": [
"./src/**/*.ts",
"./domain.d.ts"
],
"exclude": [
"node_modules"
],
}