Understanding zipper law

principle

The keywords (synonyms) with the same hash value in the same address in a single list, referred to as a synonym list.
There are m m have addresses hash linked list, simultaneously with the pointer array T [0..m-1] stored in the list head pointer each,
all the hash address i are recorded in the inserted node in T [ i] is a pointer to a single list.
T is the initial value of each component should be a null pointer.

use

Mainly used to solve the problem of key values ​​conflict

Scenes

  • HashMap HashMap to use the zipper method key is transformed into hashcode, this value is likely to be repeated, but why HashMap no problem

  • Seeking set intersection

image

An ordered set {1,3,5,7,8,9}

2 ordered set {2,3,4,5,6,7}

Two pointer to the first element, the element size comparison:

  • If the same, into the result set, free to move a pointer

  • Otherwise, the smaller the value of a pointer move until the tail

The benefits of this approach are:

(1) elements of a set up are compared, the time complexity is O (n)

(2) multiple sets can be ordered at the same time, this item applies to more than Segmentation of the intersection of demand url_id

This method zipper sides like a gear, like the fastener than eleven, so called zipper Method

Guess you like

Origin www.cnblogs.com/geektcp/p/11518455.html
law