Skip to content

Commit d7085fe

Browse files
author
Samchon
committed
Fix #54, Fix #55, Fix #56
1 parent ac68a64 commit d7085fe

File tree

10 files changed

+64
-22
lines changed

10 files changed

+64
-22
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"email": "[email protected]",
77
"url": "http://samchon.org"
88
},
9-
"version": "2.3.0",
9+
"version": "2.3.1-dev.20191212",
1010
"main": "./index.js",
1111
"typings": "./index.d.ts",
1212
"scripts": {

src/base/iterator/ListIterator.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//================================================================
22
/** @module std.base */
33
//================================================================
4-
import { IContainer } from "../container/IContainer";
54
import { Iterator } from "./Iterator";
65
import { ReverseIterator } from "./ReverseIterator";
76

7+
import { IContainer } from "../container/IContainer";
8+
import { OutOfRange } from "../../exception/LogicError";
9+
810
/**
911
* Basic List Iterator.
1012
*
@@ -110,9 +112,22 @@ export abstract class ListIterator<T extends Elem,
110112
*/
111113
public get value(): T
112114
{
115+
this._Try_value();
113116
return this.value_;
114117
}
115118

119+
/**
120+
* @hidden
121+
*/
122+
protected _Try_value(): void
123+
{
124+
if (this.value_ === undefined && this.equals(this.source().end()) === true)
125+
{
126+
let name: string = this.source().constructor.name;
127+
throw new OutOfRange(`Error on std.${name}.Iterator.value: cannot access to the std.${name}.end().value.`);
128+
}
129+
}
130+
116131
/* ---------------------------------------------------------------
117132
COMPARISON
118133
--------------------------------------------------------------- */

src/benchmark/exceptions.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Vector, List, HashMap, ForwardList } from "../container";
22
import { SharedMutex } from "../thread/SharedMutex";
33
import { Semaphore } from "../thread/Semaphore";
44

5-
import { Exception } from "../exception/Exception";
65
import { advance } from "../iterator";
76
import {
87
cyl_bessel_j, cyl_neumann,
@@ -20,7 +19,7 @@ async function except(proc: Procedure): Promise<string>
2019
}
2120
catch (exp)
2221
{
23-
if (exp instanceof Exception)
22+
if (exp instanceof Error)
2423
return ` ${exp.name} | ${exp.message} `;
2524
}
2625
return " NULL | NULL ";
@@ -41,7 +40,7 @@ export async function main(): Promise<string>
4140

4241
let exceptions: string[] = [
4342
// VECTOR
44-
await except(() => { v.at(-1); }),
43+
await except(() => { v.end().value; }),
4544
await except(() => { v.at(1); }),
4645
await except(() => { v.set(-1, 4); }),
4746
await except(() => { v.set(1, 4); }),
@@ -54,10 +53,18 @@ export async function main(): Promise<string>
5453
// LIST
5554
await except(() => { l.insert(new List<number>().begin(), 4 ); }),
5655
await except(() => { l.erase(new List<number>().begin()); }),
56+
await except(() => { l.end().value; }),
57+
await except(() => { l.end().value = 3 }),
58+
await except(() => { fl.end().value; }),
59+
await except(() => { fl.end().value = 3 }),
60+
await except(() => { fl.before_begin().value; }),
61+
await except(() => { fl.before_begin().value = 3 }),
5762

5863
// ASSOCIATIVE
5964
await except(() => { m.get(3); }),
6065
await except(() => { m.extract(3); }),
66+
await except(() => { m.end().value.second = 5; }),
67+
await except(() => { m.find(3).second = 5; }),
6168

6269
// GLOBAL
6370
await except(() => { advance(fl.begin(), -4); }),

src/benchmark/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async function benchmark(feature: string): Promise<void>
2323
// REPORT MEMORY USAGE
2424
//----
2525
let memory: NodeJS.MemoryUsage = global.process.memoryUsage();
26-
let performance: string = "> ## Performancn"
26+
let performance: string = "> ## Performance \n"
2727
+ `> - Elapsed time: ${time} ms\n`;
2828

2929
for (let key in memory)

src/container/ForwardList.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import { _IDeque } from "../base/container/IDequeContainer";
1010
import { _IFront } from "../base/container/ILinearContainer";
1111
import { _IListAlgorithm } from "../base/disposable/IListAlgorithm";
1212

13-
import { ForOfAdaptor } from "../base/iterator/ForOfAdaptor";
1413
import { _Repeater } from "../base/iterator/_Repeater";
14+
import { ForOfAdaptor } from "../base/iterator/ForOfAdaptor";
1515
import { Vector } from "./Vector";
16+
import { OutOfRange } from "../exception/LogicError";
1617

1718
import { advance, distance } from "../iterator/global";
1819
import { equal_to, less } from "../functional/comparators";
@@ -37,17 +38,17 @@ export class ForwardList<T>
3738
/**
3839
* @hidden
3940
*/
40-
private size_!: number;
41+
private size_: number;
4142

4243
/**
4344
* @hidden
4445
*/
45-
private before_begin_!: ForwardList.Iterator<T>;
46+
private before_begin_: ForwardList.Iterator<T>;
4647

4748
/**
4849
* @hidden
4950
*/
50-
private end_!: ForwardList.Iterator<T>;
51+
private end_: ForwardList.Iterator<T>;
5152

5253
/* ===============================================================
5354
CONSTRUCTORS & SEMI-CONSTRUCTORS
@@ -95,7 +96,9 @@ export class ForwardList<T>
9596
{
9697
this.ptr_ = {value: this};
9798

98-
this.clear();
99+
this.end_ = ForwardList.Iterator.create(this.ptr_, null!);
100+
this.before_begin_ = ForwardList.Iterator.create(this.ptr_, this.end_);
101+
this.size_ = 0;
99102

100103
if (args.length === 1 && args[0] instanceof Array)
101104
{
@@ -136,7 +139,6 @@ export class ForwardList<T>
136139
public assign(first: any, last: any): void
137140
{
138141
this.clear();
139-
140142
this.insert_after(this.before_begin_, first, last);
141143
}
142144

@@ -145,9 +147,7 @@ export class ForwardList<T>
145147
*/
146148
public clear(): void
147149
{
148-
this.end_ = ForwardList.Iterator.create(this.ptr_, null!, null!);
149-
this.before_begin_ = ForwardList.Iterator.create(this.ptr_, this.end_);
150-
150+
ForwardList.Iterator._Set_next(this.before_begin_, this.end_);
151151
this.size_ = 0;
152152
}
153153

@@ -607,6 +607,7 @@ export namespace ForwardList
607607
*/
608608
public get value(): T
609609
{
610+
this._Try_value();
610611
return this.value_!;
611612
}
612613

@@ -615,9 +616,26 @@ export namespace ForwardList
615616
*/
616617
public set value(val: T)
617618
{
619+
this._Try_value();
618620
this.value_ = val;
619621
}
620622

623+
/**
624+
* @hidden
625+
*/
626+
private _Try_value(): void
627+
{
628+
if (this.value_ === undefined)
629+
{
630+
let source: ForwardList<T> = this.source();
631+
632+
if (this.equals(source.end()) === true)
633+
throw new OutOfRange("Error on std.ForwardList.Iterator.value: cannot access to the std.ForwardList.end().value.");
634+
else if (this.equals(source.before_begin()) === true)
635+
throw new OutOfRange("Error on std.ForwardList.Iterator.value: cannot access to the std.ForwardList.before_begin().value.");
636+
}
637+
}
638+
621639
/* ---------------------------------------------------------
622640
MOVERS
623641
--------------------------------------------------------- */

src/container/List.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ export namespace List
420420
*/
421421
public get value(): T
422422
{
423+
this._Try_value();
423424
return this.value_;
424425
}
425426

@@ -428,6 +429,7 @@ export namespace List
428429
*/
429430
public set value(val: T)
430431
{
432+
this._Try_value();
431433
this.value_ = val;
432434
}
433435

src/thread/Barrier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//================================================================
2-
/** @module std.experimental */
2+
/** @module std */
33
//================================================================
44
import { FlexBarrier } from "./FlexBarrier";
55

src/thread/FlexBarrier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//================================================================
2-
/** @module std.experimental */
2+
/** @module std */
33
//================================================================
44
import { ConditionVariable } from "./ConditionVariable";
55

src/thread/Latch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//================================================================
2-
/** @module std.experimental */
2+
/** @module std */
33
//================================================================
44
import { ConditionVariable } from "./ConditionVariable";
55

src/thread/Semaphore.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//================================================================
2-
/** @module std.experimental */
2+
/** @module std */
33
//================================================================
44
import { List } from "../container/List";
55
import { OutOfRange } from "../exception/LogicError";
@@ -106,11 +106,11 @@ export class Semaphore<Max extends number = number>
106106
{
107107
// VALIDATE COUNT
108108
if (count < 1)
109-
throw new OutOfRange(`Error on std.experimental.Semaphore.release(): parametric count is less than 1 -> (count = ${count}).`);
109+
throw new OutOfRange(`Error on std.Semaphore.release(): parametric count is less than 1 -> (count = ${count}).`);
110110
else if (count > this.max_)
111-
throw new OutOfRange(`Error on std.experimental.Semaphore.release(): parametric count is greater than max -> (count = ${count}, max = ${this.max_}).`);
111+
throw new OutOfRange(`Error on std.Semaphore.release(): parametric count is greater than max -> (count = ${count}, max = ${this.max_}).`);
112112
else if (count > this.acquiring_)
113-
throw new OutOfRange(`Error on std.experimental.Semaphore.release(): parametric count is greater than acquiring -> (count = ${count}, acquiring = ${this.acquiring_}).`);
113+
throw new OutOfRange(`Error on std.Semaphore.release(): parametric count is greater than acquiring -> (count = ${count}, acquiring = ${this.acquiring_}).`);
114114

115115
// DO RELEASE
116116
this.acquiring_ -= count;

0 commit comments

Comments
 (0)