feat(Vector)

This commit is contained in:
2025-07-23 10:36:50 +03:00
parent 83c491ff6f
commit aca4539ce4
21 changed files with 1103 additions and 1533 deletions

39
types/Vector.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
import { RandomAccessIterator } from './iterators/RandomAccess';
import { SequenceContainer } from './containers/Sequence';
export class Vector<T> extends SequenceContainer<T, VectorIterator<T>> {
/**
* empty vector
*/
constructor();
/**
* vector with n similar elements
* @param value which will be inserted
* @param n count of how many values will be inserted
*/
constructor(value: T, n?: number);
/**
* copies range of another vector
* @param begin of another SequenceContainer<T>
* @param end of another SequenceContainer<T>
*/
constructor(begin: ListIterator<T>, end: ListIterator<T>);
/**
* @returns vector[idx]
*/
get(idx: number): T;
/**
* vector[idx] = value
* @returns vector[idx]
*/
set(idx: number, value: T): T;
/**
* creates vector from array, string and other iterable object
*/
static from<T>(obj: Iterable<T>): Vector<T>;
}
export class VectorIterator<T> extends RandomAccessIterator<T> {
private constructor();
}

View File

@ -1,8 +1,13 @@
import { ForwardIterator } from "../iterators/Forward";
export class SequenceContainer<T, It extends ForwardIterator<T>> {
export interface SequenceContainer<T, It extends ForwardIterator<T>> {
move(rhs: SequenceContainer<T, It>): this;
size(): number;
/**
* @param size new size
* @param value to insert
*/
resize(size: number, value: T): void;
begin(): It;
end(): It;

View File

@ -1,6 +1,6 @@
import { ForwardIterator } from "./Forward";
export class BidirectionalIterator<T> extends ForwardIterator<T> {
export interface BidirectionalIterator<T> extends ForwardIterator<T> {
/**
* decrements iterator, it doesn't make copy
* @returns {this}

View File

@ -1,10 +1,12 @@
export class Item<T> {
export interface Item<T> {
value: T
}
export class ForwardIterator<T> {
export interface ForwardIterator<T> {
clone(): ForwardIterator<T>;
copy(rhs: ForwardIterator<T>): this;
get value(): T;
set value(value: T);
deref(): Item<T>;
eq(rhs: ForwardIterator<T>): boolean;
/**
@ -18,7 +20,5 @@ export class ForwardIterator<T> {
* @returns {this}
*/
move(rhs: ForwardIterator<T>): this;
get value(): T;
set value(value: T);
neq(rhs: ForwardIterator<T>): boolean;
}

9
types/iterators/RandomAccess.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
import { BidirectionalIterator } from "./Bidirectional";
export interface RandomAccessIterator<T> extends BidirectionalIterator<T> {
sub(offset: number): this;
add(offset: number): this;
cmp(rhs: RandomAccessIterator<T>): number;
get(idx: number): T;
set(idx: number, value: T): T;
}