ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.

Slides:



Advertisements
Similar presentations
Introduction to C++ An object-oriented language Unit - 01.
Advertisements

David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.
Lecture 6 Sept 11, 2008 Goals for the day: Linked list and project # 1 list class in STL (section 3.3) stack – implementation and applications.
Chapter6 LISTS AND STRINGS. Outline 1. List Specifications 2. List Implementations (a) Class Templates (b) Contiguous (c) Simply Linked (d) Simply Linked.
Backup Slides. An Example of Hash Function Implementation struct MyStruct { string str; string item; };
Searching for Data Relationship between searching and sorting Simple linear searching Linear searching of sorted data Searching for string or numeric data.
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Chapter 6 Structures By C. Shing ITEC Dept Radford University.
Introduction to Programming Lecture 39. Copy Constructor.
Module R2 Overview. Process queues As processes enter the system and transition from state to state, they are stored queues. There may be many different.
Lecture 6 : Dynamic Hashing Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
Hashing as a Dictionary Implementation
Data Structures: A Pseudocode Approach with C
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Carrano and Henry, © 2013.
Compiler Construction
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
The Symbol Table Lecture 13 Wed, Feb 23, The Symbol Table When identifiers are found, they will be entered into a symbol table, which will hold.
Data Management and File Organization
Linked Lists. Preliminaries Options for implementing an ADT List Array Has a fixed size Data must be shifted during insertions and deletions Dynamic array.
Sets and Maps Chapter 9. Chapter 9: Sets and Maps2 Chapter Objectives To understand the Java Map and Set interfaces and how to use them To learn about.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 15: Linked data structures.
Implementation of Linked List For more notes and topics visit: eITnotes.com.
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Copyright © 2002, Systems and Computer Engineering, Carleton University Hashtable.ppt * Object-Oriented Software Development Unit 8.
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Pointers OVERVIEW.
Lists II. List ADT When using an array-based implementation of the List ADT we encounter two problems; 1. Overflow 2. Wasted Space These limitations are.
CS 376b Introduction to Computer Vision 01 / 23 / 2008 Instructor: Michael Eckmann.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Hashing as a Dictionary Implementation Chapter 19.
1 Data Structures CSCI 132, Spring 2014 Lecture 20 Linked Lists.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
CS 153: Concepts of Compiler Design October 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
ICOM 4035 – Data Structures Dr. Manuel Rodríguez Martínez Electrical and Computer Engineering Department.
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
ENEE150 – 0102 ANDREW GOFFIN Linked List/Project 3.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Type Systems CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
Prof. amr Goneid, AUC1 CSCE 110 PROGRAMMING FUNDAMENTALS WITH C++ Prof. Amr Goneid AUC Part 15. Dictionaries (1): A Key Table Class.
Dictionaries and Their Implementations Chapter 18 Data Structures and Problem Solving with C++: Walls and Mirrors, Frank Carrano, © 2012.
ENEE150 – 0102 ANDREW GOFFIN More With Pointers. Importance of Pointers Dynamic Memory (relevant with malloc) Passing By Reference Pointer Arithmetic.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Sets and Maps Chapter 9. Chapter Objectives  To understand the Java Map and Set interfaces and how to use them  To learn about hash coding and its use.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Introduction to C++ programming Recap- session 1 Structure of C++ program Keywords Operators – Arithmetic – Relational – Logical Data types Classes and.
CMSC 202 Computer Science II for Majors. CMSC 202UMBC Topics Templates Linked Lists.
Prepared by Andrew Jung. Accessing Pointer Data Pointer can be used to access the contents of an array Look at the following syntax: /* Declaration and.
CSC 243 – Java Programming, Fall, 2008 Tuesday, September 30, end of week 5, Interfaces, Derived Classes, and Abstract Classes.
DYNAMIC MEMORY ALLOCATION. Disadvantages of ARRAYS MEMORY ALLOCATION OF ARRAY IS STATIC: Less resource utilization. For example: If the maximum elements.
C++ Programming:. Program Design Including
Linked Lists & Hash Tables
CS2006- Data Structures I Chapter 5 Linked Lists I.
ENEE150 Discussion 13 Section 0101 Adam Wang.
Binary Search Trees.
Chapter 16-2 Linked Structures
Hashing as a Dictionary Implementation
Data structures in C++.
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Indirection.
Data Structures & Algorithms
CS410 – Software Engineering Lecture #5: C++ Basics III
Presentation transcript:

ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers

Project 4 Hash Table ADT  A data type that points to a hash table  Separate struct needed for hash table nodes themselves  Hash table struct MUST contain:  Pointer to bucket array for table  Function pointer to a print function for the table  Hash table struct should probably contain:  Table stats (total number of records, average search, worst search)  Hash table NODE structs must contain:  Self-referring next pointer (like a linked list)  Generic “data” pointer  String key Goffin – ENEE150

Project 4 Continued Hash Table Operations  Phash_table new_hash(int size, void (*print_func)(void *)): constructor  Takes function pointer to set the hash table’s print function  void free_hash(Phash_table table): destructor  void insert_hash(Phash_table table, char *key, void *data)  “constructor” for hash table node: uses hash function to insert into table  void *find_hash(Phash_table table, char *key)  Returns pointer to node with key or NULL if no node with key exists  void stat_hash(Phash_table table, int *total, float *average_search, int *worst_search)  Modifies variables total, average_search, and worse_search by reference  void dump_hash(Phash_table table)  Uses function pointer to print table contents  void resize_hash(Phash_table table, int size)  Changes number of buckets to “size” – you must re-hash all the entries! Goffin – ENEE150

Other Project 4 ADT Notes You can use other fields or private methods!  As long as the public methods work as stated, you’re good Hash function  Due to potential bit overflow, use unsigned int variables to store intermediate values Search stats based on number of records traversed to get to the one you’re looking for  Typically, more buckets = more efficient searching Goffin – ENEE150

Project 4: Implementations parse.c  Parsing words in a dictionary and inserting them into the hash table  In this case, the word is both the key and part of the data  See handout #14 for an earlier implementation of this performance-test.c  Code is provided: simply shows how increasing buckets improves performance  Also shows benefit of separating use and implementation  Yeung didn’t need your ADT implementation to write this module! Goffin – ENEE150

Function Pointers Sometimes different users may want slightly different results from an ADT  Ex: Printing the hash table in project 4  Someone may want to print int data, others char data, etc. Can make functions generic using function pointers  Further supports polymorphism for ADTs Goffin – ENEE150

Function Pointer Declaration Must specify return type and parameters void (*func)(int, float)  The above can only be a function pointer for a function with the same interface  Can assign a function to the function pointer by simply saying func = foo; where foo is a function with the same interface as func (*func)(10, 3.14);  The above passes 10 and 3.14 into foo Goffin – ENEE150