Need to do

1. Structure of array and linked list 2. Order, traversal and inversion of binary tree 3hash() conflict of ways to see somehash4. Weak references in the tablehashWhat did () doCopy the code

An array of

advantages

1. Query quick index 2Copy the code

disadvantages

1. Slow increments and deletions 2. Only one type can be stored. Fixed size is inconvenient to expandCopy the code
Add, delete and change the element alignment and rebind indexCopy the code

The list

advantages

1. Add, delete and change very fastCopy the code
Linked lists are linked by Pointers, storage addresses are not contiguous, add and delete operations, directly to the address of the pointer to modifyCopy the code

disadvantages

1. Query is very slowCopy the code
You need to start the query at the beginning nodeCopy the code

Hash table (dictionary)

hash() According to the data analysis

  • Direct address method
  • Square the middle
  • Take more method

In order to get the index, if you get index, you can evaluate it

/ / array for variable array [array setObject: object1 atIndexedSubscript: object1. Hash]; // Overwrite objecth - (NSUInteger)hash{return hash();Copy the code

keyValue

  • The index is computed using the internal hash()
  • What are hash collisions: two values in an index
  • How to solve it?
1. Zipper method: Store the linked list in index again, with X-axis as the outer layer and Y-axis 2 as the secondary storage. Direct judgment: one-way) | | reach a value of 3. Continuehash(4)...Copy the code

The hash implementation of weak

static inline uint32_t ptr_hash(uint64_t key)
{
    key ^= key >> 4;
    key *= 0x8a970be7488fda55;
    key ^= __builtin_bswap64(key);
    return (uint32_t)key;
}
Copy the code

figure

The tree

  • Binary tree (traversal)
  • HashMap is implemented using red-black trees
  • Binary tree inversion

Hash table

Stack (First in last out)

advantages


Copy the code

disadvantages


Copy the code

Queue (FIFO)

Queues hold tasks that are executed by threads

advantages


Copy the code

disadvantages


Copy the code

autoreleasePool

advantages


Copy the code

disadvantages


Copy the code

advantages


Copy the code

disadvantages


Copy the code

why


Copy the code