Hash set - INTRODUCTION The HashSet and TreeSet classes both implement the Set interface An iterator visits all elements in a set A set iterator

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
INTRODUCTION The HashSet and TreeSet classes both implement the Set interface. An iterator visits all elements in a set. A set iterator does not visit the elements in the order in which you inserted them. The set implementation rearranges the elements so that it can locate them quickly. A hash function computes an integer value from an object. A good hash function minimizes collisions—identical hash codes for different objects. When removing an element from a priority queue, the element with the highest priority is retrieved. A heap is an almost complete tree in which the values of all nodes are at most as large as those of theirdescendants. The regular layout of a heap makes it possible to store heap nodes efficiently in an array. The heapsort algorithm is based on inserting elements into a heap and removing them in sorted order. EXERCISES Review Design Patterns Singleton In software engineering, the singleton pattern is a design pattern used to implement the mathematical concept of a singleton, by restricting the instantiation of a class to one object. This is useful when exactly one object is needed to coordinate actions across the system. The concept is sometimes generalized to systems that operate more efficiently when only one object exists, or that restrict the instantiation to a certain number of objects (say, five). Some consider it an anti-pattern, judging that it is overused, introduces unnecessary limitations in situations where a sole instance of a class is not actually required, and introduces global state into an application. [1][2][3][4][5][6] Applicability: Logger Classes Configuration Classes Accesing resources in shared mode Factories implemented as Singletons
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Problems and implementation: Thread-safe implementation for multi-threading use. Lazy instantiation using double locking mechanism. Iterator In object-oriented programming, the iterator pattern is a design pattern in which an iterator is used to traverse a container and access the container's elements. The iterator pattern decouples algorithms from containers; in some cases, algorithms are necessarily container- specific and thus cannot be decoupled. For example, the hypothetical algorithm SearchForElement can be implemented generally using a specified type of iterator rather than implementing it as a container-specific algorithm. This allows SearchForElement to be used on any container which supports the required type of iterator.
Background image of page 2
Visitor In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure on which it operates. A practical result of this separation is the ability to add new operations to existing object structures without modifying those structures. It is one way to easily follow the open/closed principle. In essence, the visitor allows one to add new virtual functions to a family of classes without
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/30/2011 for the course MECHATRONI EN11ME2050 taught by Professor Perera during the Spring '11 term at Asian Institute of Technology.

Page1 / 14

Hash set - INTRODUCTION The HashSet and TreeSet classes both implement the Set interface An iterator visits all elements in a set A set iterator

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online