Presentation is loading. Please wait.

Presentation is loading. Please wait.

Feedback from Assignment 2

Similar presentations


Presentation on theme: "Feedback from Assignment 2"— Presentation transcript:

1 Feedback from Assignment 2
Feedback from Assignment 2

2 An Important Hashing Issue
Generally, all collection classes that use hashing have a design induced speedup that results because Instead of searching a long list, say 10000, elements via a linear search (how else can you search things that may not be sortable) They reduce the search dramatically by breaking the list into 1000 lists and searching only one 10 element list. How do they do that?

3 How Does Hashing Work The algorithm that uses hashing simply asks each object that it is supposed to contain and makes use of a table size of size n (sometimes referred to as its buckets). Instead of insert the object into one big list, it wants to inserts it into the sublist referenced by Buckets [object hash modulo n] How does it tell if it’s already there or not? Perform a linked list search using = (equality) for a normal dictionary (an equality dictionary) or using == (identity) for an identity dictionary

4 The typical default hash for objects in an object-oriented system is
What is a default hash? The typical default hash for objects in an object-oriented system is The memory address of the object For many objects, this hash is inadequate; e.g., strings. So strings implement their own hash. hash self size = 0 ifTrue: [^0]. ^self first + self last + self size

5 Implications For The Average Programmer
If you want dictionaries to work for a new class like Dog, you need to implement 2 things hash ^”some sort of integer” = anObject ^”the boolean result of the compare” For a dog, it might be that the other objects is a dog, it’s the same breed, has the same color, and has the same name

6 Where Does It Matter A readback item contains an item (a right part state) and a state (a readahead state). What happens if you just implement “=”? Suppose you have item1 and state1 and you create 2 equal readback items, r1 and r2. r1 = ReadbackItem item: item1 state: state1. r2 = ReadbackItem item: item1 state: state1. aDictionary at: r1 put: 'test1'. aDictionary at: r2 put: 'test2'. Sometimes, “aDictionary at: r1” retrieves 'test1‘ and sometimes 'test2'.

7 What’s a Hash That Would Make it Work
The following doesn’t work r1 = ReadbackItem item: item1 state: state1. r2 = ReadbackItem item: item1 state: state1. aDictionary at: r1 put: 'test1'. aDictionary at: r2 put: 'test2'. The fix works but could be better hash ^state unclosuredItems size + item transitions size ^item hash + state hash better

8 There’s a small bug in one Relation’s allTo
For a dictionary, saying values gives you a collection with all it’s elements. But, if it’s a dictionary of ordered collection, you as a result get back a collection of collections. The code needs to say aDictionary values flattened


Download ppt "Feedback from Assignment 2"

Similar presentations


Ads by Google