set4
play

Set4 15 September 2020 OSU CSE 1 Documenting Set4 (and Map4 ) By - PowerPoint PPT Presentation

Set4 15 September 2020 OSU CSE 1 Documenting Set4 (and Map4 ) By now you understand hashing and its benefits. But the algorithms we are using are not trivial, and make a lot of assumptions about the representation. How can we


  1. Set4 15 September 2020 OSU CSE 1

  2. Documenting Set4 (and Map4 ) • By now you understand hashing and its benefits. • But the algorithms we are using are not trivial, and make a lot of assumptions about the representation. • How can we document those assumptions in our code? 15 September 2020 OSU CSE 2

  3. The Representation /** * Buckets for hashing. */ private Set<T>[] hashTable; /** * Total size of abstract this . */ private int size; 15 September 2020 OSU CSE 3

  4. The Correspondence of Set4 @correspondence this = union i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) 15 September 2020 OSU CSE 4

  5. The Correspondence of Set4 @correspondence this = union i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and The prefixed union <s> = $this .hashTable[i, i+1)) introduces a universal (s) quantifier. This is the union over all possible values for i and s 15 September 2020 OSU CSE 5

  6. The Correspondence of Set4 What does the where @correspondence clause tell us about the this = values of i and s union i: integer , that are of interest to us? s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) 15 September 2020 OSU CSE 6

  7. The Correspondence of Set4 From the first two parts of @correspondence the where clause we can this = see that i has to be a valid union i: integer , index of our hash table s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) 15 September 2020 OSU CSE 7

  8. The Correspondence of Set4 The third part of the where @correspondence clause tells is that s has to this = be the set at position i of union i: integer , our hash table s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) 15 September 2020 OSU CSE 8

  9. The Correspondence of Set4 @correspondence this = union i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) And the abstract value of this is the union of all such sets s 15 September 2020 OSU CSE 9

  10. The Correspondence of Set4 Thus the value of this is @correspondence the union of all the sets in this = our hash table union i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (s) 15 September 2020 OSU CSE 10

  11. The Convention of Set4 @convention | $this .hashTable| > 0 and for all i: integer , s: finite set of T, x: T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1) and x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (|s|) 15 September 2020 OSU CSE 11

  12. The Convention of Set4 Perhaps it is better if we break this into parts… @convention | $this .hashTable| > 0 and for all i: integer , s: finite set of T, x: T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1) and x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (|s|) 15 September 2020 OSU CSE 12

  13. Set4 ’s Convention (1 of 4) | $this .hashTable| > 0 and … 15 September 2020 OSU CSE 13

  14. Set4 ’s Convention (1 of 4) | $this .hashTable| > 0 and … Surprisingly, Java arrays can have zero elements, but we want to have buckets in our hash table… 15 September 2020 OSU CSE 14

  15. Set4 ’s Convention (2 of 4) … and for all i: integer , s: finite set of T, x: T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1) and x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and … 15 September 2020 OSU CSE 15

  16. Set4 ’s Convention (2 of 4) The first three parts of … and the where clause look for all i: integer , familiar… What values of s: finite set of T, i and s are we interested in? x: T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1) and x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and … 15 September 2020 OSU CSE 16

  17. Set4 ’s Convention (2 of 4) … and for all i: integer , s: finite set of T, x: T where (0 <= i and i < | $this .hashTable| and What about the <s> = $this .hashTable[i, i+1) and values of x ? x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and … 15 September 2020 OSU CSE 17

  18. Set4 ’s Convention (2 of 4) … and for all i: integer , This tells us that if x s: finite set of T, is in a set in our x: T hash table, then that where (0 <= i and set is at a specific i < | $this .hashTable| and position in our hash <s> = $this .hashTable[i, i+1) and table... x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and … 15 September 2020 OSU CSE 18

  19. Set4 ’s Convention (2 of 4) In other words, this tells … and us that we are hashing the entries in our set! for all i: integer , s: finite set of T, x: T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1) and x is in s) ([computed result of x.hashCode()] mod | $this .hashTable| = i)) and … 15 September 2020 OSU CSE 19

  20. Set4 ’s Convention (3 of 4) … and for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and … 15 September 2020 OSU CSE 20

  21. Set4 ’s Convention (3 of 4) What values of i are we interested in? … and for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and … 15 September 2020 OSU CSE 21

  22. Set4 ’s Convention (3 of 4) … and for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and … And for those values of i what must be true? 15 September 2020 OSU CSE 22

  23. Set4 ’s Convention (3 of 4) In other words, this tells us that all entries in the array must have been … and initialized for all i: integer where (0 <= i and i < | $this .hashTable|) ([entry at position i in $this .hashTable is not null ]) and … 15 September 2020 OSU CSE 23

  24. Set4 ’s Convention (4 of 4) … and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (|s|) 15 September 2020 OSU CSE 24

  25. Set4 ’s Convention (4 of 4) … and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and The prefixed sum <s> = $this .hashTable[i, i+1)) introduces a universal (|s|) quantifier. This is the sum over all possible values for i and s 15 September 2020 OSU CSE 25

  26. Set4 ’s Convention (4 of 4) … and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (|s|) The where clause looks familiar… What values of i and s are we interested in? 15 September 2020 OSU CSE 26

  27. Set4 ’s Convention (4 of 4) … and $this .size = sum i: integer , s: finite set of T where (0 <= i and i < | $this .hashTable| and <s> = $this .hashTable[i, i+1)) (|s|) What does this tell us about the value of $this .size with respect to the value of this ? 15 September 2020 OSU CSE 27

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend