Data Structures

发布时间:2014-10-22 12:26:41编辑 分享查询网我要评论
本篇文章主要介绍了"Data Structures",主要涉及到Data Structures方面的内容,对于Data Structures感兴趣的同学可以参考一下。

Hash Tables哈希表Hash tables are an important exception to all the suggestions above. You cannot initialize an empty hash-table using var aHash: Hash; . You must use var aHash = {}; to initialize a hash table.Significant functions/methods of the hash table:Count An integer number of elements in the hash table.Keys A collection (list-like data structure) of the keys in the hash table.Contains(aKey) Is aKey a key in the hash table?Remove(aKey) Removes a key/value pair.Add(aKey, aValue) Equivalent to aHash[aKey] = aValue;ArrayLists动态列表You might be tempted to use new Array(); for your arrays. While this is understandable, the Array implementation has some significant limits, notably not supporting the indexOf method. The ArrayList has many of the convenience methods one might want. Warnings:You cannot create a null ArrayList using var someArray: ArrayList; and subsequently access that ArrayList's members without first creating it. Workaround: in your Awake function, do var someArray = new ArrayList();You cannot access the ArrayList constructor - var someArray = new ArrayList(foo, bar, baz); doesn't work. Workaround:You must create the ArrayList and subsequently populate it.Significant functions/methods of the array list:Count An integer number of elements in the array. Use this instead of length. e.g. for (i=0; i < anArrayList.Count; i++) { ... }Contains(anObject) Is aMember an element in the hash table? e.g. if (anArrayList.Contains(anObject)) { ... }.Remove(aMember) Removes aMember. Does not raise an error if aMember doesn't exist in the array.Add(anObject) Equivalent to anArray[] = aMember; except that anArray.Add(anObject) works.

上一篇:【转】用 Unity 做 iPhone 游戏之代码优化个人总结


关键词: Data Structures