Skip to content

Commit

Permalink
feat(vector-pools): enable TS strict compiler flags (refactor)
Browse files Browse the repository at this point in the history
- add missing type hints/return types
  • Loading branch information
postspectacular committed Jun 4, 2019
1 parent b6b69e6 commit 1af6f78
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
6 changes: 3 additions & 3 deletions packages/vector-pools/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface IVecPool extends IRelease {

free(vec: StridedVec | TypedArray): boolean;

freeAll();
freeAll(): void;
}

export type VecFactory = (
Expand Down Expand Up @@ -72,7 +72,7 @@ export const enum GLType {
/**
* Conversion from `GLType` to `Type`.
*/
export const GL2TYPE = {
export const GL2TYPE: { [id: number]: Type } = {
[GLType.I8]: Type.I8,
[GLType.U8]: Type.U8,
[GLType.I16]: Type.I16,
Expand All @@ -86,7 +86,7 @@ export const GL2TYPE = {
/**
* Conversion from `Type` to `GLType`.
*/
export const TYPE2GL = {
export const TYPE2GL: { [id: number]: GLType } = {
[Type.I8]: GLType.I8,
[Type.U8]: GLType.U8,
[Type.I16]: GLType.I16,
Expand Down
4 changes: 2 additions & 2 deletions packages/vector-pools/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { GL2TYPE, GLType, TYPE2GL } from "./api";
*/
export const asNativeType = (type: GLType | Type): Type => {
const t = GL2TYPE[type];
return t !== undefined ? t : type;
return t !== undefined ? t : <Type>type;
};

export const asGLType = (type: GLType | Type): GLType => {
const t = TYPE2GL[type];
return t !== undefined ? t : type;
return t !== undefined ? t : <GLType>type;
};
29 changes: 18 additions & 11 deletions packages/vector-pools/src/linked-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,16 @@ import { StridedVec, Vec } from "@thi.ng/vectors";
import { AVecList } from "./alist";
import { VecFactory } from "./api";

interface Cell<T extends StridedVec> {
prev: CellVec<T>;
next: CellVec<T>;
}

type CellVec<T extends StridedVec> = T & Cell<T>;

export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
head: T;
tail: T;
head: CellVec<T>;
tail: CellVec<T>;
readonly closed: boolean;

protected _length: number;
Expand Down Expand Up @@ -39,7 +46,7 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {

*[Symbol.iterator]() {
if (this._length) {
let v: any = this.head;
let v = this.head;
const first = v;
do {
yield v;
Expand All @@ -53,15 +60,15 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
}

add(): T {
const v: any = this.alloc();
const v = <CellVec<T>>this.alloc();
if (v) {
if (this.tail) {
v.prev = this.tail;
(<any>this.tail).next = v;
this.tail.next = v;
this.tail = v;
if (this.closed) {
v.next = this.head;
(<any>this.head).prev = v;
this.head.prev = v;
}
this._length++;
} else {
Expand All @@ -77,9 +84,9 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
if (!this._length) {
return i === 0 ? this.add() : undefined;
}
const q: any = this.nth(i);
const q = <CellVec<T>>this.nth(i);
if (!q) return;
const v: any = this.alloc();
const v = <CellVec<T>>this.alloc();
if (v) {
if (this.head === q) {
this.head = v;
Expand All @@ -99,7 +106,7 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
if (this.has(vec)) {
this._length--;
this.freeIDs.push(vec.offset);
const v: any = vec;
const v = <CellVec<T>>vec;
if (v.prev) {
v.prev.next = v.next;
}
Expand All @@ -119,7 +126,7 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
}

has(value: T) {
let v: any = this.head;
let v = this.head;
const first = v;
do {
if (v === value) {
Expand All @@ -130,7 +137,7 @@ export class VecLinkedList<T extends StridedVec> extends AVecList<T> {
return false;
}

nth(n: number): T {
nth(n: number): T | undefined {
if (n < 0) {
n += this._length;
}
Expand Down

0 comments on commit 1af6f78

Please sign in to comment.