0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

文字列をキーとする時にRecord<string,T>と{name:string,data:T}[]のどちらを使うか

0
Posted at

ツクールMZ向けのライブラリを作成している際にぶつかった問題。

何らかのKeyとValueのペアを扱うデータの際、表現方法は以下の3種類がある。

aa
type DataMap<T> = Map<string,T>;
type DataRecord<T> = Record<string,T>;
type DataArray<T> ={
  name:string;
  data:T;
}[];

MapとRecordはほぼ同じだが、DataArray<T>の方はデータの持ち方がだいぶ異なる。
DataArrayに対して検索を行うと線形探索になり効率が悪いが、array.map()で変換するなら後者の方が良い。
今回作成したのはコンパイラ的な処理だったのだが、作業を進めるうちにDataArrayの方がメインになっていった。
RecordやMapのような型にするのは最後の方で充分なようだ。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?