English 中文(简体)
A. 3200名独裁者名单
原标题:A .plist of 3200 dictionaries

我有一个名单,有3200名字典。 每个字典有20个关键/价值。 如何以最佳方式通过它进行搜索?

我有一句叫“id”的一句大话,现在我做的是,通过阵列的所有内容,要求每个要素(字典)对钥匙“id”的价值进行对比,如果发现的话,则与其他id相比。

This is really slow, like I can see a lag of about 1-2 seconds. Is there a better way? Thanks

问题回答

What you re doing now is an O(n) operation (linear in the number of items in the list). You can get a "constant time" O(1) lookup if you keep another "lookaside" data structure that helps you index into your list.

在你撰写3 200个字典清单之前,又创建了一个特别字典,标明你的身份证,以便把大阵列索引。 换言之,每个钥匙都将是身份证,其价值将是一个具有指数编号的NSNumber。 之后(在同一名单中或单独一个名单中)也除外。

然后,当你需要做一项研究时,就在座标语中只读到<>-objectForKey:,这将会立即使你回到你看望的条目索引上。

如果你用活的数据更新,那么你总是把眼部的字典归到一起。 请注意,这也假设了你的身份证是独一无二的(如其正确无误)。

为什么你不使用Skkite数据库?

我注意到的第一件事是,你似乎总是在同一个<代码>id钥匙上搜索。 如果是这样的话,那么你就应当按照<条码>d对你的各种字典进行分类。 然后,你可以就分类阵列进行双轨搜索。 结果:通过<条码>查询任何字典> 最多为12项行动。 相比之下,通过3 200件物品进行的线性搜索平均为1 600件,可能需要多达3 200件。

如果你需要寻找几个不同的钥匙,如果所有独裁者都拥有同样的钥匙,那么核心数据可能是一个非常好的解决方案。 NSManaged 标 题 理论家,但框架将照顾到你们的指数化,搜寻工作迅速而比较容易。





相关问题
How do you create UIBarButtonItems with a radio interface?

I have a UIToolbar that needs three buttons in a radio style, meaning that of the three, only one button can be pushed at a time. The documentation makes reference to the possibility of setting up ...

iPhone settings bundle

I want to allow the user to enter a valid date using the iPhone’s settings application. I have experimented with many of the PreferenceSpecifiers data node types including date. I have two issues: ...

Circular #import/@class problem in ObjectiveC

I m going to use an example to properly illustrate my confusion. I can t quite wrap my head around this. In Cocoa touch, we have UIViewController and its subclass, UINavigationController. Now, UIVC ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Cocoa-Touch: issue looping MPMoviePlayerController

I have an app which has to load some data at startup, so I want to display a splash-screen animation. I m using the MPMoviePlayerController to play a m4v file. The movie has it s background set to [...

Iphone sequential animation with setAnimationDelay

I m trying to chain animation events. The application I m coding for work has a multiple choice quiz. First you pick your multiple choice answer. The quiz view fades away. Then a label ("correct" or "...

热门标签