戻る |
vh_stdvecを作成 |
|
New vh_stdvec |
|
|
|
Set v = New vh_stdvec |
|
この時点ですべての機能が使用可能 |
|
|
Variantの1次元配列をmoveして自身のデータとする(LBound
= 0にする) |
|
Function from(ByRef
v As Variant) As Variant |
|
|
|
(from メソッドを発行すると以前の値は消える) |
|
m = iota(1, 10) |
|
Set v = New vh_stdvec |
|
v.from m
← move なので配列のサイズに関わりなく作成できる |
|
v.printS |
|
[Data]: 0 -> 9 : [Accessible]: 0 -> 9 |
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 ← m のデータを奪い取る |
|
printM m |
|
← move されて Empty になっている |
|
※ size、capacity ともにUbound(v)になる |
|
戻る |
全ての要素を削除 |
|
Function clear()
As vh_stdvec |
|
|
|
v.clear |
|
v.printS |
|
[Data]: 0 -> -1 : [Accessible]: 0 -> -1 |
|
v.printM |
|
#Empty Vector# |
|
※ size、capacity ともに0になる |
|
|
|
vh_stdvecどうしのswap |
|
Function swap(ByVal
target As vh_stdvec) As vh_stdvec |
|
|
|
v1.from(iota(1, 10)).printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v2.from(array(5, 4, 3, 2, 1)).printM |
|
5 4
3 2 1 |
戻る |
v1.swap v2
'← 入れ替える |
|
v1.printM |
|
5 4
3 2 1 |
|
v2.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
|
|
同じ配列を持ったvh_stdvecオブジェクトの生成 |
|
Function clone()
As vh_stdvec |
|
|
|
v1.from(iota(1, 10)).printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
Set v2 = v1.clone |
|
v2.printM |
戻る |
1 2
3 4 5
6 7 8
9 10 |
|
|
配列部分を戻して自身は解放(shrinkしてから出力する) |
|
Function free()
As Variant |
|
|
|
x = v.free
← move なので代入時間は一瞬 |
|
printM x |
|
1 2
3 4 5
6 7 8
9 10 ← v のデータを奪い取る |
|
v.printS |
|
[Data]: 0 -> -1 : [Accessible]: 0 -> -1 |
|
v.printM |
戻る |
#Empty Vector# |
|
※ size、capacity ともに0になる |
|
|
書き込み済み要素数を取得 |
|
Property Get size() As Long |
|
|
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
?v.size |
|
10 |
|
|
ReDimせずに格納できる最大の要素数を取得 |
|
Property Get capacity() As Long |
|
|
|
?v.capacity |
|
10
←元のキャパシティ |
|
v.push_back 11
← 末尾に要素を追加してみる |
|
?v.capacity |
|
20 ←拡張された |
|
v.push_back 12
← 再度追加 |
|
?v.capacity |
|
20 ←拡張不要でした |
|
戻る |
領域を指定の長さまたはsizeまで切り詰める |
|
Function shrink(Optional
ByRef size_ As Variant) As vh_stdvec |
|
|
|
?v.size |
|
12 |
|
?v.capacity |
|
20 |
|
?v.shrink.capacity |
|
12
← shrink を引数なしで呼び出すと capacity = size になる |
|
?v.shrink(8).capacity |
|
8
← 指定した長さまで切り詰める |
|
v.printM |
|
1 2
3 4 5
6 7 8 |
|
|
|
指定した位置から個数を指定して範囲を削除する |
|
Function erase_n(ByVal begin As Long, ByVal n As Long) As vh_stdvec |
|
|
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.erase_n 4,
3 |
|
v.printM |
|
1 2
3 4 8
9 10
← [5, 6, 7]が削除された |
|
※ capacity を超える長さにしてもエラーにはならない |
|
※ capacityは変化しない |
|
|
戻る |
デバッグウィンドウに書き込み済み領域と配列領域を表示する |
|
Sub printS() |
|
|
|
v.printS |
|
[Data]: 0 -> 6 : [Accessible]: 0 -> 9 |
|
|
|
デバッグウィンドウに 書き込み済み領域の全体または一部を表示する |
|
Sub printM(Optional
ByRef r As Variant) |
|
|
|
v.from(iota(1, 10)).printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
|
|
|
デバッグウィンドウにジャグ配列を展開して表示する |
|
Sub printM_(Optional
ByRef r As Variant, Optional ByRef c As Variant) |
|
|
|
Set v = New vh_stdvec |
|
v.push_back iota(1,4) |
|
v.push_back iota(11,14) |
|
v.push_back iota(21,26) |
|
v.push_back iota(0,9) |
|
v.printM_ |
|
1 2
3 4 |
|
11 12 13 14 |
|
21 22 23 24 25 26 |
|
0 1
2 3 4
5 6 7
8 9 |
|
|
戻る |
指定位置の 値 を取得する(1以上の第2引数を指定した場合はその長さ分配列で返す) |
|
Property Get val(ByVal begin As Long, Optional ByVal len_ As Long = 0) As
Variant |
|
|
|
v.from iota(1,
10) |
|
? v.val(3) |
|
4 |
|
printM v.val(3, 3) |
|
4 5
6 |
|
|
|
指定位置の 値 を取得する move版(1以上の第2引数を指定した場合はその長さ分配列で返す) |
|
Property Get pop(ByVal begin As Long, Optional ByVal len_ As Long = 0) As
Variant |
|
|
|
v.from iota(1,
10) |
|
? v.pop(3) |
|
4 |
|
v.printM |
|
1 2
3 5 6
7 8 9
10 |
|
|
|
指定位置に値を設定する(値はmoveされる) |
|
Function push(ByVal
pos As Long, ByVal x As Variant) As vh_stdvec |
|
|
|
v.printM |
|
1 2
3 5 6
7 8 9
10 |
|
v.push(3,
4).printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
※ capacity 以上の位置への設定はエラーとなる |
|
※ エンド位置を超える位置へ設定をした場合、エンド位置はそこに移動する |
|
|
|
戻る |
同一の値に対する push の複数回適用 |
|
Function push_n(ByVal
pos As Long, ByRef x As Variant, ByVal n As Long) As vh_stdvec |
|
|
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.push_n(3,
111, 4).printM |
|
1 2
3 111 111 111 111 8
9 10 |
|
※ capacity 以上の位置への設定はエラーとなる |
|
※ エンド位置を超える位置へ設定をした場合、エンド位置はそこに移動する |
|
|
|
配列の一括 push |
|
Function push_array(ByVal pos As Long, ByVal x As Variant) As vh_stdvec |
|
|
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.push_array(3,
iota(100, 104)).printM |
|
1 2
3 100 101 102 103 104 9
10 |
|
※ capacity 以上の位置への設定はエラーとなる |
|
※ エンド位置を超える位置へ設定をした場合、エンド位置はそこに移動する |
|
|
|
beginの位置の前にn個のEmptyを挿入する |
|
Function insert_empty(ByVal begin As Long, ByVal n As Long) As vh_stdvec |
|
|
|
v.from iota(1, 10) |
戻る |
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.insert_empty(4,
5).printM |
|
1 2
3 4
5 6 7
8 9 10 |
|
v.push_array(4, iota(101,105)).printM |
|
1 2
3 4 101 102 103 104 105 5
6 7 8
9 10 |
|
|
|
※ 挿入開始位置beginは0以上であればcapacityを超えていてもよい |
|
v.printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.insert_empty(12, 5).printS |
|
[Data]: 0 -> 9 : [Accessible]: 0 -> 19 |
|
|
|
書き込み済み末尾に対するpush(領域拡張する) |
|
Function push_back(ByVal x As Variant) As vh_stdvec |
|
|
|
v.clear |
|
v.push_back(110).push_back(119).printM |
|
110 119 |
|
|
|
書き込み済み末尾に対する同一値の複数push(領域拡張する) |
|
Function push_back_n(ByRef x As Variant, ByVal n As Long) As vh_stdvec |
|
|
|
v.printM |
|
110 119 |
|
v.push_back_n("0120",
8).printM |
戻る |
110 119 0120 0120 0120 0120 0120 0120 0120 0120 |
|
|
|
書き込み済み末尾に対するpush_array(領域拡張する) |
|
Function push_back_array(ByVal arr As Variant) As vh_stdvec |
|
|
|
v.printM |
|
110 119 |
|
a = iota(120, 127) |
|
v.push_back_array(a).printM |
|
110 119 120 121 122 123 124 125 126 127 |
|
|
|
push_back_arrayの反復 |
|
Function push_back_arrays(ByVal arr As Variant) As vh_stdvec |
|
|
|
a=iota(1,10) |
|
b = iota(10, 20) |
|
c = zipWith(p_a__o, a, b) |
|
v.push_back_arrays(c).printM |
|
1 2
3 4 5
6 7 8
9 2 3
4 5 6
7 8 9
10 3 4
5 6 7
8 9 10 11 |
|
4 5
6 7 8
9 10 11 12 5
6 7 8
9 10 11 12 13 6
7 8 9
10 11 12 13 14 |
|
7 8
9 10 11 12 13 14 15 8
9 10 11 12 13 14 15 16 9
10 11 12 13 14 |
|
15 16 17 10 11 12 13 14 15 16 17 18 |
|
|
|
抽出条件を与えて配列をフィルタリングする |
|
Function filter(ByRef
pred As Variant) As vh_stdvec |
|
|
戻る |
v.from(iota(1, 20)).printM |
|
1 2
3 4 5
6 7 8
9 10 11 12 13 14 15 16 17 18 19 20 |
|
v.filter(p_mod(
,2)).printM |
|
1 3
5 7 9
11 13 15 17 19 |
|
|
変換式を与えて配列を変換する |
|
Function map(ByRef fun As Variant) As
vh_stdvec |
|
|
|
v.from(iota(1, 10)).printM |
|
1 2
3 4 5
6 7 8
9 10 |
|
v.map(p_mult).printM |
|
1 4
9 16 25 36 49 64 81 100 |
|
|
比較関数を与えて配列をソートする |
|
Function orderby(ByRef comp As Variant)
As vh_stdvec |
|
|
|
v.from(uniform_int_dist(10, 1, 10)).printM |
|
7 1
6 3 9
10 9 6
4 4 |
|
v.orderby(p_less).printM |
|
1 3
4 4 6
6 7 9
9 10 |
|
|
|
v.from(uniform_int_dist(20, 1, 100)).printM |
|
33 36 64 55 100 49 47 92 30 49 25 65 90 40 31 35 68 34 45 41 |
戻る |
v.filter(p_mod(
,2)).map(p_plus(100)).orderby(p_less).printM |
|
125 131 133 135 141 145 147 149 149 155 165 |
|
|