GJL: The Generic Java Library

Size: px
Start display at page:

Download "GJL: The Generic Java Library"

Transcription

1 GJL: The Generic Java Library An STL for Java Winter 1999 Semester Project Laboratoire des Méthodes de Programmation Ecole Polytechnique Fédérale de Lausanne Corine Hari February 2000

2 Table of Contents INTRODUCTION...2 MOTIVATION... 2 DOCUMENT ORGANIZATION... 3 GENERIC JAVA...4 POSSIBLE SOLUTIONS...5 STRUCTURE OF GJL...6 CONTAINERS... 6 ITERATORS... 8 FUNCTION OBJECTS ALGORITHMS PROBLEMS ENCOUNTERED AND CHANGES MADE...11 CONCLUSION...12 BIBLIOGRAPHY APPENDIX I: GJL PACKAGE APPENDIX II: FUNCTIONS OBJECTS APPENDIX III. ALGORITHMS APPENDIX IV: CHANGES MADE GJL: The Generic Java Library Corine Hari

3 Introduction C++ has STL, Ada has the Ada Generics Library, but so far no equivalent library exists for Java. The goal of this project was therefore to develop GJL, the Generic Java Library, to provide effective ways to organize data and process it. Motivation A generic library is a library containing different data structures, called containers, and algorithms that can be applied to them. The JDK does already have some ways of dealing with data structures such as Collections, but the possibilities are very limited. Only the most basic access methods are supported and the underlying structure is not really organized in any way. The aim of GJL is to offer different types of data structures, each having specific characteristics optimized. For example, DLists offer fast insertions whereas HashSets are better suited for fast object lookup. Each programmer can then choose the structure that best fits his needs and does not have to rely on a single general implementation. The main interest of GJL however lies in its set of generic algorithms. The idea behind GJL, and all generic libraries, is that many algorithms do not depend on the underlying structure of the container on which they are applied, but only on a few fundamental semantic properties, namely accessing, inserting and deleting elements. For instance, to search for an element with a specific value or to sort the elements of a container, it does not matter whether they are stored in an array or a linked list. All the algorithm needs is to be able to read the values of the elements and, in the case of a sort, to delete them and insert them elsewhere. Adding this level of abstraction between algorithms and containers drastically reduces the amount of code that has to be written. Before, a different version of an algorithm had to be written for every different container. With GJL, creating a new algorithm will mean creating only one version which can be applied on a generic container. The same way, when creating a new container it is not necessary to rewrite new versions of existing algorithms for them to work with this specific container. It is also important to note that the GJL containers and algorithms must be designed to deal with any type of element. This means that they do not have to be rewritten to work with all the different types, which also reduces the amount of code produced. GJL: The Generic Java Library Corine Hari

4 The following figure illustrates this concept: k (Sort, Shuffle, ) i (Integer, String, ) j (Array, HashMap, ) Consider a three-dimensional space, the three dimensions being data types (i), containers (j) and algorithms (k). To cover all the different possibilities, you would have to create i*j*k different pieces of code. However, as the algorithms and containers are generic, the i axis can be dropped, which reduces the number of different versions to j*k. And as we saw that algorithms work on all sorts of containers, this reduces the total number of different pieces of code to j+k. Using a generic library therefore improves software development, as reducing the amount of code reduces development time and simplifies debugging and maintenance. Since there is only one version of each algorithm, finding and fixing bugs is a lot easier. It also increases the portability of code, as there is a standard interface that all data structures should implement. This avoids having each programmer define his own specific classes which are not compatible with anyone else's. Document organization Introduction to GJ (Generic Java) the tool which made it possible to create GJL. Brief description of the possible approaches to the problem and justification of the choice of adapting an existing library, JGL, to obtain GJL. Detailed description of the structure of the library. Problems encountered while porting JGL to GJL and the changes they induced. Comparison of the library produced with the goals set above, noting certain functionalities that have been left out and suggesting possible improvements. GJL: The Generic Java Library Corine Hari

5 Generic Java As mentioned in the introduction, for GJL to be effective it is important that containers and algorithms be generic so as not to have to redefine them for every type. Java does have a mechanism which allows you to do this by having all the containers contain Objects. The problem with this method is that there is no type checking possible. It is up to the programmer to keep track of what is inserted into and extracted from the containers and to make sure the types are coherent. Errors could go undetected until run-time. Moreover, this requires a lot of casts to be inserted into the code. The solution to these problems is parameterized types. With the type parameters being declared explicitly, using the library becomes much safer as type checking is now possible. Errors can be detected at compile-time rather than having to wait until run-time. Much fewer casts have to be inserted as the containers know what type of objects they contain, making the code clearer. All this while still providing the flexibility of generic types which is essential for writing GJL. Up to now this solution did not exist in the Java programming language. As in the case of STL in C++ where Stepanov had to wait for templates to be implemented to create his library, a Generic Java Library could not be efficiently written before parameterized types were added to the language. GJ (Generic Java) is a brand new extension to Java. It is implemented by translation into Java which erases type parameters and inserts the appropriate casts and bridge methods. GJ produces programs that are very similar to what would be written if generics were not available, it simply automates the process. To take full advantage of the potential of GJL, programs should be written in GJ. Using pure Java makes it impossible to parameterize the algorithms and containers and so does not make use of this interesting possibility. GJL does of course support "normal" Java code, as this is equivalent to simply considering the type of the elements to be Object. Additional information on GJ can be found in [1] and [2]. These papers, as well as the GJ compiler, are available for download at GJL: The Generic Java Library Corine Hari

6 Possible solutions After looking into the problem, two different solutions appeared for writing this Generic Java Library. One was to start from scratch, based on the successful design of the C++ STL, and the other was to adapt an existing library, JGL, created by ObjectSpace. I chose the second solution for the following reasons. JGL was created in Since then it has been in public use and currently exists as version 3.1. This leads to believe that it has been extensively tested and must be quite reliable. Starting from scratch would mean giving up all this experience. Also, JGL has probably acquired a following of users during these years. Providing an enhanced version would be more constructive than trying to create a rival one. Moreover, creating a whole new library is much too big of a task for a semester project. I could only have developed a small part of it which would have been useless on its own. So if a library already exists, why does it have to be adapted? As I said before, generic types did not exist in Java until recently. JGL was coded using the means that were available then, that is "pure" Java. This means that JGL is plagued by all the problems that were mentioned in the previous section. Adapting JGL to GJL actually consists of adding generics to the existing code. This makes for a safer, more reliable library. GJL: The Generic Java Library Corine Hari

7 Structure of GJL As mentioned before, GJL consists mainly of containers (data structures that store objects) and algorithms that work on these different containers. But there are two other types of components that have not yet been introduced: iterators and function objects. Iterators are very important in that they are a way of abstracting the access to the containers. They are used to traverse a sequence of elements. Algorithms use them to access the containers, which is consistent with the idea of keeping the algorithms as generic as possible. The figure below illustrates how iterators allow us to separate algorithms from the container implementations: Algorithm Iterator Object Container Function objects, of functors, are a way of representing "executable data". They define operations that can be executed on the elements. All these components are defined in detail below. A complete list of the files composing GJL along with a description of the package structure is given in Appendix I. Containers GJL provides eleven sorts of different containers. Each of these implement a Container interface which defines the following basic methods: add clear clone contents isempty equals remove adds an element to the container removes every element from the container returns a shallow copy of the container returns an Enumeration positioned at the start of the container returns true if the container contains no elements returns true if the contents match those of another container of the same type removes element(s) represented by Enumerations GJL: The Generic Java Library Corine Hari

8 size/maxsize start/finish tostring returns current/maximum number of elements in container returns an iterator positioned at the start/finish of the container returns a string that describes the container These methods only use basic properties of objects and so do not depend on the type of object they contain. These are the only methods that the algorithms should use to make sure they can be applied on any type of container. The containers then differ in the way their elements are arranged and if they use keys for sorting purposes. This defines two big groups of containers: sequence and associative. Sequence containers organize their elements in a strictly linear arrangement. They all provide the following methods: pushfront/pushback popfront/popback front/back at/put remove replace count indexof contains insert an item at the beginning/end remove and return the item positioned at the beginning/ end return the first/last item return/replace the item at a specified index remove a particular value replace one value with another count the number of matching elements return the index of a particular element return true if a particular element is present The performance of these methods will vary depending on the type of sequence. The programmer must choose among the following types of sequence containers for the ones that best fit his purpose: Array Deque DList SList Linear, contiguous storage; fast inserts at the end only Linear, noncontiguous storage; fast inserts at extremities Doubly linked list; fast inserts anywhere Singly linked list; fast inserts at extremities A few additional types of sequence containers are provided which are simply restricted versions of the other types. Certain operations are not allowed, which results in the simulation of a stack or queue: Stack LIFO data structure Queue FIFO data structure PriorityQueue queue that pops elements in a sorted order Associative containers are containers that provide fast retrieval of the elements based on keys. GJL has Sets, that deal with the key internally, and Maps, that allow the user to specify the key. The objects can be stored randomly or can be ordered based on the key. Duplicates can be allowed or disallowed, which gives us the functionality of multisets and multimaps of STL. This summarizes the available associative containers and their characteristics: GJL: The Generic Java Library Corine Hari

9 HashSet OrderedSet HashMap OrderedMap Stores elements by hash Stores and orders elements by hash Stores elements by key; 1-to-1 or 1-to-many mappings Stores and orders elements by key; 1-to-1 or 1-to-many mappings The following figure gives an overview of the different containers available and how they relate to each other. container sequence set map array deque dlist slist priority queue queue stack hashset ordered set hashmap ordered map Iterators In STL iterators are "a generalization of pointers that allow a programmer to work with different data structures (containers) in a uniform manner" 1. In Java the concept of pointers does not exist, but iterators do provide a way of abstracting the access to containers, making it possible to work with the different structures "in a uniform manner". Iterators are organized in five categories, each having a set of particular requirements that have to be satisfied. The two basic types of iterators are input and output iterators, which simply traverse the associated container and can read from, respectively write to, it. As those two abilities taken separately are not much use, forward iterators combine them both to produce an iterator that can traverse a container and read and/or write each element. This iterator cannot back up, however. This functionality is added to obtain a bidirectional iterator. The last type of iterator is the random access iterator. This iterator satisfies all the requirements of a bidirectional iterator, but also provides the ability to jump from any place to any other. The following figure illustrates the relationships between the different iterators: 1 Meng Lee, Alexander Stepanov : The Standard Template Library GJL: The Generic Java Library Corine Hari

10 input iterator output iterator forward iterator bidirectional iterator random-access iterator Each GJL container has an associated iterator class. Most are random access iterators, however some are limited to bidirectional, or even forward, iterators. That is because only the functions that are realizable in (amortized) constant time are defined. For example, random access in a list takes linear time, so random access is not provided. Only efficient functions are implemented. The following table shows the highest iterator category that can be used with each container: Array Deque Dlist HashMap HashSet OrderedMap OrderedSet PriorityQueue Queue Slist Stack RandomAccessIterator RandomAccessIterator BidirectionalIterator ForwardIterator ForwardIterator BidirectionalIterator BidirectionalIterator RandomAccessIterator Same as underlying sequence ForwardIterator Same as underlying sequence GJL: The Generic Java Library Corine Hari

11 Function objects Function objects are yet another essential tool for making algorithms generic. For example, there are algorithms that apply a function to each object in a container. They take a function object as parameter which specifies the function that has to be applied. The actual mechanism of traversing a container and applying the function to each element only has to be written once. There are two types of function objects: functions and predicates. Functions perform an operation on one or more arguments and return a result. This result is often reinserted into the container. Predicates return a Boolean and are generally used as the comparator for ordering elements or to trigger an action. GJL defines interfaces for unary and binary functions and predicates which simply have an execute method. Users can easily implement these interfaces to create their own function objects. A large set of standard functions and predicates is also provided in gjl.functions and gjl.predicates. See Appendix II for complete list and descriptions. Algorithms The GJL algorithms are designed to perform operations on containers. But to be kept as generic as possible they operate on iterators that specify all or part of a container. This way the algorithms can work on different types of containers, sub-ranges of containers and any object that satisfies the iterator interface. The algorithms can be divided into four categories: mutating operations, non-mutating operations, sorting and related operations and generalized numeric operations. Mutating operations include algorithms that modify the contents of the container, such as transforming, replacing, shuffling, etc. Non-mutating algorithms are those that do things like find elements or count the number of elements with a certain value, which doesn't modify the container. Sorting operations are of course sorts and related operations such as finding the minimum or maximum of a sequence. Examples of generalized numeric operations are summing the values or calculating the adjacent difference between the elements of a container. It is important to note that operations like comparisons for sorts, or even summing, are defined by a function object that can be specified by the user. A list of all the GJL algorithms with a short description of each is included in Appendix III. GJL: The Generic Java Library Corine Hari

12 Problems encountered and changes made Although the goal at first was to produce a library that would be fully backwards-compatible with JGL, some of the structures used were impossible to adapt in GJL. ObjectSpace sometimes took advantage of the fact that all elements were Objects, allowing them to reference different things depending on the dynamic context. This sort of thing is not possible with GJ which demands that types be specified at compile-time. Consequently, the implementation of GJL is sometimes a little more restrictive, but this also makes it safer. Although correct, JGL's implementation left more room for errors when using the library. Adding types detected these potentially dangerous situations which would otherwise have been more difficult to find. Adding parameterized types also helped to detect another flaw in JGL, this time in design. Here is the specific example: the Map containers implement both the Container and Dictionary (from JDK) interfaces. Both interfaces contained an elements() method which for a Container returned an Enumeration of elements (in this case key/value pairs) and for a Dictionary an Enumeration of values. In the JGL version, as both returned Objects, it was not apparent that the types were not compatible. When adding generic types however, it was obvious that this implementation was impossible and that one of the two methods had to be renamed. This led to one of the most noticeable differences between GJL and JGL: all GJL containers have a contents() method which return an Enumeration of their elements, whereas in JGL containers, this method is named elements(). From that moment on, full compatibility between GJL and JGL became impossible, so whenever little modifications could be made to improve the code, they were done even if they affected some method signatures. Some could have been avoided or worked around to be compatible with JGL, but as compatibility was not an option anymore, this was not done. A detailed list of all the changes that could affect programs written using JGL is in Appendix IV for reference. GJL: The Generic Java Library Corine Hari

13 Conclusion This library was first intended to be fully compatible with JGL. This, however, is not the case as some modifications were necessary to correct flaws in the design. The changes that have been made are minor, though, and users that are familiar with JGL would have no problem adapting to GJL. There are two parts of the JGL package that have not yet been ported to GJL. These are Adapters and Voyager objects. Adapters are used to allow native Java arrays and JDK data structures to behave like a JGL container, which allows algorithms to be applied to these structures. This was not implemented in this version of GJL, namely because of time constraints, but it could be a useful addition to make in the future. Until then this functionality can easily be replaced with GJL Arrays using the object equivalent of the primitives. The Voyager package is a version of the collection classes that can be used in a distributed fashion with ObjectSpace Voyager 1.0. This package was not considered during the course of this project, but it could be developed for a future version of GJL. What was produced in the course of this project is a safe version of the core functionalities of a Generic Java Library. Its modular design makes it easily extendable to incorporate new data structures, algorithms and function objects. However a very complete set of these is already provided. This project also demonstrated the usefulness of adding parameterized types to the Java programming language. While offering all the flexibility needed if properly used, GJ restricts programming styles that could lead to unsafe situations. GJL: The Generic Java Library Corine Hari

14 Bibliography [1] Gilad Bracha, Martin Odersky, David Stoutamire, PhilipWadler GJ: Extending the Java programming language with type parameters August [2] Gilad Bracha, Martin Odersky, David Stoutamire, Philip Wadler GJ Specification May 1998 [3] Philip Wadler GJ: A Generic Java Dr. Dobb's Journal February 2000 [4] Johannes Weidl The Standard Template Library Tutorial April 1996 [5] Jak Kirman A modest STL tutorial January 1998 [6] ObjectSpace JGL Documentation; GJL: The Generic Java Library Corine Hari

15 Appendix I: GJL package files gjl package: Containers Array.java Container.java DList.java Deque.java HashMap.java HashSet.java Map.java OrderedMap.java OrderedSet.java PriorityQueue.java Queue.java SList.java Sequence.java Set.java Stack.java Iterators ArrayIterator.java BidirectionalIterator.java DListIterator.java DequeIterator.java ForwardIterator.java HashMapIterator.java HashSetIterator.java InputIterator.java OrderedMapIterator.java OrderedSetIterator.java OutputIterator.java RandomAccessIterator.java SListIterator.java Function Objects BinaryFunction.java BinaryPredicate.java UnaryFunction.java UnaryPredicate.java Auxiliary Classes InvalidOperationException.java Opaque.java Pair.java PairIteratorFirst.java PairIteratorSecond.java Range.java Tree.java TreePair.java gjl.algorithms package Applying.java Comparing.java Copying.java Counting.java Filling.java Filtering.java Finding.java Hashing.java Heap.java MinMax.java OrderedSetOperations.java Permuting.java Predicates.java Printing.java Removing.java Replacing.java Reversing.java Rotating.java SetOperations.java Shuffling.java Sorting.java Swapping.java Transforming.java GJL: The Generic Java Library Corine Hari

16 gjl.functions package BinaryCompose.java BinaryPredicateFunction.java BindFirst.java BindSecond.java ConstantFunction.java DividesNumber.java Hash.java IdentityFunction.java LengthString.java MinusNumber.java ModulusNumber.java NegateNumber.java NumberHelper.java PlusNumber.java PlusString.java Print.java SelectFirst.java SelectSecond.java SwappedBinaryFunction.java TimesNumber.java ToString.java UnaryCompose.java UnaryPredicateFunction.java gjl.predicates package BinaryAnd.java BinaryComposePredicate.java BinaryNot.java BinaryOr.java BinaryTern.java BindFirstPredicate.java BindSecondPredicate.java ConstantPredicate.java EqualCollationKey.java EqualCollator.java EqualNumber.java EqualString.java EqualTo.java GreaterCollationKey.java GreaterCollator.java GreaterEqualCollationKey.java GreaterEqualCollator.java GreaterEqualNumber.java GreaterEqualString.java GreaterNumber.java GreaterString.java HashComparator.java IdenticalTo.java InstanceOf.java LessCollationKey.java LessCollator.java LessEqualCollationKey.java LessEqualCollator.java LessEqualNumber.java LessEqualString.java LessNumber.java LessString.java LogicalAnd.java LogicalNot.java LogicalOr.java NegativeNumber.java NotEqualCollationKey.java NotEqualCollator.java NotEqualNumber.java NotEqualString.java NotEqualTo.java NotIdenticalTo.java NumberHelper.java PositiveNumber.java SwappedBinaryPredicate.java UnaryAnd.java UnaryComposePredicate.java UnaryNot.java UnaryOr.java UnaryTern.java gjl.util package Benchmark.java ConditionalEnumeration.java InsertIterator.java ObjectOutputStreamIterator.java OutputStreamIterator.java Randomizer.java ReverseIterator.java GJL: The Generic Java Library Corine Hari

17 Appendix II: Functions Objects Predicates x and y represent arguments to execute() P, Q, and R represent other predicate objects C represents an instance of a java.lang.class object V represents a constant value Unary Predicates BindFirstPredicate P( V, x ) BindSecondPredicate P( x, V ) ConstantPredicate V InstanceOf x instanceof C LogicalNot!x NegativeNumber x < 0 PositiveNumber x > 0 UnaryAnd P( x ) && Q( x ) UnaryComposePredicate P( Q( x ) ) UnaryNot!P( x ) UnaryOr P( x ) Q( x ) UnaryTern P( x )? Q( x ) : R( x ) Binary Predicates BinaryAnd P( x, y ) && Q( x, y ) BinaryComposePredicate P( Q( x ), R( y ) ) BinaryNot!P( x, y ) BinaryOr P( x, y ) Q( x, y ) BinaryTern P( x, y )? Q( x, y ) : R( x, y ) ConstantPredicate V EqualCollationKey x.compareto( y ) == 0 EqualCollator collator.compare( x, y ) == 0 EqualNumber x == y EqualString x.tostring().equals( y.tostring() ) EqualTo x.equals( y ) GreaterEqualCollationKey (collator.getcollationkey(x.tostring())).compare( collator.getcollationkey( y.tostring() ) ) >= 0 GreaterEqualCollator collator.compare( x.tostring(), y.tostring() ) <= 0 GreaterEqualNumber x >= y GreaterEqualString x.tostring().compareto( y.tostring() ) >= 0 GJL: The Generic Java Library Corine Hari

18 GreaterCollationKey (collator.getcollationkey(x.tostring())).compare( collator.getcollationkey( y.tostring() ) ) > 0 GreaterCollator collator.compare( x.tostring(), y.tostring() ) > 0 GreaterNumber x > y GreaterString x.tostring().compareto( y.tostring() ) > 0 HashComparator x.hashcode() < y.hashcode() IdenticalTo x == y LessEqualCollationKey collator.getcollationkey(x.tostring())).compare( collator.getcollationkey( y.tostring() ) ) <= 0 LessEqualCollator collator.compare( x.tostring(), y.tostring() ) <= 0 LessEqualNumber x <= y LessEqualString x.tostring().compareto( y.tostring() ) <= 0 LessCollationKey (collator.getcollationkey(x.tostring())).compare( collator.getcollationkey( y.tostring() ) ) < 0 LessCollator collator.compare( x.tostring(), y.tostring() ) < 0 LessNumber x < y LessString x.tostring().compareto( y.tostring() ) < 0 LogicalAnd x && y LogicalOr x y NotEqualCollationKey x.compareto( y )!= 0 NotEqualCollator collator.compare( x, y )!= 0 NotEqualNumber x!= y NotEqualString!x.toString().equals( y.tostring() ) NotEqualTo!x.equals( y ) NotIdenticalTo x!= y SwappedBinaryPredicate P( y, x ) GJL: The Generic Java Library Corine Hari

19 Functions x and y represent arguments to execute() P, Q and R represent other function objects V represents a constant value Unary Functions BindFirst P( V, x ) BindSecond P( x, V ) ConstantFunction V Hash x.hashcode() IdentityFunction x LengthString x.tostring().length() NegateNumber -x SelectFirst x.first SelectSecond x.second ToString x.tostring() UnaryCompose P( Q( x ) ) UnaryPredicateFunction P( x ) Binary Functions BinaryCompose P( Q( x ), R( y ) ) BinaryPredicateFunction P( x, y ) ConstantFunction V DividesNumber x / y MinusNumber x - y ModulusNumber x % y PlusNumber x + y PlusString x.tostring() + y.tostring() SwappedBinaryFunction P( y, x ) TimesNumber x * y GJL: The Generic Java Library Corine Hari

20 Appendix III. Algorithms All algorithms are implemented as static methods of their class. Applying foreach() inject() apply a function to every item in a range iteratively apply a binary function to every item in a range Comparing equal() check that two sequences match lexicographicalcompare() lexicographically compare two sequences median() return the median of three values mismatch() search two sequences for a mismatched item Copying copy() copybackward() Counting accumulate() adjacentdifference() count() countif() Filling fill() filln() Filtering reject() select() unique() uniquecopy() Finding adjacentfind() detect() every() find() findif() some() Heap makeheap() copy a range of items to another area copy a range of items backwards to another area sum the values in a range calculate and sum the difference between adjacent values count items in a range that match a value count items in a range that satisfy a predicate set every item in a range to a particular value set n items to a particular value return all values that do not satisfy a predicate return all values that satisfy a predicate collapse all consecutive values in a sequence copy a sequence, collapsing consecutive values locate consecutive sequence in a range return first item that satisfies a predicate return true if every item in a range satisfies a predicate locate an item in a sequence locate an item that satisfies a predicate in a range return true if at least one item in a range satisfies a predicate make a sequence into a heap GJL: The Generic Java Library Corine Hari

21 popheap() pushheap() sortheap() MinMax minelement() maxelement() Permuting nextpermutation() prevpermutation() Printing print() println() tostring() Removing remove() removecopy() removecopyif() removeif() Replacing. replace() replacecopy() replacecopyif() replaceif() Reversing reverse() reversecopy() Rotating rotate() rotatecopy() pop the top value from a heap place the last element into a heap sort a heap return the minimum item within a range return the maximum item within a range change sequence to next lexicographic permutation change sequence to previous lexicographic permutation prints a sequence to standard output prints a sequence to standard output followed by a newline returns a description of a sequence remove all matching items from a sequence copy a sequence, removing all matching items copy sequence, removing all that satisfy predicate remove items that satisfy predicate from sequence replace specified value in a sequence with another copy sequence, replacing matching values copy sequence, replacing values that satisfy predicate replace specified values that satisfy a predicate reverse the items in a sequence create a reversed copy of a sequence rotate a sequence by n positions copy a sequence, rotating it by n positions SetOperations includes() search for one sequence in another sequence setdifference() create set of elements in 1st sequence that are not in 2nd setintersection() create set of ele ments that are in both sequences setsymmetricdifference() create set of elements that not in both sequences setunion() create set of elements that are in either sequence GJL: The Generic Java Library Corine Hari

22 Shuffling randomshuffle() Sorting itersort() sort() Swapping iterswap() swapranges() Transforming collect() transform() randomize sequence using random shuffles create iterators that will traverse a container in a sorted manner without reordering the container itself sort a sequence swap the values indicated by two iterators swap two ranges of items return result of applying a function to every item in a range transform one sequence into another GJL: The Generic Java Library Corine Hari

23 Appendix IV: Changes made gjl.container.java public Enumeration<A> elements() was changed to public Enumeration<A> contents() for reasons explained in the text. This change was applied to all the containers. gjl.*mapiterator.java In JGL these iterators were designed to be able to iterate over keys, values or key/value pairs. As it was not possible in GJL to have iterators over different types, they were restricted to the key/value pairs. This caused the disappearance of the 'mode' variable. As a value for this variable was passed into most constructors, the signature of these methods have changed. gjl.orderedmap.java int remove (A key) was changed to B remove (A key) to match the Dictionary interface B add () was changed to Pair<A,B> add() to match Map interface gjl.tree.java Class was made non final to be able to extend it to TreePair gjl.functions.*number.java The 'class' variable which was used to determine what type of number the function was being passed is now useless and was removed. This affected the signature of the constructors. New classes: gjl.treepair.java A class that extends the red-black tree implementation in Tree.java to adapt it for key/value pairs. Used for OrderedMaps gjl.pairiteratorfirst.java, gjl.pairiteratorsecond.java Iterators that iterate over the first, respectively second, elements of an iterator of Pairs. gjl.predicates.constantunarypredicate.java, gjl.predicates.constantbinarypredicate.java gjl.functions.constantunaryfunction.java, gjl.functions.constantbinaryfunctions.java Replace ConstantPredicate.java and ConstantFunction.java. Classes that were removed: gjl.algos.java gjl.algorithms.predicates.java gjl.xhashcomp.java gjl.xequalto.java These classes contained copies of methods from other packages. As the methods copied are publicly accessible and having the same code duplicated makes maintenance harder, these copies were removed. GJL: The Generic Java Library Corine Hari

Generic Programming with JGL 4

Generic Programming with JGL 4 Generic Programming with JGL 4 By John Lammers Recursion Software, Inc. July 2004 TABLE OF CONTENTS Abstract...1 Introduction to Generic Programming...1 How does Java support generic programming?...2 The

More information

Lecture 21 Standard Template Library. A simple, but very limited, view of STL is the generality that using template functions provides.

Lecture 21 Standard Template Library. A simple, but very limited, view of STL is the generality that using template functions provides. Lecture 21 Standard Template Library STL: At a C++ standards meeting in 1994, the committee voted to adopt a proposal by Alex Stepanov of Hewlett-Packard Laboratories to include, as part of the standard

More information

Major Language Changes, pt. 1

Major Language Changes, pt. 1 C++0x What is C++0x? Updated version of C++ language. Addresses unresolved problems in C++03. Almost completely backwards compatible. Greatly increases expressiveness (and complexity!) of language. Greatly

More information

To use various types of iterators with the STL algorithms ( ). To use Boolean functions to specify criteria for STL algorithms ( 23.8).

To use various types of iterators with the STL algorithms ( ). To use Boolean functions to specify criteria for STL algorithms ( 23.8). CHAPTER 23 STL Algorithms Objectives To use various types of iterators with the STL algorithms ( 23.1 23.20). To discover the four types of STL algorithms: nonmodifying algorithms, modifying algorithms,

More information

CS11 Advanced C++ Fall Lecture 1

CS11 Advanced C++ Fall Lecture 1 CS11 Advanced C++ Fall 2006-2007 Lecture 1 Welcome! ~8 lectures Slides are posted on CS11 website http://www.cs.caltech.edu/courses/cs11 ~6 lab assignments More involved labs 2-3 week project at end CS

More information

Data_Structures - Hackveda

Data_Structures - Hackveda Data_Structures - Hackveda ( Talk to Live Mentor) Become a Data Structure and Algorithm Professional - (Beginner - Advanced) Skill level: Beginner - Advanced Training fee: INR 15999 only (Topics covered:

More information

Boost.Compute. A C++ library for GPU computing. Kyle Lutz

Boost.Compute. A C++ library for GPU computing. Kyle Lutz Boost.Compute A C++ library for GPU computing Kyle Lutz GPUs (NVIDIA, AMD, Intel) Multi-core CPUs (Intel, AMD) STL for Parallel Devices Accelerators (Xeon Phi, Adapteva Epiphany) FPGAs (Altera, Xilinx)

More information

New Iterator Concepts

New Iterator Concepts New Iterator Concepts Author: David Abrahams, Jeremy Siek, Thomas Witt Contact: dave@boost-consulting.com, jsiek@osl.iu.edu, witt@styleadvisor.com Organization: Boost Consulting, Indiana University Open

More information

Unit 4 Basic Collections

Unit 4 Basic Collections Unit 4 Basic Collections General Concepts Templates Exceptions Iterators Collection (or Container) Classes Vectors (or Arrays) Sets Lists Maps or Tables C++ Standard Template Library (STL Overview A program

More information

CS11 Introduction to C++ Spring Lecture 8

CS11 Introduction to C++ Spring Lecture 8 CS11 Introduction to C++ Spring 2013-2014 Lecture 8 Local Variables string getusername() { string user; } cout user; return user;! What happens to user when function

More information

COEN244: Class & function templates

COEN244: Class & function templates COEN244: Class & function templates Aishy Amer Electrical & Computer Engineering Templates Function Templates Class Templates Outline Templates and inheritance Introduction to C++ Standard Template Library

More information

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003

Data Structures. COMS W1007 Introduction to Computer Science. Christopher Conway 1 July 2003 Data Structures COMS W1007 Introduction to Computer Science Christopher Conway 1 July 2003 Linked Lists An array is a list of elements with a fixed size, accessed by index. A more flexible data structure

More information

Chapter 5. The Standard Template Library.

Chapter 5. The Standard Template Library. Object-oriented programming B, Lecture 11e. 1 Chapter 5. The Standard Template Library. 5.1. Overview of main STL components. The Standard Template Library (STL) has been developed by Alexander Stepanov,

More information

(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University

(8 1) Container Classes & Class Templates D & D Chapter 18. Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University (8 1) Container Classes & Class Templates D & D Chapter 18 Instructor - Andrew S. O Fallon CptS 122 (October 8, 2018) Washington State University Key Concepts Class and block scope Access and utility functions

More information

C++ Standard Template Library

C++ Standard Template Library C++ Standard Template Library CS 247: Software Engineering Principles Generic Algorithms A collection of useful, typesafe, generic (i.e., type-parameterized) containers that - know (almost) nothing about

More information

More STL algorithms. Design Decisions. Doc No: N2569= Reply to: Matt Austern Date:

More STL algorithms. Design Decisions. Doc No: N2569= Reply to: Matt Austern Date: Doc No: N2569=08-0079 Reply to: Matt Austern Date: 2008-02-29 More STL algorithms This paper proposes a number of nonstandard STL-style algorithms for inclusion in the standard. Nothing

More information

Contents. 2 Introduction to C++ Programming,

Contents. 2 Introduction to C++ Programming, cppfp2_toc.fm Page vii Thursday, February 14, 2013 9:33 AM Chapter 24 and Appendices F K are PDF documents posted online at www.informit.com/title/9780133439854 Preface xix 1 Introduction 1 1.1 Introduction

More information

Foundations of Programming, Volume I, Linear structures

Foundations of Programming, Volume I, Linear structures Plan 1. Machine model. Objects. Values. Assignment, swap, move. 2. Introductory algorithms: advance, distance, find, copy. Iterators: operations, properties, classification. Ranges and their validity.

More information

When we program, we have to deal with errors. Our most basic aim is correctness, but we must

When we program, we have to deal with errors. Our most basic aim is correctness, but we must Chapter 5 Errors When we program, we have to deal with errors. Our most basic aim is correctness, but we must deal with incomplete problem specifications, incomplete programs, and our own errors. When

More information

Standard ADTs. Lecture 19 CS2110 Summer 2009

Standard ADTs. Lecture 19 CS2110 Summer 2009 Standard ADTs Lecture 19 CS2110 Summer 2009 Past Java Collections Framework How to use a few interfaces and implementations of abstract data types: Collection List Set Iterator Comparable Comparator 2

More information

+ Abstract Data Types

+ Abstract Data Types Linked Lists Abstract Data Types An Abstract Data Type (ADT) is: a set of values a set of operations Sounds familiar, right? I gave a similar definition for a data structure. Abstract Data Types Abstract

More information

The Standard Template Library. An introduction

The Standard Template Library. An introduction 1 The Standard Template Library An introduction 2 Standard Template Library (STL) Objective: Reuse common code Common constructs: Generic containers and algorithms STL Part of the C++ Standard Library

More information

19.1 The Standard Template Library

19.1 The Standard Template Library Chapter 19: The Template Library From a review of Effective STL : 50 Specific Ways to Improve Your Use of the Standard Template Library by ScottMeyers: It s hard to overestimate the importance of the Standard

More information

Deitel Series Page How To Program Series

Deitel Series Page How To Program Series Deitel Series Page How To Program Series Android How to Program C How to Program, 7/E C++ How to Program, 9/E C++ How to Program, Late Objects Version, 7/E Java How to Program, 9/E Java How to Program,

More information

More STL algorithms (revision 2)

More STL algorithms (revision 2) Doc No: N2666=08-0176 Reply to: Matt Austern Date: 2008-06-11 More STL algorithms (revision 2) This paper proposes a number of nonstandard STL-style algorithms for inclusion in the

More information

Objects Managing a Resource

Objects Managing a Resource Objects Managing a Resource 1 What is a Resource Respects Release/Acquire protocol files (open/close) memory allocation (allocate/free) locks (acquire/release). 2 What is a Resource Objects when constructed,

More information

C and C++ Courses. C Language

C and C++ Courses. C Language C Language The "C" Language is currently one of the most widely used programming languages. Designed as a tool for creating operating systems (with its help the first Unix systems were constructed) it

More information

Lecture-5. STL Containers & Iterators

Lecture-5. STL Containers & Iterators Lecture-5 STL Containers & Iterators Containers as a form of Aggregation Fixed aggregation An object is composed of a fixed set of component objects Variable aggregation An object is composed of a variable

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

Advanced C++ STL. Tony Wong

Advanced C++ STL. Tony Wong Tony Wong 2017-03-25 C++ Standard Template Library Algorithms Sorting Searching... Data structures Dynamically-sized array Queues... The implementation is abstracted away from the users The implementation

More information

Linked Lists and Abstract Data Structures A brief comparison

Linked Lists and Abstract Data Structures A brief comparison Linked Lists and Abstract Data A brief comparison 24 March 2011 Outline 1 2 3 4 Data Data structures are a key idea in programming It s just as important how you store the data as it is what you do to

More information

CIS 190: C/C++ Programming. Lecture 12 Student Choice

CIS 190: C/C++ Programming. Lecture 12 Student Choice CIS 190: C/C++ Programming Lecture 12 Student Choice Outline Hash Maps Collisions Using Open Addressing Collisions Chaining Collisions In C++ C++ STL Containers C++ GUI Resources Hash Maps (AKA Hash Tables)

More information

MODULE 37 --THE STL-- ALGORITHM PART V

MODULE 37 --THE STL-- ALGORITHM PART V MODULE 37 --THE STL-- ALGORITHM PART V My Training Period: hours Note: Compiled using Microsoft Visual C++.Net, win32 empty console mode application. g++ compilation example is given at the end of this

More information

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell

Hash Tables. CS 311 Data Structures and Algorithms Lecture Slides. Wednesday, April 22, Glenn G. Chappell Hash Tables CS 311 Data Structures and Algorithms Lecture Slides Wednesday, April 22, 2009 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks CHAPPELLG@member.ams.org 2005

More information

MODULE 35 --THE STL-- ALGORITHM PART III

MODULE 35 --THE STL-- ALGORITHM PART III MODULE 35 --THE STL-- ALGORITHM PART III My Training Period: hours Note: Compiled using Microsoft Visual C++.Net, win32 empty console mode application. g++ compilation example is given at the end of this

More information

Data Structure. Recitation III

Data Structure. Recitation III Data Structure Recitation III Topic Binary Search Abstract Data types Java Interface Linked List Binary search Searching a sorted collection is a common task. A dictionary is a sorted list of word definitions.

More information

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University

Lecture 6. COMP1006/1406 (the OOP course) Summer M. Jason Hinek Carleton University Lecture 6 COMP1006/1406 (the OOP course) Summer 2014 M. Jason Hinek Carleton University today s agenda assignments A1,A2,A3 are all marked A4 marking just started A5 is due Friday, A6 is due Monday a quick

More information

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada

Data Structures - CSCI 102. CS102 Hash Tables. Prof. Tejada. Copyright Sheila Tejada CS102 Hash Tables Prof. Tejada 1 Vectors, Linked Lists, Stack, Queues, Deques Can t provide fast insertion/removal and fast lookup at the same time The Limitations of Data Structure Binary Search Trees,

More information

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library

Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library Unit 1: Preliminaries Part 4: Introduction to the Standard Template Library Engineering 4892: Data Structures Faculty of Engineering & Applied Science Memorial University of Newfoundland May 6, 2010 ENGI

More information

Unifying Operator and Function-Object Variants of Standard Library Algorithms

Unifying Operator and Function-Object Variants of Standard Library Algorithms Unifying Operator and Function-Object Variants of Standard Library Algorithms Author: Douglas Gregor, Indiana University Document number: N2743=08-0253 Date: 2008-08-25 Project: Programming Language C++,

More information

C++ How To Program 10 th Edition. Table of Contents

C++ How To Program 10 th Edition. Table of Contents C++ How To Program 10 th Edition Table of Contents Preface xxiii Before You Begin xxxix 1 Introduction to Computers and C++ 1 1.1 Introduction 1.2 Computers and the Internet in Industry and Research 1.3

More information

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17

/633 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/27/17 01.433/33 Introduction to Algorithms Lecturer: Michael Dinitz Topic: Priority Queues / Heaps Date: 9/2/1.1 Introduction In this lecture we ll talk about a useful abstraction, priority queues, which are

More information

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

36. Collections. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 36. Collections Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Introduction Arrays Class Interface Collection and Class Collections ArrayList Class Generics LinkedList Class Collections Algorithms

More information

Working Draft, Technical Specification for C++ Extensions for Parallelism, Revision 1

Working Draft, Technical Specification for C++ Extensions for Parallelism, Revision 1 Document Number: N3960 Date: 2014-02-28 Reply to: Jared Hoberock NVIDIA Corporation jhoberock@nvidia.com Working Draft, Technical Specification for C++ Extensions for Parallelism, Revision 1 Note: this

More information

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct.

MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. MID TERM MEGA FILE SOLVED BY VU HELPER Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the elements may locate at far positions

More information

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures

Purpose of Review. Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures C++ Review 1 Purpose of Review Review some basic C++ Familiarize us with Weiss s style Introduce specific constructs useful for implementing data structures 2 Class The Class defines the data structure

More information

Generics in Java and Beyond

Generics in Java and Beyond Generics in Java and Beyond Martin Buechi 2001 by Martin Büchi 1 Overview Generics Abstraction of generic concepts. C++ templates (STL), parameterized types, ML polymorphic data types and functions, Beta

More information

Parallelism and Concurrency in C++17 and C++20. Rainer Grimm Training, Coaching and, Technology Consulting

Parallelism and Concurrency in C++17 and C++20. Rainer Grimm Training, Coaching and, Technology Consulting Parallelism and Concurrency in C++17 and C++20 Rainer Grimm Training, Coaching and, Technology Consulting www.grimm-jaud.de Multithreading and Parallelism in C++ Multithreading in C++17 Parallel STL The

More information

Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING)

Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING) Java Data Structures Collections Framework BY ASIF AHMED CSI-211 (OBJECT ORIENTED PROGRAMMING) What is a Data Structure? Introduction A data structure is a particular way of organizing data using one or

More information

Introduction to Programming Using Java (98-388)

Introduction to Programming Using Java (98-388) Introduction to Programming Using Java (98-388) Understand Java fundamentals Describe the use of main in a Java application Signature of main, why it is static; how to consume an instance of your own class;

More information

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement

9/21/17. Outline. Expression Evaluation and Control Flow. Arithmetic Expressions. Operators. Operators. Notation & Placement Outline Expression Evaluation and Control Flow In Text: Chapter 6 Notation Operator evaluation order Operand evaluation order Overloaded operators Type conversions Short-circuit evaluation of conditions

More information

MODULE 33 --THE STL-- ALGORITHM PART I

MODULE 33 --THE STL-- ALGORITHM PART I MODULE 33 --THE STL-- ALGORITHM PART I My Training Period: hours Note: Compiled using Microsoft Visual C++.Net, win32 empty console mode application. g++ compilation examples given at the end of this Module.

More information

Programming in C++ using STL. Rex Jaeschke

Programming in C++ using STL. Rex Jaeschke Programming in C++ using STL Rex Jaeschke Programming in C++ using STL 1997, 1999, 2002, 2007, 2009 Rex Jaeschke. All rights reserved. Edition: 2.0 All rights reserved. No part of this publication may

More information

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph Prelim 2 CS 2110, 16 November 2017, 7:30 PM 1 2 3 4 5 6 7 Total Question Name Short Heaps Tree Collections Sorting Graph answer Max 1 18 10 25 10 16 20 100 Score Grader The exam is closed book and closed

More information

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts)

CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) CISC220 Lab 2: Due Wed, Sep 26 at Midnight (110 pts) For this lab you may work with a partner, or you may choose to work alone. If you choose to work with a partner, you are still responsible for the lab

More information

Java Collections Framework

Java Collections Framework Java Collections Framework Introduction In this article from my free Java 8 course, you will be given a high-level introduction of the Java Collections Framework (JCF). The term Collection has several

More information

About this exam review

About this exam review Final Exam Review About this exam review I ve prepared an outline of the material covered in class May not be totally complete! Exam may ask about things that were covered in class but not in this review

More information

More about The Competition

More about The Competition Data Structure I More about The Competition TLE? 10 8 integer operations, or 10 7 floating point operations, in a for loop, run in around one second for a typical desktop PC. Therefore, if n = 20, then

More information

Standard Template Library

Standard Template Library Standard Template Library The standard template library (STL) contains CONTAINERS ALGORITHMS ITERATORS A container is a way that stored data is organized in memory, for example an array of elements. Algorithms

More information

Type Checking and Type Equality

Type Checking and Type Equality Type Checking and Type Equality Type systems are the biggest point of variation across programming languages. Even languages that look similar are often greatly different when it comes to their type systems.

More information

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING

4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING 4.1 COMPUTATIONAL THINKING AND PROBLEM-SOLVING 4.1.2 ALGORITHMS ALGORITHM An Algorithm is a procedure or formula for solving a problem. It is a step-by-step set of operations to be performed. It is almost

More information

Data Structures and Abstractions with Java

Data Structures and Abstractions with Java Global edition Data Structures and Abstractions with Java Fourth edition Frank M. Carrano Timothy M. Henry Data Structures and Abstractions with Java TM Fourth Edition Global Edition Frank M. Carrano University

More information

Einführung in die Programmierung Introduction to Programming

Einführung in die Programmierung Introduction to Programming Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Prof. Dr. Bertrand Meyer Lecture 14: Container Data Structures Topics for this lecture Containers and genericity

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss another important ADT: PriorityQueue. Like stacks and queues, priority queues store arbitrary collections

More information

Containers and genericity. A standardized naming scheme. Cursor properties. Lists. Adding a cell. A specific implementation: (singly) linked lists

Containers and genericity. A standardized naming scheme. Cursor properties. Lists. Adding a cell. A specific implementation: (singly) linked lists Topics for this lecture Chair of Software Engineering Einführung in die Programmierung Introduction to Programming Containers and genericity Container operations Prof. Dr. Bertrand Meyer Lists October

More information

Distributed Real-Time Control Systems. Lecture 16 C++ Libraries Templates

Distributed Real-Time Control Systems. Lecture 16 C++ Libraries Templates Distributed Real-Time Control Systems Lecture 16 C++ Libraries Templates 1 C++ Libraries One of the greatest advantages of C++ is to facilitate code reuse. If code is well organized and documented into

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

CS11 Advanced C++ Spring 2018 Lecture 2

CS11 Advanced C++ Spring 2018 Lecture 2 CS11 Advanced C++ Spring 2018 Lecture 2 Lab 2: Completing the Vector Last week, got the basic functionality of our Vector template working It is still missing some critical functionality Iterators are

More information

Statistics Case Study 2000 M. J. Clancy and M. C. Linn

Statistics Case Study 2000 M. J. Clancy and M. C. Linn Statistics Case Study 2000 M. J. Clancy and M. C. Linn Problem Write and test functions to compute the following statistics for a nonempty list of numeric values: The mean, or average value, is computed

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Data Structures in C++ Using the Standard Template Library

Data Structures in C++ Using the Standard Template Library Data Structures in C++ Using the Standard Template Library Timothy Budd Oregon State University ^ ADDISON-WESLEY An imprint of Addison Wesley Longman, Inc. Reading, Massachusetts Harlow, England Menlo

More information

Course Review. Cpt S 223 Fall 2009

Course Review. Cpt S 223 Fall 2009 Course Review Cpt S 223 Fall 2009 1 Final Exam When: Tuesday (12/15) 8-10am Where: in class Closed book, closed notes Comprehensive Material for preparation: Lecture slides & class notes Homeworks & program

More information

use static size for this buffer

use static size for this buffer Software Design (C++) 4. Templates and standard library (STL) Juha Vihavainen University of Helsinki Overview Introduction to templates (generics) std::vector again templates: specialization by code generation

More information

Supplement I.A: Glossary. For Introduction to C++ Programming, Second Edition By Y. Daniel Liang

Supplement I.A: Glossary. For Introduction to C++ Programming, Second Edition By Y. Daniel Liang Chapter 1 Supplement I.A: Glossary For Introduction to C++ Programming, Second Edition By Y. Daniel Liang assembly language A low-level programming language in which a mnemonic is used to represent each

More information

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview

Introduction to Visual Basic and Visual C++ Introduction to Java. JDK Editions. Overview. Lesson 13. Overview Introduction to Visual Basic and Visual C++ Introduction to Java Lesson 13 Overview I154-1-A A @ Peter Lo 2010 1 I154-1-A A @ Peter Lo 2010 2 Overview JDK Editions Before you can write and run the simple

More information

The Java Type System (continued)

The Java Type System (continued) Object-Oriented Design Lecture 5 CSU 370 Fall 2007 (Pucella) Friday, Sep 21, 2007 The Java Type System (continued) The Object Class All classes subclass the Object class. (By default, this is the superclass

More information

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE

DOWNLOAD PDF LINKED LIST PROGRAMS IN DATA STRUCTURE Chapter 1 : What is an application of linear linked list data structures? - Quora A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. The elements

More information

DATA STRUCTURE AND ALGORITHM USING PYTHON

DATA STRUCTURE AND ALGORITHM USING PYTHON DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting

More information

Chapters and Appendices F J are PDF documents posted online at the book s Companion Website, which is accessible from.

Chapters and Appendices F J are PDF documents posted online at the book s Companion Website, which is accessible from. Contents Chapters 23 26 and Appendices F J are PDF documents posted online at the book s Companion Website, which is accessible from http://www.pearsonhighered.com/deitel See the inside front cover for

More information

CS2 Algorithms and Data Structures Note 6

CS2 Algorithms and Data Structures Note 6 CS Algorithms and Data Structures Note 6 Priority Queues and Heaps In this lecture, we will discuss priority queues, another important ADT. As stacks and queues, priority queues store arbitrary collections

More information

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013

Linear Structures. Linear Structure. Implementations. Array details. List details. Operations 2/10/2013 Linear Structure Linear Structures Chapter 4 CPTR 318 Every non-empty linear structure has A unique element called first A unique element called last Every element except last has a unique successor Every

More information

Scientific programming (in C++)

Scientific programming (in C++) Scientific programming (in C++) F. Giacomini INFN-CNAF School on Open Science Cloud Perugia, June 2017 https://baltig.infn.it/giaco/201706_perugia_cpp What is C++ C++ is a programming language that is:

More information

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures

MIDTERM EXAMINATION Spring 2010 CS301- Data Structures MIDTERM EXAMINATION Spring 2010 CS301- Data Structures Question No: 1 Which one of the following statement is NOT correct. In linked list the elements are necessarily to be contiguous In linked list the

More information

Summer Final Exam Review Session August 5, 2009

Summer Final Exam Review Session August 5, 2009 15-111 Summer 2 2009 Final Exam Review Session August 5, 2009 Exam Notes The exam is from 10:30 to 1:30 PM in Wean Hall 5419A. The exam will be primarily conceptual. The major emphasis is on understanding

More information

CONTAİNERS COLLECTİONS

CONTAİNERS COLLECTİONS CONTAİNERS Some programs create too many objects and deal with them. In such a program, it is not feasible to declare a separate variable to hold reference to each of these objects. The proper way of keeping

More information

CS 32. Lecture 5: Templates

CS 32. Lecture 5: Templates CS 32 Lecture 5: Templates Vectors Sort of like what you remember from Physics but sort of not Can have many components Usually called entries Like Python lists Array vs. Vector What s the difference?

More information

Prelim 2 SOLUTION. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph

Prelim 2 SOLUTION. CS 2110, 16 November 2017, 7:30 PM Total Question Name Short Heaps Tree Collections Sorting Graph Prelim 2 SOLUTION CS 2110, 16 November 2017, 7:30 PM 1 2 3 4 5 6 7 Total Question Name Short Heaps Tree Collections Sorting Graph answer Max 1 18 10 25 10 16 20 100 Score Grader The exam is closed book

More information

Exceptions, Templates, and the STL

Exceptions, Templates, and the STL Exceptions, Templates, and the STL CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 16 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/

More information

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different.

Trees. Chapter 6. strings. 3 Both position and Enumerator are similar in concept to C++ iterators, although the details are quite different. Chapter 6 Trees In a hash table, the items are not stored in any particular order in the table. This is fine for implementing Sets and Maps, since for those abstract data types, the only thing that matters

More information

Programming with Haiku

Programming with Haiku Programming with Haiku Lesson 2 Written by DarkWyrm All material 2010 DarkWyrm In our first lesson, we learned about how to generalize type handling using templates and some of the incredibly flexible

More information

Function Templates. Consider the following function:

Function Templates. Consider the following function: Function Templates Consider the following function: void swap (int& a, int& b) { int tmp = a; a = b; b = tmp; Swapping integers. This function let's you swap the contents of two integer variables. But

More information

Model Solutions. COMP 103: Test April, 2013

Model Solutions. COMP 103: Test April, 2013 Family Name:............................. Other Names:............................. ID Number:............................... Signature.................................. Instructions Time allowed: 40 minutes

More information

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs

Algorithms in Systems Engineering IE172. Midterm Review. Dr. Ted Ralphs Algorithms in Systems Engineering IE172 Midterm Review Dr. Ted Ralphs IE172 Midterm Review 1 Textbook Sections Covered on Midterm Chapters 1-5 IE172 Review: Algorithms and Programming 2 Introduction to

More information

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1

CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 Review from Lecture 21 CSCI-1200 Data Structures Fall 2018 Lecture 22 Hash Tables, part 2 & Priority Queues, part 1 the single most important data structure known to mankind Hash Tables, Hash Functions,

More information

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Java How to Program, 10/e. Copyright by Pearson Education, Inc. All Rights Reserved. Java How to Program, 10/e Copyright 1992-2015 by Pearson Education, Inc. All Rights Reserved. Data structures Collections of related data items. Discussed in depth in Chapters 16 21. Array objects Data

More information

Data Structures Question Bank Multiple Choice

Data Structures Question Bank Multiple Choice Section 1. Fundamentals: Complexity, Algorthm Analysis 1. An algorithm solves A single problem or function Multiple problems or functions Has a single programming language implementation 2. A solution

More information

SFU CMPT Topic: Function Objects

SFU CMPT Topic: Function Objects SFU CMPT-212 2008-1 1 Topic: Function Objects SFU CMPT-212 2008-1 Topic: Function Objects Ján Maňuch E-mail: jmanuch@sfu.ca Friday 14 th March, 2008 SFU CMPT-212 2008-1 2 Topic: Function Objects Function

More information

Object-Oriented Programming for Scientific Computing

Object-Oriented Programming for Scientific Computing Object-Oriented Programming for Scientific Computing STL and Iterators Ole Klein Interdisciplinary Center for Scientific Computing Heidelberg University ole.klein@iwr.uni-heidelberg.de Summer Semester

More information

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority.

3. Priority Queues. ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. 3. Priority Queues 3. Priority Queues ADT Stack : LIFO. ADT Queue : FIFO. ADT Priority Queue : pick the element with the lowest (or highest) priority. Malek Mouhoub, CS340 Winter 2007 1 3. Priority Queues

More information

The Java Collections Framework. Chapters 7.5

The Java Collections Framework. Chapters 7.5 The Java s Framework Chapters 7.5 Outline Introduction to the Java s Framework Iterators Interfaces, Classes and Classes of the Java s Framework Outline Introduction to the Java s Framework Iterators Interfaces,

More information