Hashing in java.util http://java.sun.com/j2se/1.5.0/docs/api/index.html.

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Sequence of characters Generalized form Expresses Pattern of strings in a Generalized notation.
Dictionaries Chapter Chapter Contents Specifications for the ADT Dictionary Entries and methods Using the ADT Dictionary English Dictionary Telephone.
CS 106 Introduction to Computer Science I 05 / 03 / 2010 Instructor: Michael Eckmann.
Using Maps. A simple map: Hashtable To create a Hashtable, use: import java.util.*; Hashtable table = new Hashtable(); To put things into a Hashtable,
1 L43 Collections (3). 2 OBJECTIVES  To use the collections framework interfaces to program with collections polymorphically.  To use iterators to “walk.
HASHING CSC 172 SPRING 2002 LECTURE 22. Hashing A cool way to get from an element x to the place where x can be found An array [0..B-1] of buckets Bucket.
Algorithm Programming Containers in Java Bar-Ilan University תשס " ו by Moshe Fresko.
What Is a Collection?  A collection (sometimes called a container) is simply an object that groups multiple elements into a single unit.  Collections.
24-Jun-15 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 17 Advanced Java Concepts Data Structure Support.
Collections The objectives of this chapter are: To outline the Collections infrastructure in Java To describe the various collection classes To discuss.
Dictionaries and Hash Tables Cmput Lecture 24 Department of Computing Science University of Alberta ©Duane Szafron 2000 Some code in this lecture.
CSE 373 Data Structures and Algorithms Lecture 18: Hashing III.
The Collections Framework A Brief Introduction. Collections A collection is a structured group of objects –An array is a kind of collection –A Vector.
Using Maps. 2 A simple map: Hashtable To create a Hashtable, use: import java.util.*; Hashtable table = new Hashtable(); To put things into a Hashtable,
Hashing The Magic Container. Interface Main methods: –Void Put(Object) –Object Get(Object) … returns null if not i –… Remove(Object) Goal: methods are.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
Sets and Maps Part of the Collections Framework. The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Recitation 1 CS0445 Data Structures Mehmud Abliz.
Collections in Java. Kinds of Collections Collection --a group of objects, called elements –Set-- An unordered collection with no duplicates SortedSet.
1 Sets and Maps Starring: keySet Co-Starring: Collections.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Chapter 18 Java Collections Framework
1 TCSS 143, Autumn 2004 Lecture Notes Java Collection Framework: Maps and Sets.
1/20/03A2-1 CS494 Interfaces and Collection in Java.
Sets and Maps Chris Nevison. Set Interface Models collection with no repetitions subinterface of Collection –has all collection methods has a subinterface.
The Java Collections Framework Based on
CSC 142 P 1 CSC 142 Collections [Reading: Chapter 10]
3-February-2003cse Collections © 2003 University of Washington1 Java Collections CSE 403, Winter 2003 Software Engineering
1 Collections Framework A collections framework is a unified architecture for representing and manipulating collections. All collections frameworks contain:
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
Sets and Maps Sets Maps The Comparator Interface Sets and Maps in Java Collections API – TreeSet – TreeMap Review for Exam Reading:
Set and Map IS 313, Skeletons  Useful coding patterns  Should understand how and why they work how to use  possible quiz material.
Copyright (c) Systems and Computer Engineering, Carleton University * Object-Oriented Software Development Unit 13 The Collections Framework.
Maps Nick Mouriski.
Week 9 - Friday.  What did we talk about last time?  Collisions  Open addressing ▪ Linear probing ▪ Quadratic probing ▪ Double hashing  Chaining.
Sets and Maps Part of the Collections Framework. 2 The Set interface A Set is unordered and has no duplicates Operations are exactly those for Collection.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
Starting Out with Java From Control Structures through Data Structures by Tony Gaddis and Godfrey Muganda Collections in Java.
1 Maps, Stacks and Queues Maps Reading:  2 nd Ed: 20.4, 21.2, 21.7  3 rd Ed: 15.4, 16.2, 16.7 Additional references: Online Java Tutorial at
Collections Dwight Deugo Nesa Matic
Hashing By Emily Nelson. The Official Definition Using a hash function to turn some kind of data in relatively small integers or Strings The “hash code”
Java Collections CHAPTER 3-February-2003
Fundamental of Java Programming
Efficiency of in Binary Trees
Week 8 - Wednesday CS221.
Week 8 - Friday CS221.
Road Map CS Concepts Data Structures Java Language Java Collections
Using Maps.
Using Maps.
Containers ב Java אליהו חלסצ'י תכנות מתקדם תרגול מספר 3
Programming in Java Lecture 11: ArrayList
Lecture 6: Collections.
Hashing as a Dictionary Implementation
Chapter 10 Hashing.
CSE 373: Data Structures and Algorithms
Part of the Collections Framework
Using Maps.
Maps "He's off the map!" -Stan (Mark Ruffalo) Eternal Sunshine of the Spotless Mind.
Collections in Java The objectives of this lecture are:
"He's off the map!" - Eternal Sunshine of the Spotless Mind
Using Maps.
Collections Framework
L5. Necessary Java Programming Techniques
Data Structures II AP Computer Science
Set and Map IS 313,
Presentation transcript:

Hashing in java.util http://java.sun.com/j2se/1.5.0/docs/api/index.html

HashMap A map is a collection that holds pairs (key,value), or entries. HashMap is an implementation of the interface Map (read main section 5.5, p.275) Class hierarchy in java.util is as follows: Object AbstractMap HashMap

HashMap Uses chaining as collision resolution technique HashMap permits null values and the null key. HashMap implementation is not synchronized, i.e. If multiple threads access this map concurrently, and at least one of the threads modifies the map structurally, then other threads may have unsynchronized access to the map.

HashMap An instance of HashMap has two parameters that affect its performance: initial capacity and load factor (default value =0.75). When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the capacity is roughly doubled by calling a rehash method.

HashMap Methods in class HashMap include: Constructor methods: Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75). HashMap(int ic) Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).

HashMap Constructor methods (continue): HashMap(int ic, float lf) Constructs an empty HashMap with the specified initial capacity and load factor. HashMap(Map m) Constructs a new HashMap with the same elements from the specified Map m.

HashMap Methods void clear() boolean containsKey(Object key) Removes all mappings from this hash map. boolean containsKey(Object key) Returns true if this map contains a mapping for the specified key. boolean containsValue(Object value) Returns true if this map maps one or more keys to the specified value.

HashMap Methods (continue) Set entrySet() Returns a set containing all the pairs (key, value) in the hash map. Object get(Object key) Returns the object associated with key. boolean isEmpty() Return true if this map contains no elements, false otherwise.

HashMap Methods (continue) Object put(Object key, Object val) Put the pair(key,val) in the hash map; return a value associated with key if there is any in the hash map, null otherwise. void putAll(Map m) Add objects from map m to the current hash map. Void rehash() A protected method to increase the capacity of the hashtable; the method is called automatically when the number of keys in the hashtable is greater than the product of the load factor and the current capacity.

HashMap Methods (continue) Object remove(Object key) Remove the pair (key, corresponding value) from the hash map and return the value associated currently with key in the hash map. int size() Returns the number of objects in this map

HashSet A set is an object that stores unique elements. HashSet is an implementation of the interface Set Class hierarchy in java.util is as follows: Object AbstractCollection AbstractSet HashSet

HashSet Methods in class HashSet include: Constructor methods: Creates an empty HashSet with initial capacity (16) and load factor (0.75). HashSet(int ic) Constructs an empty HashSet with the specified initial capacity and the default load factor (0.75).

HashSet Constructor methods (continue): HashSet(int ic, float lf) Constructs an empty HashSet with the specified initial capacity and load factor. HashSet(Collection c) Constructs a new HashSet with the same elements from the specified Collection c.

HashSet Methods boolean add(Object ob) void clear() Adds the specified element to this set if it is not already present void clear() Remove all the objects from the hash set boolean contains(Object ob) Return true if the hash set contains the object ob boolean isEmpty() Returns true if this set contains no elements.

HashSet Methods (continue) boolean remove(Object ob) Removes the specified element from this set if it is present. int size() Returns the number of elements in this set (its cardinality).

Hashtable This is another implementation of the interface Map. It is roughly equivalent to HashMap except that it is synchronized and does not permit null keys or null values. Class hierarchy in java.util is as follows: Object Dictionary Hashtable Check: http://java.sun.com/j2se/1.5.0/docs/api/index.html