CPSC 252 Tables / Maps / Dictionaries Page 1 Tables, Maps and Dictionaries A table (or map or dictionary) is a collection of key/value pairs. In general.

Slides:



Advertisements
Similar presentations
Linear Lists – Array Representation
Advertisements

. STL: C++ Standard Library (continued). STL Iterators u Iterators are allow to traverse sequences u Methods  operator*  operator->  operator++, and.
1 STL Map & Multimap Ford & Topp Chapter 11 Josuttis Sections: 6.5 & 6.6 CSE Lecture 15 – Maps.
An Introduction to Hashing. By: Sara Kennedy Presented: November 1, 2002.
They’re not just binary anymore!
Week 5 - Associative Containers: sets and maps. 2 2 Main Index Main Index Content s Content s Container Types Sequence Containers Adapter Containers Associative.
hashing1 Hashing It’s not just for breakfast anymore!
1 Associative Containers Gordon College Prof. Brinton.
Lecture 11 March 5 Goals: hashing dictionary operations general idea of hashing hash functions chaining closed hashing.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
Main Index Contents 11 Main Index Contents Container Types Container Types Sequence Containers Sequence Containers Associative Containers Associative Containers.
CMSC 202 Lesson 24 Iterators and STL Containers. Warmup Write the class definition for the templated Bag class – A bag has: Random insertion Random removal.
CSE 332: C++ Associative Containers II Associative Containers’ Associated Types Associative containers declare additional types –A key_type gives the type.
CS-2851 Dr. Mark L. Hornick 1 Tree Maps and Tree Sets The JCF Binary Tree classes.
1 Stacks Stack Examples Stack API More Examples/Uses Base Conversion Activation Records RPN Implementing a Stack Stacks.
1 Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
Containers Overview and Class Vector
1 The Map ADT © Rick Mercer. 2 The Map ADT  A Map is an abstract data type where a value is "mapped" to a unique key  Also known as Dictionary  Need.
Data Structures. The Stack: Definition A stack is an ordered collection of items into which new items may be inserted and from which items may be deleted.
Data Structures.  Consider storing data for 100 employees by their Social Security Numbers (SSN)  SSN range: –  A fast search:
DATA STRUCTURES AND ALGORITHMS Lecture Notes 12 Prepared by İnanç TAHRALI.
Main Index Contents 11 Main Index Contents Week 3 – The Vector Container.
Dictionaries Collection of pairs.  (key, element)  Pairs have different keys  E.g. a pair contains two components, student id and name (1234, Nan)
Beyond Lists: Other Data Structures CS303E: Elements of Computers and Programming.
STL multimap Container. STL multimaps multimaps are associative containers –Link a key to a value –AKA: Hashtables, Associative Arrays –A multimap allows.
CPSC 252 Operator Overloading and Convert Constructors Page 1 Operator overloading We would like to assign an element to a vector or retrieve an element.
Goals for Today 1  Multiton  maps  static factory methods.
Mixing Static and Non-static
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Stacks.
CPSC 252 The Big Three Page 1 The “Big Three” Every class that has data members pointing to dynamically allocated memory must implement these three methods:
CS261 Data Structures Maps (or Dictionaries). Goals Introduce the Map(or Dictionary) ADT Introduce an implementation of the map with a Dynamic Array.
11-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
Sets and Maps Computer Science 4 Mr. Gerb Reference: Objective: Understand the two basic applications of searching.
Standard C++ Library Part II. Last Time b String abstraction b Containers - vector.
Sets and Maps Sets Maps The Comparator Interface Sets and Maps in Java Collections API – TreeSet – TreeMap Review for Exam Reading:
CPSC 252 Hashing Page 1 Hashing We have already seen that we can search for a key item in an array using either linear or binary search. It would be better.
1 Associative Containers Ordered Ordered Unordered UnorderedSets Maps as sets of pairs Set API Ex: Sieve of Eratosthenes Ex: Sieve of EratosthenesImplementation.
Abstract Data Type EnhanceEdu.
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
Associative Containers Sets Maps Section 4.8. Associative Containers.
1 Chapter 3 Lists, Stacks, and Queues Reading: Sections 3.1, 3.2, 3.3, 3.4 Abstract Data Types (ADT) Iterators Implementation of Vector.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
Introduction to Data Structure, Fall 2006 Slide- 1 California State University, Fresno Introduction to Data Structure Chapter 4 Ming Li Department of Computer.
CSE 143 Lecture 11: Sets and Maps reading:
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
CSCI  Sequence Containers – store sequences of values ◦ vector ◦ deque ◦ list  Associative Containers – use “keys” to access data rather than.
Main Index Contents 11 Main Index Contents Sets Defined by a key along with other data Sets Defined by a key along with other data Key-Value Data Key-Value.
CPSC 252 ADTs and C++ Classes Page 1 Abstract data types (ADTs) An abstract data type is a user-defined data type that has: private data hidden inside.
SQL – Python and Databases
CSCI 104 Abstract Data Types
C++ Standard Library.
Stack and Queue APURBO DATTA.
Recursion.
Abstract Data Types Iterators Vector ADT Sections 3.1, 3.2, 3.3, 3.4
Object Oriented Programming COP3330 / CGS5409
Associative Structures
Chapter 3 Lists, Stacks, and Queues Abstract Data Types, Vectors
Recitation Outline C++ STL associative containers Examples
Doubly Linked List Implementation
Classes.
Lists - I The List ADT.
Lists - I The List ADT.
Iterators and STL Containers
Hashing in java.util
Doubly Linked List Implementation
Recitation Outline Hash tables in C++ STL Examples Recursive example
A dictionary lookup mechanism
Presentation transcript:

CPSC 252 Tables / Maps / Dictionaries Page 1 Tables, Maps and Dictionaries A table (or map or dictionary) is a collection of key/value pairs. In general the objects in a table have no fixed order and each object is accessed using the associated key. So, for example, we could have a table of drivers in BC, each object is a driver having a name, address, number of points for bad driving, etc. Each of these objects has an associated key – the corresponding driver’s license number. struct Driver { string name; string address; int points; int licenseNumber; };

CPSC 252 Tables / Maps / Dictionaries Page 2 In the example above, each object (driver) has a unique key (driver’s license number). In general it is important to understand that keys are not necessarily unique – it is possible that one key corresponds to many different objects (values). In the case where every object has a unique key, we refer to the table as a (one-to-one) map. If the keys are not unique so that more than one object is mapped onto the same key then we refer to the table as a many-to-one map or multimap.

CPSC 252 Tables / Maps / Dictionaries Page 3 Map Accessor (retrieving from a map) const object& operator[]( key ) const // given a key, the corresponding object is returned Note that: the return type is both const and a reference this is similar to [] in the IntVector class Usage example: cout << myTable[ key ]; // object corresponding to key is retrieved // from myTable and written to cout

CPSC 252 Tables / Maps / Dictionaries Page 4 Map Mutator (storing into a map) object& operator[]( key ); // used to associate a key with an object Note that: the return type is not const but is again a reference this is similar to [] in the IntVector class Usage example: myTable[ key ] = object; // inserts object into myTable and associates it with // the given key

CPSC 252 Tables / Maps / Dictionaries Page 5 Other necessary map methods bool empty( key ) const; // returns true if key is not in table; // otherwise false void erase( key ); // removes key and the corresponding object from // the table We will examine the implementation of maps (tables) later