FlashBuilder 调试器如何知道将项目添加到具有字符串键的关联数组中的顺序?
我有一个对象数组,它使用分隔字符串作为键。在 FB4 调试器中检查时,键看起来像这样:
[+] 22477◦25220◦20.1 [+] 22477◦25220◦20.6 [+] 22477◦25220◦20.8 [+] 22477◦25244◦55.1K(j)
前两项是数字(转换为字符串),但多部分分隔键中的第三项自然是字符串 - 它就像字母数字库架引用。正如预期的那样,当您单击调试器中的 [+] 图标时,您可以查看与该字符串键关联的对象。到目前为止,一切都很好。
调试器按照添加到数组的(预先排序的)顺序显示键。但是,当迭代对象数组时:
for (var key: String in MyAssociativeArray){ // keys are visited not in the order displayed by the debugger }
键以其他顺序返回——内部哈希?我的问题是,调试器如何知道添加键的顺序,以及我可以在迭代数组时在运行时访问这些知识吗?我想按照对象添加的顺序迭代它们。 或者我是否需要维护这些键的自己的索引,以显示它们添加到关联数组中的顺序?
[0] 22477◦25220◦20.1 [1] 22477◦25220◦20.6 [2] 22477◦25220◦20.8 [3] 22477◦25244◦55.1K(j)
谢谢
I have an array of objects which uses a delimited string as the keys. When examined in the FB4 debugger, the keys look like this:
[+] 22477◦25220◦20.1 [+] 22477◦25220◦20.6 [+] 22477◦25220◦20.8 [+] 22477◦25244◦55.1K(j)
The first two items are numeric (cast to string) but the third item in the multi-part delimited key is naturally a string -- it's like an alphanumeric library shelf reference. As expected, when you click on the [+] icon in the debugger, you can view the object associated with that string key. So far so good.
The debugger shows the keys in the (pre-sorted) order in which they were added to the array. However, when iterating the object array so:
for (var key: String in MyAssociativeArray){ // keys are visited not in the order displayed by the debugger }
the keys are returned in some other order --internal hash? My question is, how does the debugger know the order the keys were added in, and can I access that knowledge at runtime when iterating the array? I want to iterate the objects in the order in which they were added. Or do I need to maintain my own index of these keys showing the order they were added to the associative array?
[0] 22477◦25220◦20.1 [1] 22477◦25220◦20.6 [2] 22477◦25220◦20.8 [3] 22477◦25244◦55.1K(j)
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调试器按字典顺序对关联数组中的项目列表进行排序(按数字和字母顺序排序),以便更轻松地找到您要查找的内容。您的示例中的列表是这样排序的。您以相同的顺序将项目添加到关联数组中纯属巧合。
如果不创建额外的元数据,您将无法发现将项目添加到关联数组的顺序。如果您需要这样的行为,请尝试为此创建一个自定义类。
这是一个例子:
通过上面的内容,您可以执行以下操作:
The debugger sorts lists of items in an associative array lexicographically for you (ordered numerically and alphabetically) to make it easier to find what you're looking for. The list in your example is sorted this way. It's a coincidence that you added items to the associative array in the same order.
There is no way for you to discover the order in which you add items to an associative array without creating additional metadata. If you need such behavior try creating a custom class for this.
Here's an example:
With the above you can do something like this: