NSDictionary Search Time Complexity

NoodleOfDeath

Is the search operation selector objectForKey: of the NSDictionary class of order 1 time complexity like a hashtable?

stevesliva

I hate to have a mostly-link answer, but everything you might want to know and more is here: Exposing NSDictionary

This is the code suggested for objectForKey:

- (id)objectForKey:(id)aKey
{
    NSUInteger sizeIndex = _szidx;
    NSUInteger size = __NSDictionarySizes[sizeIndex];

    id *storage = (id *)object_getIndexedIvars(dict);

    NSUInteger fetchIndex = [aKey hash] % size;

    for (int i = 0; i < size; i++) {
        id fetchedKey = storage[2 * fetchIndex];

        if (fetchedKey == nil) {
            return nil;
        }

        if (fetchedKey == aKey || [fetchedKey isEqual:aKey]) {
            return storage[2 * fetchIndex + 1];
        }

        fetchIndex++;

        if (fetchIndex == size) {
            fetchIndex = 0;
        }
    }

    return nil;
}

As Bartosz Ciechanowski says:

Worse case performance is linear

Read the rest!

He proves that there is definitely object instance == checking before an isEqual test. And a lot more.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Time Complexity of Binary Search?

From Dev

Search time complexity of this sql query

From Dev

Breadth First Search time complexity analysis

From Java

What is the time-complexity in a binary search?

From Dev

Time complexity of Uniform-cost search

From Dev

Running time complexity for binary search tree

From Dev

Time and Space Complexity for Breadth First Search

From Dev

Time complexity of deletion in binary search tree

From Dev

Time/Space Complexity of Depth First Search

From Dev

GATE 2008: Time Complexity of Binary Search Tree

From Dev

Time and Space Complexity for Breadth First Search

From Dev

Time complexity of deletion in binary search tree

From Dev

Time complexity in search of a list within a tree

From Dev

What would be time Complexity of binary search algorithm?

From Dev

Time complexity for rebuilding binary search tree / quadtree / octtree?

From Dev

Time Complexity of breadth first search with adjacency matrix representation?

From Dev

How to handle the time complexity for permutation of strings during anagrams search?

From Dev

Time complexity of search operation on hash tables using separate chaining

From Dev

Why does assignment in a binary search algorithm not add to the time complexity?

From Dev

'if not in' time complexity

From Dev

Time Complexity?

From Dev

search element in NSDictionary nested in another NSDictionary

From Dev

iterative deepening depth first search higer time complexity than depth first search?

From Dev

iterative deepening depth first search higer time complexity than depth first search?

From Dev

Search NSArray of NSDictionary using NSPredicate

From Dev

How to calculate the average time complexity of the nearest neighbor search using kd-tree?

From Dev

What's time complexity of algorithm for finding all Unique Binary Search Trees?

From Dev

AI tree search. Time complexity of 8-queen, by placeing one by one without attack

From Dev

How to calculate the average time complexity of the nearest neighbor search using kd-tree?

Related Related

  1. 1

    Time Complexity of Binary Search?

  2. 2

    Search time complexity of this sql query

  3. 3

    Breadth First Search time complexity analysis

  4. 4

    What is the time-complexity in a binary search?

  5. 5

    Time complexity of Uniform-cost search

  6. 6

    Running time complexity for binary search tree

  7. 7

    Time and Space Complexity for Breadth First Search

  8. 8

    Time complexity of deletion in binary search tree

  9. 9

    Time/Space Complexity of Depth First Search

  10. 10

    GATE 2008: Time Complexity of Binary Search Tree

  11. 11

    Time and Space Complexity for Breadth First Search

  12. 12

    Time complexity of deletion in binary search tree

  13. 13

    Time complexity in search of a list within a tree

  14. 14

    What would be time Complexity of binary search algorithm?

  15. 15

    Time complexity for rebuilding binary search tree / quadtree / octtree?

  16. 16

    Time Complexity of breadth first search with adjacency matrix representation?

  17. 17

    How to handle the time complexity for permutation of strings during anagrams search?

  18. 18

    Time complexity of search operation on hash tables using separate chaining

  19. 19

    Why does assignment in a binary search algorithm not add to the time complexity?

  20. 20

    'if not in' time complexity

  21. 21

    Time Complexity?

  22. 22

    search element in NSDictionary nested in another NSDictionary

  23. 23

    iterative deepening depth first search higer time complexity than depth first search?

  24. 24

    iterative deepening depth first search higer time complexity than depth first search?

  25. 25

    Search NSArray of NSDictionary using NSPredicate

  26. 26

    How to calculate the average time complexity of the nearest neighbor search using kd-tree?

  27. 27

    What's time complexity of algorithm for finding all Unique Binary Search Trees?

  28. 28

    AI tree search. Time complexity of 8-queen, by placeing one by one without attack

  29. 29

    How to calculate the average time complexity of the nearest neighbor search using kd-tree?

HotTag

Archive