Algorithms and OOD (CSC 207 2014S) : EBoards
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Overview
Can "this is wickedly fast and efficient" be my distinguishing characteristic?
Yes.
Will you be upset if my parser is not O(n)?
Yes. Well, I won't be upset if it's O(logn), but that seems impossible.
Will you be upset if my unparser is not O(n)?
No.
int find(K key)
{
int index = Math.abs(key.hashCode()) % this.pairs.length;
KVPair pair;
while ((pair = (KVPair) this.pairs[index]) != null)
{
System.out.println(index);
if (pair.key == key)
{
return index;
}// if the keys match
else
{
// two distinct keys hashed to the same place
// increment index by the offset to avoid collision
index = (index + PROBE_OFFSET) % this.pairs.length;
} // if the keys don't match
}// while the cell is not empty
return index;
} // find(K)
== and !=.System.err.println
and not System.out.println.Rewritten
int find(K key)
{
int index = Math.abs(key.hashCode()) % this.pairs.length;
KVPair pair;
while (((pair = (KVPair) this.pairs[index]) != null)
&& (!key.equals(pair.key)))
{
System.err.println(index);
// two distinct keys hashed to the same place
// increment index by the offset to avoid collision
index = (index + PROBE_OFFSET) % this.pairs.length;
}// while the cell is not empty
return index;
} // find(K)
How do we ensure that this terminates?
Whoops. Rebelsky can't design functions. This should have the option of throwing an exception.
Primary: [Front Door] [Schedule] - [Academic Honesty] [Disabilities] [Email] - [FAQ] [Teaching & Learning] [Grading] [Rubric] - [Calendar]
Current: [Assignment] [EBoard] [Lab] [Outline] [Reading]
Sections: [Assignments] [EBoards] [Examples] [Handouts] [Labs] [Outlines] [Partners] [Readings]
Reference: [Java 7 API] [Java Code Conventions] [GNU Code Conventions]
Related Courses: [CSC 152 2006S (Rebelsky)] [CSC 207 2013F (Rebelsky)] [CSC 207 2013S (Walker)] [CSC 207 2011S (Weinman)]
Misc: [SamR] [Glimmer Labs] [CS@Grinnell] [Grinnell] [Issue Tracker (Course)] [Issue Tracker (Textbook)]
Copyright (c) 2013-14 Samuel A. Rebelsky.

This work is licensed under a Creative Commons Attribution 3.0 Unported License. To view a copy of this
license, visit http://creativecommons.org/licenses/by/3.0/
or send a letter to Creative Commons, 543 Howard Street, 5th Floor,
San Francisco, California, 94105, USA.