0% found this document useful (0 votes)
4 views60 pages

Object Orientation Abstraction and Data Structures Using Scala Second Edition Lacher instant download

Ebook download

Uploaded by

dacrimateizj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views60 pages

Object Orientation Abstraction and Data Structures Using Scala Second Edition Lacher instant download

Ebook download

Uploaded by

dacrimateizj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 60

Object Orientation Abstraction and Data

Structures Using Scala Second Edition Lacher pdf


download

https://textbookfull.com/product/object-orientation-abstraction-
and-data-structures-using-scala-second-edition-lacher/

Download more ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

A Beginner's Guide to Scala, Object Orientation and


Functional Programming (Second Edition) John Hunt

https://textbookfull.com/product/a-beginners-guide-to-scala-
object-orientation-and-functional-programming-second-edition-
john-hunt/

Object Oriented Data Structures Using Java 4th Edition


Dale

https://textbookfull.com/product/object-oriented-data-structures-
using-java-4th-edition-dale/

A Beginner’s Guide to Scala, Object Orientation and


Functional Programming John Hunt

https://textbookfull.com/product/a-beginners-guide-to-scala-
object-orientation-and-functional-programming-john-hunt/

Learning concurrent programming in Scala learn the art


of building intricate modern scalable and concurrent
applications using Scala Second Edition Prokopec

https://textbookfull.com/product/learning-concurrent-programming-
in-scala-learn-the-art-of-building-intricate-modern-scalable-and-
concurrent-applications-using-scala-second-edition-prokopec/
Mastering Go create Golang production applications
using network libraries concurrency and advanced Go
data structures Second Edition Tsoukalos

https://textbookfull.com/product/mastering-go-create-golang-
production-applications-using-network-libraries-concurrency-and-
advanced-go-data-structures-second-edition-tsoukalos/

Practical object-oriented design: an agile primer using


Ruby Second Edition Metz

https://textbookfull.com/product/practical-object-oriented-
design-an-agile-primer-using-ruby-second-edition-metz/

Modern Programming Made Easy Using Java Scala Groovy


and JavaScript Second Edition Adam L Davis

https://textbookfull.com/product/modern-programming-made-easy-
using-java-scala-groovy-and-javascript-second-edition-adam-l-
davis/

Problem Solving in Data Structures & Algorithms Using C


First Edition Jain

https://textbookfull.com/product/problem-solving-in-data-
structures-algorithms-using-c-first-edition-jain/

Data Structures Using C 2nd edition Reema Thareja


Oxford Publication 2014 Reema Thareja

https://textbookfull.com/product/data-structures-using-c-2nd-
edition-reema-thareja-oxford-publication-2014-reema-thareja/
OBJECT-ORIENTATION,
ABSTRACTION, AND
DATA STRUCTURES
USING

SCALA
SECOND EDITION
CHAPMAN & HALL/CRC
TEXTBOOKS IN COMPUTING

Series Editors

John Impagliazzo Andrew McGettrick


Professor Emeritus, Hofstra University Department of Computer
and Information Sciences
University of Strathclyde

Aims and Scope

This series covers traditional areas of computing, as well as related technical areas, such as
software engineering, artificial intelligence, computer engineering, information systems, and
information technology. The series will accommodate textbooks for undergraduate and gradu-
ate students, generally adhering to worldwide curriculum standards from professional societ-
ies. The editors wish to encourage new and imaginative ideas and proposals, and are keen to
help and encourage new authors. The editors welcome proposals that: provide groundbreaking
and imaginative perspectives on aspects of computing; present topics in a new and exciting
context; open up opportunities for emerging areas, such as multi-media, security, and mobile
systems; capture new developments and applications in emerging fields of computing; and
address topics that provide support for computing, such as mathematics, statistics, life and
physical sciences, and business.

Published Titles

Paul Anderson, Web 2.0 and Beyond: Principles and Technologies


Henrik Bærbak Christensen, Flexible, Reliable Software: Using Patterns and
Agile Development
John S. Conery, Explorations in Computing: An Introduction to Computer
Science
John S. Conery, Explorations in Computing: An Introduction to Computer
Science and Python Programming
Iztok Fajfar, Start Programming Using HTML, CSS, and JavaScript
Jessen Havill, Discovering Computer Science: Interdisciplinary Problems,
Principles, and Python Programming
Ted Herman, A Functional Start to Computing with Python
Pascal Hitzler, Markus Krötzsch, and Sebastian Rudolph, Foundations of
Semantic Web Technologies
Mark J. Johnson, A Concise Introduction to Data Structures using Java
Mark J. Johnson, A Concise Introduction to Programming in Python
Lisa C. Kaczmarczyk, Computers and Society: Computing for Good
Mark C. Lewis, Introduction to the Art of Programming Using Scala
Mark C. Lewis and Lisa L. Lacher, Introduction to Programming and Problem-
Solving Using Scala, Second Edition
Published Titles Continued
Mark C. Lewis and Lisa L. Lacher, Object-Orientation, Abstraction, and Data Structures Using
Scala, Second Edition
Efrem G. Mallach, Information Systems: What Every Business Student Needs to Know
Bill Manaris and Andrew R. Brown, Making Music with Computers: Creative Programming
in Python
Uvais Qidwai and C.H. Chen, Digital Image Processing: An Algorithmic Approach with
MATLAB®
David D. Riley and Kenny A. Hunt, Computational Thinking for the Modern Problem Solver
Henry M. Walker, The Tao of Computing, Second Edition
Aharon Yadin, Computer Systems Architecture
Chapman & Hall/CRC
TEXTBOOKS IN COMPUTING

OBJECT-ORIENTATION,
ABSTRACTION, AND
DATA STRUCTURES
USING

SCALA
SECOND EDITION

Mark C. Lewis
Lisa L. Lacher
CRC Press
Taylor & Francis Group
6000 Broken Sound Parkway NW, Suite 300
Boca Raton, FL 33487-2742
© 2017 by Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, an Informa business

No claim to original U.S. Government works

Printed on acid-free paper


Version Date: 20161109

International Standard Book Number-13: 978-1-4987-3216-1 (Paperback)

This book contains information obtained from authentic and highly regarded sources. Reasonable efforts have been
made to publish reliable data and information, but the author and publisher cannot assume responsibility for the valid-
ity of all materials or the consequences of their use. The authors and publishers have attempted to trace the copyright
holders of all material reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and let us know so we may
rectify in any future reprint.

Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced, transmitted, or uti-
lized in any form by any electronic, mechanical, or other means, now known or hereafter invented, including photocopy-
ing, microfilming, and recording, or in any information storage or retrieval system, without written permission from the
publishers.

For permission to photocopy or use material electronically from this work, please access www.copyright.com (http://
www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923,
978-750-8400. CCC is a not-for-profit organization that provides licenses and registration for a variety of users. For
organizations that have been granted a photocopy license by the CCC, a separate system of payment has been arranged.

Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and are used only for
identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
Contents

List of Figures xvii

List of Tables xxiii

Preface xxv

1 Scala Language Basics 1


1.1 First Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Variables and Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.4 Statements and Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.4.1 Lambda Expressions/Closures . . . . . . . . . . . . . . . . . . . . 9
1.5 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5.1 Conditionals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5.2 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.5.3 Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.6 Declarations and Scope . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.7 Essential Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.7.1 Standard Input and import Statements . . . . . . . . . . . . . . . 19
1.7.2 Basic Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.7.2.1 Array and List . . . . . . . . . . . . . . . . . . . . . . . 21
1.7.2.2 Creating Collections Using fill . . . . . . . . . . . . . . 22
1.7.2.3 Creating Collections Using tabulate . . . . . . . . . . . 22
1.7.2.4 Creating Arrays Using new . . . . . . . . . . . . . . . . . 23
1.7.2.5 Creating Lists Using Cons . . . . . . . . . . . . . . . . . 24
1.7.2.6 Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
1.7.2.7 Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
1.7.2.8 Higher-Order Methods . . . . . . . . . . . . . . . . . . . 29
1.7.3 The Option Type . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
1.7.4 Text Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
1.8 Other Language Features . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.8.1 Unfinished Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.8.2 Named Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
1.8.3 Default Parameter Values . . . . . . . . . . . . . . . . . . . . . . . 38
1.8.4 Curried Functions/Methods . . . . . . . . . . . . . . . . . . . . . . 38
1.8.5 Pass-by-Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
1.9 The Read, Evaluate, Print Loop (REPL) . . . . . . . . . . . . . . . . . . 41
1.10 Putting It Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
1.11 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.11.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 43
1.11.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

vii
viii Contents

2 Basics of Object-Orientation and Software Development 51


2.1 The Meaning of Object-Orientation . . . . . . . . . . . . . . . . . . . . . 51
2.2 What Are classes? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
2.3 Software Development Stages . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.4 Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2.5 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
2.6 Bank Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.6.1 Bank Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.6.2 Bank Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.6.3 Bank Implementation . . . . . . . . . . . . . . . . . . . . . . . . . 66
2.6.4 Making an Application . . . . . . . . . . . . . . . . . . . . . . . . 72
2.7 Making Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.8 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.8.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 77
2.8.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
2.8.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79

3 Details of Object-Orientation in Scala 81


3.1 The 2D Vector classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
3.1.1 this Keyword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
3.2 Special Methods and Symbolic Names . . . . . . . . . . . . . . . . . . . . 84
3.2.1 Scala Naming Rules/Symbolic Names . . . . . . . . . . . . . . . . 84
3.2.1.1 Precedence and Associativity . . . . . . . . . . . . . . . . 88
3.2.2 Unary Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
3.2.3 Property Assignment Methods . . . . . . . . . . . . . . . . . . . . 89
3.2.4 The apply Method . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
3.2.5 The update Method . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.3 object Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.3.1 Companion Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 94
3.4 Final Versions of 2D Vectors . . . . . . . . . . . . . . . . . . . . . . . . . 96
3.5 case classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
3.6 Encapsulation/Separating Interface from Implementation . . . . . . . . . 102
3.7 Revisiting the API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
3.8 import Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
3.9 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.9.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 106
3.9.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
3.9.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

4 Abstraction and Polymorphism 115


4.1 Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
4.2 Inclusion Polymorphism (Inheritance and Subtyping) . . . . . . . . . . . . 118
4.2.1 Inheritance in the Scala Type System . . . . . . . . . . . . . . . . 122
4.2.2 Inheritance in Scala Code . . . . . . . . . . . . . . . . . . . . . . . 122
4.2.3 private Visibility and Inheritance . . . . . . . . . . . . . . . . . . 126
4.2.4 protected Visibility . . . . . . . . . . . . . . . . . . . . . . . . . . 127
4.2.5 Calling Methods on the Supertype . . . . . . . . . . . . . . . . . . 127
4.2.6 Abstract Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
4.2.7 traits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
4.2.8 final . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
4.2.9 Method Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Contents ix

4.2.10 Inheriting from Function Types . . . . . . . . . . . . . . . . . . . . 134


4.2.11 Enumerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
4.3 Parametric Polymorphism . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
4.3.1 Parametric Types . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
4.3.2 Parametric Functions and Methods . . . . . . . . . . . . . . . . . 140
4.3.2.1 Parametric Sorts . . . . . . . . . . . . . . . . . . . . . . . 142
4.3.3 Type Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
4.3.3.1 Type Bounds and Sorting . . . . . . . . . . . . . . . . . . 145
4.4 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.4.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
4.4.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148

5 GUIs and Graphics 149


5.1 Project Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
5.2 ScalaFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
5.3 Drawing Program Layout . . . . . . . . . . . . . . . . . . . . . . . . . . . 156
5.3.1 Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
5.3.2 Panes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158
5.3.3 Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
5.4 Drawing Program Design . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
5.5 Interactivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
5.5.1 Properties, Observables, and Bindings . . . . . . . . . . . . . . . . 166
5.6 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
5.6.1 Shapes and Scene Graph . . . . . . . . . . . . . . . . . . . . . . . 167
5.6.2 Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
5.7 Keyboard and Mouse Input . . . . . . . . . . . . . . . . . . . . . . . . . . 174
5.8 Animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
5.9 Other Elements of ScalaFX . . . . . . . . . . . . . . . . . . . . . . . . . . 179
5.10 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
5.10.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 179
5.10.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
5.10.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182

6 Other Collection Types 185


6.1 The scala.collection Packages . . . . . . . . . . . . . . . . . . . . . . . . . 185
6.1.1 scala.collection.immutable . . . . . . . . . . . . . . . . . . . . . . . 186
6.1.2 scala.collection.mutable . . . . . . . . . . . . . . . . . . . . . . . . 188
6.2 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
6.2.1 Running through Sets . . . . . . . . . . . . . . . . . . . . . . . . . 190
6.2.2 Mutable vs. Immutable . . . . . . . . . . . . . . . . . . . . . . . . 191
6.2.3 Using a Set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
6.3 Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
6.3.1 Looping through a Map . . . . . . . . . . . . . . . . . . . . . . . . 195
6.3.2 Using Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 196
6.4 Buffers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
6.5 Collections as Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
6.6 Project Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
6.6.1 Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
6.6.2 Adding Drawables . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
6.7 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
x Contents

6.7.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 208


6.7.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
6.7.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209

7 Stacks and Queues 213


7.1 Abstract Data Types (ADTs) . . . . . . . . . . . . . . . . . . . . . . . . . 214
7.2 Operations on Stacks and Queues . . . . . . . . . . . . . . . . . . . . . . . 214
7.3 Real Meaning of O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
7.4 O(1) Requirement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
7.5 Array-Based Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217
7.6 Array-Based Queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
7.7 Unit Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
7.7.1 Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
7.7.2 Writing Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
7.7.3 Test Suites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
7.7.4 Test-Driven Development . . . . . . . . . . . . . . . . . . . . . . . 229
7.8 RPN Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 230
7.9 Breadth-First Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 234
7.10 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.10.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 238
7.10.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239
7.10.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

8 Multithreading and Concurrency 243


8.1 The Multicore and Manycore Future . . . . . . . . . . . . . . . . . . . . . 244
8.2 Threads (Conceptual) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
8.3 Futures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246
8.3.1 Using foreach, map, and flatMap . . . . . . . . . . . . . . . . . . 247
8.3.2 Working in Parallel . . . . . . . . . . . . . . . . . . . . . . . . . . 251
8.3.3 Futures with for Loops . . . . . . . . . . . . . . . . . . . . . . . . 253
8.3.4 Getting a Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
8.4 Parallel Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 257
8.4.1 Parallel for Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
8.4.2 Parallel reduce, fold, and aggregate . . . . . . . . . . . . . . . . 259
8.4.3 When to Use Parallel Collections . . . . . . . . . . . . . . . . . . . 260
8.5 Race Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
8.6 Synchronization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263
8.7 Deadlock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 265
8.8 Multithreading in GUIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 267
8.9 Multithreaded Mandelbrot (Project Integration) . . . . . . . . . . . . . . 269
8.10 Actors and Akka . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
8.10.1 Akka . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 276
8.10.2 Actors Communicating . . . . . . . . . . . . . . . . . . . . . . . . 278
8.10.3 The Ask Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
8.10.4 Be Careful with sender and this . . . . . . . . . . . . . . . . . . 283
8.10.5 The Actor Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . 284
8.10.6 Error Handling and the Actor Lifecycle . . . . . . . . . . . . . . . 287
8.10.7 Routers (Project Integration) . . . . . . . . . . . . . . . . . . . . . 291
8.10.8 More to Akka . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
8.11 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297
8.11.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 297
Contents xi

8.11.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299


8.11.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300

9 Low-Level Multithreading and Java Libraries 303


9.1 Basic Threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303
9.1.1 Wait/Notify . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
9.1.2 Other Thread Methods . . . . . . . . . . . . . . . . . . . . . . . . 309
9.2 Concurrency Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
9.2.1 Executors and Executor Services . . . . . . . . . . . . . . . . . . . 311
9.2.2 Callable and Java Futures . . . . . . . . . . . . . . . . . . . . . . . 311
9.2.3 Parallel Data Structures . . . . . . . . . . . . . . . . . . . . . . . . 314
9.2.3.1 Shared Barriers . . . . . . . . . . . . . . . . . . . . . . . 314
9.2.3.2 The Exchange . . . . . . . . . . . . . . . . . . . . . . . . 315
9.2.3.3 Assembly Line . . . . . . . . . . . . . . . . . . . . . . . . 316
9.2.3.4 Ticketed Passengers . . . . . . . . . . . . . . . . . . . . . 317
9.2.3.5 Other Threadsafe Types . . . . . . . . . . . . . . . . . . 317
9.2.4 Atomic (java.util.concurrent.atomic) . . . . . . . . . . . . . . 317
9.2.5 Locks (java.util.concurrent.locks) . . . . . . . . . . . . . . . 318
9.3 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 319
9.3.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 319
9.3.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 320
9.3.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 321

10 Stream I/O and XML 323


10.1 The java.io Package . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
10.2 Streams for Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
10.3 Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
10.3.1 try-catch-finally Revisited . . . . . . . . . . . . . . . . . . . . . 327
10.3.2 Effect of Exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . 329
10.3.3 Loan Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 329
10.4 Decorating Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
10.4.1 Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
10.4.2 Binary Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332
10.5 Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 335
10.5.1 Binary Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . 335
10.5.2 XML Serialization . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
10.5.2.1 Nature of XML . . . . . . . . . . . . . . . . . . . . . . . 340
10.5.2.2 XML in Scala Code . . . . . . . . . . . . . . . . . . . . . 342
10.5.2.3 Serializing to XML . . . . . . . . . . . . . . . . . . . . . 344
10.6 Saving Drawings (Project Integration) . . . . . . . . . . . . . . . . . . . . 345
10.7 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
10.7.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 366
10.7.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
10.7.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367

11 Networking 369
11.1 TCP and UDP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 369
11.2 Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
11.2.1 TCP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 370
11.2.2 UDP Sockets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
11.2.3 Streams from Sockets . . . . . . . . . . . . . . . . . . . . . . . . . 373
xii Contents

11.3 URLs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378


11.4 Remote Method Invocation (RMI) . . . . . . . . . . . . . . . . . . . . . . 380
11.5 Collaborative Drawing (Project Integration) . . . . . . . . . . . . . . . . . 388
11.6 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.6.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.6.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 401
11.6.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402

12 Linked Lists 405


12.1 The List/Seq ADT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 405
12.2 Nature of Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
12.3 Nature of Linked Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 406
12.4 Mutable Singly Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . 408
12.4.1 Implementing mutable.Buffer . . . . . . . . . . . . . . . . . . . . 412
12.4.2 Iterators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
12.5 Mutable Doubly Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . 417
12.6 Immutable Singly Linked List . . . . . . . . . . . . . . . . . . . . . . . . . 422
12.7 Linked List-Based Stacks and Queues . . . . . . . . . . . . . . . . . . . . 425
12.7.1 Linked List-Based Stack . . . . . . . . . . . . . . . . . . . . . . . . 425
12.7.2 Linked List-Based Queue . . . . . . . . . . . . . . . . . . . . . . . 426
12.8 Project Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
12.9 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 427
12.9.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 427
12.9.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 428
12.9.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429

13 Priority Queues 431


13.1 Two Approaches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 431
13.1.1 Searching by Priority . . . . . . . . . . . . . . . . . . . . . . . . . 432
13.1.2 Sorted Linked List . . . . . . . . . . . . . . . . . . . . . . . . . . . 432
13.1.3 Problems with Arrays . . . . . . . . . . . . . . . . . . . . . . . . . 434
13.2 Project Integration: Discrete Event Simulation . . . . . . . . . . . . . . . 435
13.2.1 Cell Splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435
13.2.2 Collision Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 438
13.3 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445
13.3.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 445
13.3.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446
13.3.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 446

14 Refactoring 449
14.1 Smells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 449
14.2 Refactorings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452
14.2.1 Built-in Refactoring Methods . . . . . . . . . . . . . . . . . . . . . 453
14.2.2 Introduce Null Object . . . . . . . . . . . . . . . . . . . . . . . . . 454
14.2.3 Add and Remove Parameter . . . . . . . . . . . . . . . . . . . . . 454
14.2.4 Cures for Switch Statements . . . . . . . . . . . . . . . . . . . . . 455
14.2.5 Consolidate Conditional Expression . . . . . . . . . . . . . . . . . 456
14.2.6 Convert Procedural Design to Objects . . . . . . . . . . . . . . . . 457
14.2.7 Encapsulate Collection . . . . . . . . . . . . . . . . . . . . . . . . 457
14.2.8 Push Down or Pull Up Field or Method . . . . . . . . . . . . . . . 458
14.2.9 Substitute Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 458
Contents xiii

14.3 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459


14.3.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 459
14.3.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459
14.3.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459

15 Recursion 461
15.1 Refresher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 461
15.2 Project Integration: A Maze . . . . . . . . . . . . . . . . . . . . . . . . . . 462
15.2.1 The Recursive Approach . . . . . . . . . . . . . . . . . . . . . . . 462
15.2.2 Graphical Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . 464
15.2.3 Longest Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 471
15.2.4 Optimizing the Maze . . . . . . . . . . . . . . . . . . . . . . . . . 471
15.3 Graph Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 473
15.4 Divide and Conquer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481
15.4.1 Merge Sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482
15.4.2 Quicksort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 484
15.4.3 Formula Parser . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487
15.5 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 488
15.5.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 488
15.5.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 489
15.5.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 490

16 Trees 493
16.1 General Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493
16.1.1 Implementations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 494
16.1.2 Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495
16.2 Project Integration: Formula Parsing . . . . . . . . . . . . . . . . . . . . . 498
16.2.1 Formula Tree Traversals and In-Order Traversal . . . . . . . . . . 502
16.3 Binary Search Trees: Binary Trees as Maps . . . . . . . . . . . . . . . . . 503
16.3.1 Order Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
16.3.2 Immutable BSTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511
16.4 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 514
16.4.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 514
16.4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515
16.4.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 516

17 Regular Expressions and Context-Free Parsers 519


17.1 Chomsky Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 519
17.1.1 Regular Grammars . . . . . . . . . . . . . . . . . . . . . . . . . . . 521
17.1.2 Context-Free Grammars . . . . . . . . . . . . . . . . . . . . . . . . 521
17.1.3 Context-Sensitive Grammars . . . . . . . . . . . . . . . . . . . . . 522
17.1.4 Recursively Enumerable Grammars . . . . . . . . . . . . . . . . . 522
17.2 Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 522
17.2.1 Characters and Character Classes . . . . . . . . . . . . . . . . . . 523
17.2.2 Logical Operators and Capturing Groups . . . . . . . . . . . . . . 524
17.2.3 Greedy Quantifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . 525
17.2.4 Boundary Requirements . . . . . . . . . . . . . . . . . . . . . . . . 526
17.2.5 Using Regular Expressions in Code . . . . . . . . . . . . . . . . . . 526
17.2.6 Drawback of Regular Expressions . . . . . . . . . . . . . . . . . . 528
17.3 Context-Free Parsers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 529
17.3.1 Default Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530
xiv Contents

17.3.2 Specified Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 530


17.4 Project Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531
17.5 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535
17.5.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 535
17.5.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536
17.5.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 536

18 Binary Heaps 539


18.1 Binary Heaps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 539
18.1.1 Binary Heaps as Arrays . . . . . . . . . . . . . . . . . . . . . . . . 539
18.2 Heaps as Priority Queues . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
18.3 Heapsort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547
18.4 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
18.4.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 549
18.4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 549
18.4.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 550

19 Direct Access Binary Files 551


19.1 Random Access Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 551
19.1.1 Fixed Record Length . . . . . . . . . . . . . . . . . . . . . . . . . 552
19.1.2 Indexed Variable Record Length . . . . . . . . . . . . . . . . . . . 557
19.2 Linked Structures in Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 560
19.3 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
19.3.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 567
19.3.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 567
19.3.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 568

20 Spatial Trees 569


20.1 Spatial Data and Grids . . . . . . . . . . . . . . . . . . . . . . . . . . . . 569
20.2 Quadtrees and Octrees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573
20.3 kD-Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 578
20.4 Efficient Bouncing Balls . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
20.5 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 582
20.5.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 582
20.5.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583
20.5.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583

21 Augmenting Trees 587


21.1 Augmentation of Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 587
21.2 Balanced BSTs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
21.2.1 Rotations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 588
21.2.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 589
21.3 Order-Statistic Trees: Trees as Sequences . . . . . . . . . . . . . . . . . . 593
21.4 Augmented Spatial Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . 600
21.5 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
21.5.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 605
21.5.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605
21.5.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 606
Contents xv

22 Hash Tables 609


22.1 Basics of Hash Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 609
22.1.1 Hashing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 610
22.1.2 Hashing Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611
22.2 Chaining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 612
22.3 Open Addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 616
22.3.1 Probing Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 617
22.3.2 Removing with Open Addressing . . . . . . . . . . . . . . . . . . . 618
22.3.3 Open Addressing Implementation . . . . . . . . . . . . . . . . . . 619
22.4 End of Chapter Material . . . . . . . . . . . . . . . . . . . . . . . . . . . . 622
22.4.1 Summary of Concepts . . . . . . . . . . . . . . . . . . . . . . . . . 622
22.4.2 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623
22.4.3 Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623

Bibliography 625

Index 627
List of Figures

1 This figure shows the relationships between the chapters in this book to
help you pick which ones you want to cover, and in what order. . . . . . . xxviii

1.1 The Scala API looks like this when viewing scala.collection.immutable.List.
The right column shows the various objects, classes, and traits. Selecting
one shows you the visible members inside of it. This is generated using
ScalaDoc on the library code. . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.1 This is a simple example of a UML use case diagram. Actors are drawn as
stick figures. The system being analyzed is a box. The ways in which the
actors use the system are drawn as circles. . . . . . . . . . . . . . . . . . . 61
2.2 This shows the UML class diagram for the Student class from section 2.2
along with a class for a course that contains multiple students. . . . . . . 62
2.3 This figure shows a use case diagram for a potential bank application that
models the customer-facing aspects of a bank. . . . . . . . . . . . . . . . . 64
2.4 This figure shows a class diagram for a potential bank application that
models the customer-facing aspects of a bank. . . . . . . . . . . . . . . . . 65

3.1 This figure shows three vectors, where v3 = v2 + v1 . . . . . . . . . . . . . . 82


3.2 This is part of the right column that you see when you enter the API.
The little circles with the letters c, o, and t indicate whether it is a class,
object, or trait. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104

4.1 This figure shows a limited set of options for the subtyping relationships of
animals as a UML diagram. . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.2 This is a simple class diagram showing subtypes of fruit. . . . . . . . . . . 119
4.3 This class diagram for fruit adds some methods that we might want and
how they might be overridden in the subclasses. . . . . . . . . . . . . . . . 120
4.4 Diagram of general subtype relationships in Scala. This figure has been
adapted from a similar figure in Programming in Scala by Odersky, Spoon,
and Venners [10]. The thick lines with full arrowheads indicate a subtyping
relationship. The thin lines with an open arrowhead indicate an implicit
conversion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.5 This UML class diagram shows what is commonly called the diamond prob-
lem. The challenge with this construct is that it can lead to significant
ambiguity. Different languages have different ways of dealing with this. . . 134

5.1 This is a use case diagram for our drawing program. . . . . . . . . . . . . 150
5.2 This is a simple diagram of what we want our GUI to look like when we are
done with the project. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
5.3 This class diagram shows the most of the classes/traits that are relevant
to the ScalaFX scene graph. . . . . . . . . . . . . . . . . . . . . . . . . . . 154
5.4 This is the window that pops up when you run the full version of FirstGUI. 155

xvii
xviii List of Figures

5.5 This is the window that pops up when you run DrawingMain. . . . . . . . 160
5.6 This is a first cut class diagram for our drawing project. . . . . . . . . . . 161
5.7 This is the window that pops up when you run the more complete version
of DrawingMain. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174

6.1 This is a UML diagram of the main types in the scala.collection package.
The collection types we have dealt with, including List[A] and Array[A],
have been under the Seq[A] part of the hierarchy. . . . . . . . . . . . . . . 186
6.2 This is a UML diagram of the main types in the scala.collection.immutable
package. This image is significantly simplified. If you look in the API you
will see that most of the types inherit from multiple other types. . . . . . 187
6.3 This is a UML diagram of the main types in the scala.collection.mutable
package. This image is significantly simplified. If you look in the API you
will see that most of the types inherit from multiple other types. . . . . . 188

7.1 This figure shows a graphical representation of the meaning of O. The solid
line represents g(n), which would be a measure of the amount of compu-
tation done for an input size n. The dotted line is the function, c × f (n),
where we want to say that g(n) is O(f (n)). This plot labels a position m,
above which the dotted curve is always above the solid curve. . . . . . . . 216
7.2 This figure shows a graphical representation of an Array-based stack and
how it changes over several operations. The stack stores data in the Array
and uses an integer index to keep track of the position of the top. . . . . . 219
7.3 This figure shows a graphical representation of an Array-based queue and
how it changes over several operations. The queue stores data in the Array
and uses integer indexes to keep track of the front and back. . . . . . . . . 223
7.4 This figure shows a graphical representation of an Array-based queue when
it needs to grow on an enqueue. The queue is seen as empty if front==back.
For that reason, the grow operation should happen when the last slot will
be filled. In addition to allocating a bigger Array, the copy operation needs
to move elements of the Array around and alter the location of front and
back. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224
7.5 This is what Eclipse shows when a JUnit test is run and all tests are passed.
A green bar means that everything is good. If you get a red bar, then one
or more tests have failed and they will be listed for you. . . . . . . . . . . 228
7.6 This is the drawing program after adding a maze and executing a breadth-
first solution. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 237
7.7 This figures shows in a graphical way what happens when a breadth-first
search is run. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238

8.1 This figure shows frequencies, transistor counts, and core counts for x86
processors produced between 1978 and 2016. The log scale on the plot makes
it so that exponential curves appear as straight lines. The dotted lines show
fits to the full transistor count data and the frequency data through 2000.
Clock speeds shown are the highest release for each chip. . . . . . . . . . . 245
8.2 This UML diagram shows the main types in the three different parallel
collection packages. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 258
8.3 This is a screen capture of the drawing program with a Mandelbrot image. 270
8.4 This figure shows a single method call between two objects in a basic se-
quence diagram. The key thing to note is that the thread goes with the call.
So when you call methods, the thread weaves around and between objects. 274
List of Figures xix

8.5 This figure shows three objects and two method calls in a basic sequence
diagram that illustrates how a race condition occurs. Even if the objects
properly encapsulate and protect their values, you still have to use synchro-
nization to prevent race conditions. . . . . . . . . . . . . . . . . . . . . . . 275
8.6 This figure shows three actors and two messages in a basic sequence diagram
that illustrates how the actor model prevents race conditions. Each actor
has only a single thread, and messages are processed sequentially, so as
long as mutable state is confined to a single actor, you cannot have race
conditions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 275
8.7 This figure shows the organization of the actor hierarchy that we are build-
ing in the example in this section. . . . . . . . . . . . . . . . . . . . . . . . 284
8.8 This is a screen capture of the drawing program with a Julia set image. . 292

11.1 This figure shows the different use cases for the socket/stream-based chat
program that we want to write. . . . . . . . . . . . . . . . . . . . . . . . . 374
11.2 This is a screen shot of the RMI chat client with two users connected. . . 387
11.3 This is a screen shot of the collaboration window. On the left is a column
showing shared drawings. On the bottom is a chat area. The main portion
is a shared sketch region where different collaborators can draw using some
simple types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 397

12.1 This figure shows what happens when you do an insert and a remove from
an array-based implementation of the list ADT. Note how operations near
the beginning have to do many copies, but operations near the end do not. 407
12.2 This figure shows the basic structure of some different forms of linked lists. 408
12.3 This figure shows what happens with insert and remove on a singly linked
list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 411
12.4 This figure shows what happens with insert and remove on a doubly linked
list. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 421

13.1 This figure shows how we can do remove from an unsorted array-based
priority queue in O(1) operations after we have done an O(n) search to find
the highest-priority element. . . . . . . . . . . . . . . . . . . . . . . . . . . 435
13.2 This screen shot shows the output of the cell simulation Drawable. The
properties that are used are visible on the left side of the window. . . . . . 439

15.1 This is the drawing program with a sample graph created using DrawGraph. 479

16.1 This figure shows a sample tree with some of the nodes labeled. Node P is
the parent of nodes C, D, and E. D and E are siblings of C. Node P has a
depth of 1 and a height of 2, while node C has a depth of 2 and a height of
1. The size of node P is six, while the size of node C is 2. . . . . . . . . . . 494
16.2 This figure shows the same tree that was displayed in figure 16.1, but draws
arrows for the first-child, next-sibling approach to building the tree. . . . . 495
16.3 This figure shows the same tree that was displayed in figures 16.1 and
16.2. Here, all of the nodes are labeled with letters to aid the discussion of
traversal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 496
16.4 This figure shows the recursion that happens when we parse the formula
3*(x-5)+x*x on the left side. On the right is the tree that we would want
to build from this formula. . . . . . . . . . . . . . . . . . . . . . . . . . . . 498
xx List of Figures

16.5 This is an example of a binary search tree using integer value keys. Searching
for an element in the tree follows steps very much like those a binary search
would perform. The bold arrows show the path that would be taken in a
search for the value 2. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 504
16.6 This figure shows the creation of the BST from figure 16.5. Each element
is placed by running down the tree in the same manner as a search until
we hit a location where there is not a child. A new node with the value is
placed in that location. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505

18.1 This figure shows an example of a binary heap. The numbers are priorities
with higher values being higher priority. Note that there is no problem with
duplicate priorities, unlike keys in a BST. There is also no order requirement
between siblings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540
18.2 This figure shows the same heap as in figure 18.1 with subscripts that num-
ber the nodes in breadth-first order. Below that is an array with the elements
at those locations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 541
18.3 Adding a new element with a priority of 9 to the heap shown in figure 18.1
goes through the following steps. A bubble is added at the next location in
a complete tree. It moves up until it reaches a point where the new value
can be added without breaking the heap order. . . . . . . . . . . . . . . . 542
18.4 Calling dequeue on the heap at the end of figure 18.3 forces the tree to
go through the following steps. The last element is moved to a temporary
variable, and a stone is placed at the top of the heap. This stone sinks down
until it reaches a point where the temporary can stop without breaking heap
order. The stone always sinks in the direction of the higher-priority child.
If the children have equal priority, it does not matter which side the stone
goes to. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 543
18.5 This shows a pictorial representation of the alternate data structure that
can be used as an efficient priority queue for collision handling. The top
array keeps the heads of lists for different time brackets during the time
step. The left array is the heads of lists for different particles. All lists are
doubly linked so that nodes can be removed without finding the one before
it. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 548

19.1 The binary file holding the linked list has the following format. The be-
ginning of the file is a header with four values written as Longs. They are
the position of the head node, the position of the tail node, the number of
nodes, and the position of the first free node. . . . . . . . . . . . . . . . . 561
19.2 The nodes of a B-tree can each store a certain number of records. The
number of records is selected to match an optimal size for disk reads and
writes. Non-leaf nodes have references to children at the beginning, end,
and between each record. The records in a node are sorted by a key. In
addition, the nodes in children have to have key values that fall between
the keys of the records they are between, or just below and above for the
beginning and end children. B-trees are always balanced and require few
disk accesses to find a record, but they do potentially waste some space. . 565
List of Figures xxi

19.3 This figure illustrates how adds are done for B-trees. A) shows the tree from
figure 19.2 with the addition of a record whose key value is 75. The 75 is
simply placed in sorted order in a leaf because there is still space left in
that node. For B), a record with a key value of 82 has been added. It would
go right after the 75 record, but there is no more space in that node. Of the
five records that would be in the node, the 75 is the median so it is moved
into the parent and the other records are split into two different nodes. This
process can propagate to higher levels in the tree if the parent is also full.
A new level is created when the root node fills and has to split. . . . . . . 566

20.1 This figure shows an example set of points with a very non-uniform spatial
distribution. A regular grid is laid over this to make it clear how the point
density in the grid cells will vary dramatically. The grid size shown here
works well for many of the low-density regions where there are only a handful
of points per cell. A grid that only had a few points per cell in the high-
density regions would be a very fine grid with an extremely large fraction
of the cells being empty in the low-density areas. . . . . . . . . . . . . . . 574
20.2 This is a quadtree with a number of non-uniformly distributed points to
illustrate how the space is partitioned. For this example, each node is only
allowed to hold a single point. The key advantage of the tree-based approach
is that the resolution does not have to be uniform. Higher-density regions
can divide the space much more finely. . . . . . . . . . . . . . . . . . . . . 575
20.3 This is a kD-tree with a number of non-uniformly distributed points to
illustrate how the space is partitioned. For this example, each node can
hold up to three points. While this example only uses two dimensions, it is
simple to scale the kD-tree higher without adding overhead. . . . . . . . . 579

21.1 This figure shows single rotations to the left and the right. These rotations
can be used when a node becomes unbalanced because the outer grandchild
on the left or the right is too tall relative to the other subtree. . . . . . . . 589
21.2 This figure shows double rotations to the left-right and the right-left. These
rotations can be used when a node becomes unbalanced because the inner
grandchild is too tall. Note that each of these is simply two applications of
the rotations from figure 21.1 . . . . . . . . . . . . . . . . . . . . . . . . . 590
21.3 This figure shows two arrays and their possible tree representations. The
second was arrived at by adding the letter ‘t’ at index 5 of the first. In the
tree, each node has the value, a letter, drawn large with a preceding number
that is the size of the node and a following number that is the index. . . . 594

22.1 This figure shows a graphic representation of the idea behind a hash table.
Keys can be any type of data and are not necessarily ordered. The keys are
mapped, using some function that we call the hash function, to positions
in the storage array. There are many more possible keys than there are
locations in the array, so it is possible to have “collisions” where different
keys map to the same location. . . . . . . . . . . . . . . . . . . . . . . . . 610
xxii List of Figures

22.2 This figure illustrates the challenge that we run into when we have the
option to remove a key-value pair when using open addressing. The left
column shows our words and the value given by our hash function using the
division method for an array with 15 elements. The middle column shows
where all those keys would wind up in the table assuming linear probing.
The third column shows it with “a” removed, which would cause problems
if we go looking for “system.” . . . . . . . . . . . . . . . . . . . . . . . . . 618
List of Tables

0.1 This table shows which projects appear as options in each of the different
chapters. The ‘X’ represents a unique project description. An ‘S’ indicates
that there is a standard description for students to use their own implemen-
tation of a data structure in their project. . . . . . . . . . . . . . . . . . . . xxx

3.1 This table shows the precedence rules for operators in Scala. The precedence
is based on the first character in the operator. . . . . . . . . . . . . . . . . . 88

19.1 This table shows how many bytes are written to disk for each of the basic
value types using either DataOutputStream or RandomAccessFile. . . . . . 552

xxiii
Preface

Thank you for purchasing Object-Orientation, Abstraction, and Data Structures Using
Scala. This book is intended to be used as a textbook for a second or third semester
course in Computer Science. The contents of this book are an expanded second edition
of the second half of Introduction to the Art of Programming Using Scala. The first half
of that book became Introduction to Programming and Problem Solving Using Scala. This
book assumes that the reader has previous programming experience, but not necessarily in
Scala. The introductory chapter is intended to quickly bring the reader up to speed on the
Scala syntax. If you already know Scala, you can skim this chapter for a refresher or skip
it completely.

To the Student
The field of Computer Science has remarkable depth. It has to in order to match the
capabilities and flexibility of the machines that we call “computers”. Your first steps into the
field should have shown you how to structure logic and break down problems, then write up
your instructions for how to solve the problems in the formal syntax of some programming
language. In this book, we want to build upon those capabilities. We want to give you
the tools of object orientation to help you structure solutions to larger, more complex
problems without experiencing mental overload in doing so. We also want to expand on
your knowledge of abstraction so that you can make your code more powerful and flexible.
Of course, all of this is implemented using the Scala programming language, which provides
powerful constructs for expressing both object orientation and abstraction.
One of the key ways that we illustrate these concepts is through the creation of data
structures. Data structures form one of the cornerstones of the field of computer science, and
understanding them is essential for anyone who wants to be an effective software developer.1
We strive to show you not only how these data structures can be written, but the strengths
and weaknesses of each one, so that you can understand when you should consider choosing
different ones.
This book also spends a fair bit of time looking at libraries that provide the functionality
you need to do real programming. This includes things like GUIs, multithreading, and
networking. The goal is to put you in a position where you can solve problems that you are
interested in. These are also vitally important topics that grow in importance every day, so
gaining a basic understanding of them early is something that we think is important.
There are a number of resources available to you that help support the mate-
rial in this book. Much of this material is kept at the book’s website, http://www.
programmingusingscala.net/. We teach our own classes using a flipped format, and there
1 One of the authors recently optimized a section of a professional program that was taking 90 seconds

to run down to 0.3 seconds simply by using more appropriate data structures for key operations.

xxv
xxvi Preface

are video playlists for every chapter in this book available at https://www.youtube.com/
channel/UCEvjiWkK2BoIH819T-buioQ. Even if you are not using this book as part of a
course that uses a flipped format, the videos can do something significant that the book
cannot. They can show you the dynamic aspect of programming. Much of the video content
is live coding where we talk through our thought processes as we construct code. This is a
valuable aspect of programming that prose on paper struggles to communicate. Where the
videos are weak is in total depth of coverage. The book goes into much deeper detail on
many topics than what is covered in the videos.
The playlists on the YouTube channel go beyond the contents of this book. They include
the previous book and a number of more advanced topics. We also post more videos on a
regular basis, so feel free to subscribe to see when additional material becomes available.
Lastly, we have put all of the code in this book in a GitHub repository (https:
//github.com/MarkCLewis/OOAbstractDataStructScala) that you can go through and
pull down. The code is organized into separate packages for each chapter. Occasionally
in the text we present changes to earlier code without showing the entire file that re-
sults. Finished files can always be found in the code repository. We have done the same
for the code written in the videos. It is available at https://github.com/MarkCLewis/
OOAbstractDataStructScalaVideos.
We hope you enjoy this step on your journey to learning computer science and developing
your programming skills.

To the Instructor
Why Scala?
Probably the most distinguishing aspect of this book is the choice of Scala as the imple-
mentation language. As an instructor, you inevitably feel multiple influences when selecting
the language to use for introductory courses, especially given that you do not really want to
focus on language at all. You want to focus on concepts, but you know that those concepts
have to be taught in some language so that students can actually get practice. So you re-
ally want a language that will let you teach the concepts that you feel are most important
without getting in the way. Given this, the next obvious question is, why is Scala a good
language for teaching the concepts covered in this book?
There are several pieces to this answer associated with the different groups of concepts
that are covered in this book. First, Scala is an object-oriented language. Much of the
discussion of the language focuses on the functional features of the language, and while
those are wonderful in many ways and the expressivity they bring is used in this book on
many occasions, the reality is that Scala is more object oriented than it is functional. It is
more object oriented than Java, C++, Python, or most of the other languages one might
consider using to teach this material, with the possible exception of Smalltalk and Ruby. All
values in Scala are objects, which simplifies many details compared to languages where there
are distinctions between primitives and objects.2 There is no concept of “static”, which is
replaced by singleton object declarations which fit much better in the OO model. Even the
functions are really just objects with an implementation of the apply method.
2 A favorite example of this is converting between a commonly used type. In Java, why do you say i =

(int)x, but i = Integer.parseInt(s)? Why can you not make an ArrayList<int> but you can make an
int[] which has very different syntax? In Scala you can say x.toInt and s.toInt and you can use the same
Int type with all of your collections which all have uniform syntax.
Preface xxvii

Scala provides many different tools for creating abstraction in code. You have the stan-
dard OO approaches through polymorphism with inheritance and type parameters. You also
have the approaches found in functional languages created by the ease of passing functions
around. Support for pass-by-name adds yet another tool for creating abstraction in code
that is not available in many languages.
Some instructors will also be happy to know that these abstraction tools are all im-
plemented in a statically typed manner. We consider knowledge of type systems to be an
integral part of programming and CS in general. Static type systems have their own formal
logic that can help to structure student thinking and there are certain topics that simply
cannot be taught in dynamically typed languages.
These factors all contribute to the use of Scala for teaching data structures. The language
works very well for teaching students how to construct type-safe collections of their own
from the ground up.
Beyond the keywords in the title of the book, we like to introduce interesting and useful
libraries, which are abundant in both Scala and the broader JVM environment. The ability
to use the advanced multithreading libraries in Scala while also leaning on Java libraries for
things like networking, is remarkably advantageous.
One of the key features of Scala is that it is not opinionated. It lets you do things your
way. Some people lament that in professional environments. However, in the classroom, that
means that you can teach what and how you want. You can use declarative constructs if
you want to focus on higher level thinking or use imperative constructs when you want your
students to have to deal with the details. A general idea behind Scala is that there is no
silver bullet for most problems in computer science, so a language should provide you with
options to do things in the way that you feel is best. We believe that this matters as much
in the classroom as in other venues.
Lastly, there are the influences beyond pedagogy. There are considerations of how a
language fits into the full departmental curriculum and how it impacts students outside
of your curriculum. Scala works well beyond just the introductory courses. It is broadly
used in web development, has a significant range of tools for parallelism, and thanks to the
Spark library, it has become a dominant force in the area of data analytics. As a result,
it is not hard to envision Scala being used in later courses in the curriculum. As for real-
world usage, we would argue that Scala sits in the sweet spot for pedagogy. It is being
broadly used outside of academia. At the time of this writing, it was number 14 on the
latest RedMonk language ranking, sitting at roughly equal position on both the GitHub
and StackOverflow axes of that ranking. This is high enough that you can point students,
parents, and colleagues to real-world usage. However, it is far enough down that students
are less likely to be able to find answers to all of your programming assignments with a
simple Google search.
While there is no perfect language for anything, we do believe that for these reasons,
and likely others that we have missed, Scala is a good option for introductory programming
courses.

Structure and Contents


This book is pretty much what the title says it is. We strive to give students a firm
foundation in the key principles of object orientation while building their ability to use
abstraction in various forms, including multiple forms of polymorphism. A lot of this is
communicated in the form of data structures, and we believe that this book can serve as a
textbook for a basic course on data structures. We present basic order analysis and discuss
the relative strengths and weaknesses of the various implementations of different Abstract
Data Types along with showing implementations of those ADTs in Scala.
xxviii Preface

FIGURE 1: This figure shows the relationships between the chapters in this book to help
you pick which ones you want to cover, and in what order.
Random documents with unrelated
content Scribd suggests to you:
Chapter Twenty Two.
The Secret of Harvey Shaw.

For three days I remained in Aix, awaiting some news or


message from the fugitives—but none came.

Tramu called and saw me twice, evidently astounded at the


channel of escape which Shaw had so cunningly prepared.
He had, no doubt, obtained an impression of one of the
servants’ master keys, and had one cut to fit the locked
door which prevented visitors from passing out by any other
way save by the front hall. He had anticipated that flight
might be necessary, and the fact that he had prepared for it
showed that he was both cunning and fearless.

Asta’s injunctions to me to say nothing showed plainly that


they intended still to keep their hiding-place a secret. And if
Shaw was the adventurer I believed, it was not likely that
either he or she would carry anything by which to reveal
their more respectable identity.

So at length, full of grave apprehensions, I left Aix,


sickened by its music and summer gaiety, and travelled
home, halting one night at the Grand in Paris, and duly
arrived at the Cecil in London. There I found a batch of
letters sent on to me from Upton End, and among them was
a formal letter from a firm of solicitors called Napier and
Norman, 129, Bedford Row, W.C., stating that they were
acting for the late Mr Guy Nicholson of Titmarsh Court, and
asking me to call upon them without delay.

Exercising caution lest I should be watched, I had


immediately on arrival telephoned from my hotel bedroom
to Lydford, but the response came back it a woman’s voice
that “the master” and Miss Asta were still abroad. Therefore
about noon on the morning following my return I went
round to Bedford Row in a taxi, and was quickly shown into
the sombre private room of an elderly, quiet-spoken man—
Mr George Napier, head of the firm.

“I’m extremely glad you have called, Mr Kemball,” he said,


as he leaned back in his chair. “I believe you were present
at Titmarsh very soon after the unfortunate death of our
client, Mr Guy Nicholson. Indeed, I remember now that we
met at the inquest. Well, Mr Nicholson, with his father and
grandfather! before him, entrusted his affairs in our hands,
and, naturally, after his decease we searched his effects for
any papers that were relative to his estate, or any private
papers which should not fall into anybody’s hands. Among
them we found this letter, sealed just as you see it, and
addressed to you. He evidently put it aside, intending to
post it in the morning, but expired in the night.”

And taking a letter from a drawer in his writing-table, he


handed it across to me.

I glanced at the superscription, and saw that it was


addressed ready for the post and that a stamp was already
upon it.

“Poor Nicholson’s death was a most mysterious one,” I


exclaimed, looking the solicitor full in the face; “I don’t
believe that he died from natural causes.”

“Well, I fear we cannot get away from the medical


evidence,” replied the matter-of-fact, grey-faced man,
peering through his spectacles. “Of course the locked door
was a most curious circumstance—yet it may be accounted
for by one of the servants, in passing before retiring,
turning the key. Or, as you suggested at the inquest, the
servant who entered the library in the morning may have
thought the door was locked. It might have caught
somehow, as locks sometimes do.”

I shook my head dubiously, and with eager fingers tore


open the message from the dead.

From its date, it had evidently been written only a few


hours prior to his untimely end, and it read—

“Strictly Private.

“Dear Mr Kemball,—I fear, owing to the fact that I have


promised Asta to take her motoring on Sunday, that I may
not be able to keep my appointment with you. Since my
confidential conversation with you, I have watched and
discovered certain things at Lydford which cause me the
keenest apprehension. Shaw is not what he pretends to be,
and many of his movements are most mysterious. By dint
of constant watching both while I have been guest there
and also by night when they have believed me to be safely
at home, I have ascertained several very remarkable facts.

“First. In secret and unknown to any—even to his gardeners


—he sets clever traps for small birds, which he visits
periodically at night, and takes away the unfortunate
creatures he finds therein.

“Secondly. He is in the habit of going forth in the night and


walking through Woldon Woods to a spot close to
Geddington village, at the corner of the road from Newton,
and there meeting a middle-aged man who frequently stops
at the inn. Once I followed them and overheard some of
their conversation. They were planning something, but what
I could not make out. However, I feel sure that they both
discovered my presence, and hence he seems in fear of me
and annoyed whenever I visit Lydford.
“Thirdly. In his bedroom there is a cupboard beside the
fireplace. The door is enamelled white, and at first is not
distinguishable from the rest of the panelling. Examine it,
and you will see that it is secured by two of the most
expensive and complicated of modern locks. What does that
cupboard contain? The contents are not plate or valuables,
for there is a large fireproof safe downstairs. Some mystery
lies there.

“Fourthly. Though he makes most clever pretences of


devotion to Asta, he hates her. Poor girl, she loves him, and
cannot see those black, covert looks he so often gives her
when her back is turned. But I have seen them, and I know
—at least, I have guessed—the reason.

“Fifthly. If you are a frequent guest there, you will hear him
sometimes utter a strange shrill whistle for no apparent
purpose, as though he does it quite unknowingly. But it is
with a purpose. What purpose?

“I feel that Asta is in danger, and it is therefore my duty to


protect her and elucidate the mystery of the strange
conspiracy which I feel convinced is now in progress. It is to
discuss these matters, and to combine to keep vigilant
watch, that I am anxious to spend a few hours with you.
Think carefully over these five points, and if I am unable to
come on Sunday I will motor over on Monday about eleven
in the morning.

“Meanwhile be careful not to show that you either know or


suspect anything. I know Shaw suspects me, and therefore
by some means I must remove his suspicions.

“That, however, will be a matter for us to discuss seriously


when we meet.
“Asta has told me of a strange and extremely weird incident
which occurred to her one night a little while ago in the
house of a friend—the apparition of a black shadowy hand. I
believe I have the solution of the mystery—a most
remarkable and terrible one.

“I ask your assistance in this affair, and am eager to meet


you to discuss it fully. Kindly destroy this letter.—Yours very
sincerely,—

“Guy Nicholson.”

I sat dumbfounded. It was just as I had believed. The man


struck down so suddenly had discovered the actual truth!
He had watched in patience and learned some strange and
startling facts.

The reference to the hand filled my mind with the hideous


recollection of what I had seen in that roadside inn at
Arnay-le-Duc—and of Arnold’s strange warning. Who was
Harford—the name I was to remember. Asta had told her
lover of her own experience, and he had solved the
mystery!

Yet he had not been spared to reveal it to me. His lips had
been closed by death. The name of Harford was still
unknown to me.

How long I sat there staring at the closely written letter in


my hand I know not. But I was awakened to a
consciousness of where I was by Mr Napier’s quiet voice
exclaiming—

“I see that my late client’s letter has made a great


impression upon you, Mr Kemball. I presume it is of a
purely private character, eh?”
“Purely private,” I managed to reply. “It does not concern
his affairs in any way whatsoever, and it is marked ‘strictly
private.’”

“Oh, very well. I, of course, have no wish whatever to


inquire into your private affairs with my dead client,” replied
the solicitor. “I believed that it might contain something
important, and for that reason hesitated to send it through
the post.”

“Yes,” I said meaningly, “it does contain something


important—very important, Mr Napier. Had this been placed
in my hand in time, my poor friend’s life might have been
saved.”

“What do you mean?” he asked quickly, staring at me


across the table. “Have you evidence—evidence of foul
play?”

“No evidence, but I find a distinct motive.”

“Anything upon which we could work in order to bring the


culprit to justice—if Mr Nicholson did not really die a natural
death?”

“I tell you he did not!” I cried angrily. “The village jury were
impressed by the medical evidence, as all rustic juries are.
Your client, Mr Napier, discovered another man’s secret, and
the latter took steps to close his lips.”

“But can you prove this? Can you name the man?”

“Yes,” I said, “I can name the man. And one day I shall
prove it.”

“You can! Why not place the matter in the hands of the
police, together with what is revealed in that letter?” he
suggested. “Allow me to act.”

“I shall act myself. At present it is not a matter for the


police. Certain facts have come to my knowledge which, if
told at Scotland Yard, would not be believed. Therefore at
present I intend to keep my knowledge strictly to myself,”
and replacing the dead man’s message in its envelope, I put
it safely into my breast-pocket, and, taking leave of the
solicitor, was soon in my taxi whirling along Holborn.

Why had Nicholson suspected that Shaw’s affection for his


foster-daughter was only feigned? Why did he allege that
Shaw hated her? Why was he in such mortal terror lest
some evil should befall her?

Perhaps, after all, in watching so closely he had, as is so


easy, discovered certain circumstances and misjudged
them, for certainly as far as I could see Shaw was entirely
devoted to the girl who had been his constant companion
ever since her childhood days. Nevertheless, that strange
letter, penned by the man whose intention it had been to
reveal to me the secret of the weird shadow of the night,
had caused me to determine to continue the vigil which had
been so abruptly ended.

I, too, would watch closely as soon as I learnt of their


hiding-place, as closely as the dead man had done. If Asta
were in actual peril, then I would stand as her protector in
place of the upright, honest young fellow who, it seemed,
had lost his life in the attempt.

But the days, nay weeks, went on. September ended and
October came with rain and chilly wind, and though I
returned to Upton End, and frequently made inquiry over
the telephone to Lydford, yet, though I wrote to Davis at
the Poste Restante at Charing Cross, I could learn no news
of them. They had descended those back stairs of the hotel
at Aix, and disappeared as completely as though the earth
had swallowed them up.

One day in the middle of October, with sudden resolve to


carry out Nicholson’s injunction to investigate, I drove over
to Lydford, and on arrival, about noon, found all smart and
well-kept as though its owner were in residence.

I told a rather lame story to the housekeeper, who, knowing


me, came to me in the long, chintz-covered drawing-room,
the blinds of which were down. She had not heard from her
master for a month past, the pleasant-faced woman
explained. He was then in Aix. I said that I had left him
there and returned to England, and was now anxious to
discover where he was.

Then, after a brief chat, I exhibited my left forefinger


enveloped in an old glove, and told her that on my way I
had some engine-trouble and had hurt my finger.

“I believe Mr Shaw keeps up in his room a small medicine


chest,” I said, for I recollected that he once told me that he
kept one there. “I wonder if I might go up and try and find
a piece of bandage.”

“Certainly,” replied Mrs Howard, and she led me upstairs to


the apartment over the drawing-room, which I had come to
Lydford for the purpose of examining. It was a large, airy,
and well-furnished room, with a big book-case at one end
and a canary in a cage at the window.

Without much difficulty she discovered the small black


japanned box, containing various surgical drugs and
bandages, and I at once sent her down to obtain a small
bowl of warm water.
Then, the instant she had gone, I sought for the cupboard
indicated by the dead man’s letter.

Yes, it was there, a long, narrow cupboard beside the


fireplace, secured by two large locks of a complicated
character such as one finds on safe or strongroom doors.

I bent and examined them thoroughly.

The bed, I noticed, was set so that the eyes of any one
lying in it would be upon that door.

What secret could be concealed there? What had the dead


man suspected? Ay, what indeed?
Chapter Twenty Three.
“A Foreigner.”

I remained a long time attending to my damaged finger—


which in reality had been injured a week before—at the
same time thoroughly investigating the missing man’s
apartment. Except for the cupboard, secured so
mysteriously by those combination locks, there was nothing
extraordinary about it. The outlook was pleasant across the
wide undulating park, and the chairs with soft cushions and
couch showed plainly that Harvey Shaw loved to take his
ease.

In no hurry to depart, I chatted affably to Mrs Howard,


wandering about the big, old-fashioned home, into regions I
had never been before.

“Poor Mr Nicholson used to stay here sometimes, didn’t


he?” I inquired presently, in a casual way.

“Oh yes, sir, the master used to delight in having the poor
young gentleman here, sir. He used to have the blue room,
nearly opposite Mr Shaw’s—the one which looks out over
the front drive. Poor Mr Nicholson! We all liked him so
much. Wasn’t it sad, sir?”

“Very sad, indeed,” I said. “The blow must nearly have


broken Miss Asta’s heart.”

“Ah! It did, sir. At first I thought the poor child would have
gone out of her mind. She was so devoted to him. Mr Shaw
was also very fond of him, I know, for I once heard him say
that he was the only man he would choose as Miss Asta’s
husband.”
“When did he say that?”

“He was sitting in the smoking-room with a friend of his—


one of the justices—Sir Gilbert Campbell, one evening after
dinner, about a fortnight before the poor young gentleman
died. I happened to be; passing and overheard his words.”

I pondered for a moment. Either Shaw was a past-master in


the art of preparing a coup, or else Guy’s surmises were
wrong. Here, in the intimacy of the family, it was declared
that Shaw was devoted to Asta. Certainly my own
observations went to confirm that supposition.

“I wonder who knows Mr Shaw’s whereabouts?” I said


presently. “I want to communicate with him upon a very
important matter.”

“Well, sir, it’s very funny that he hasn’t written to me. He’s
never been silent so long before.”

“How long have you been with him?”

“Oh, about three years now, sir.”

Then together we descended the broad oak staircase, and I


went forth into the beautiful gardens chatting with the old
white-bearded head-gardener, and going through the grape
and peach houses, all of which were most perfectly kept.

How strange, I reflected; what would this large staff of


superior servants think if they knew the truth—that their
master, a man of mystery, was a fugitive from justice—that
he and Asta had crept down the back stairs of an hotel and
disappeared into the night while the police had entered
from the front.
As I drove back in the evening through those autumn-tinted
lanes, with smiling meadows everywhere, I calmly reviewed
the situation. After all, there was really no actually
mysterious fact in Harvey Shaw having in his bedroom a
cupboard so securely locked. He, upon his own admission,
led a double life, therefore it was only to be supposed that
he possessed a good many papers, even articles of clothing,
perhaps, which he was compelled to hide from the prying
eyes of his servants.

I recalled the whole of Guy’s letter, and found that the chief
point was the fact that he had solved the weird mystery of
that strange hand—that shadowy Something which I myself
had witnessed, and against which I had been warned by
Arnold.

What was it?

But I put aside the puzzle. My chief thought was of Asta.


Where could she be? Why had she not sent me word in
secret of her hiding-place? She had, by tacit agreement,
accepted me as her friend, hence I was disappointed at
receiving no word from her.

That night, after reading my London paper over a cigar, as


was my habit, I left the library about eleven o’clock and
retired to my room.

I must have been sound asleep when, of a sudden, the


electrical alarm which my father years ago had had placed
upon the door of the big safe in the library for greater
security went off with a tremendous clatter, and I jumped
up, startled.

Taking my revolver from a drawer in the dressing-table, I


rang the bell in the servants’ quarters and switched on my
electric hand-lamp. But already the household was alarmed,
and the dogs were barking furiously at the intruders,
whoever they were.

Accompanied by my man Adams, I descended the front


stairs and, revolver in hand, entered the library, the window
of which stood open, while below the safe door there lay
upon the carpet a cheap bull’s-eye lantern with two
cylinders containing gas and some other paraphernalia,
showing that the thieves were men of scientific method, for
their intention had, I saw, been to use the oxy-hydrogen
blow-pipe. The heads of some of the rivets had been
removed and a small hole drilled through the chilled steel
three-quarters of an inch thick.

All had gone well until they had touched the handle of the
safe door, which had set off the alarm, the existence of
which they had never suspected. Then their only safety lay
in flight, and they had escaped, leaving behind them the
objects I have enumerated.

Adams telephoned for the police, while Tucker came up


from the Lodge, and I let loose the dogs and went outside
into the drive. But, unfortunately, the thieves were already
safely away, and were not likely to be caught, for in
response to the telephonic message I was told that the rural
constable was out on his beat, and was not expected back
for another couple of hours.

We three men, with several of the maid-servants, stood


outside on the lawn discussing the affair with bated breath
in the dead stillness of the night when, of a sudden, we
distinctly heard in the far distance down in the valley
beyond the King’s Wood the starting of a motor-car and the
gradual faintness of the sound as it receded along the high
road.
“There they go!” I cried. “They came in a car, and it was
awaiting them at the foot of the hill near the Three Oaks
crossways.”

Then I rushed to the telephone instrument and spoke to the


police-sergeant on duty in Newport Pagnell, asking him to
stop any car approaching from my house, informing him
what had occurred.

But half an hour later he rang up to tell me that no car had


entered the town from any direction; therefore it was
apparent that in preference to passing through Newport
Pagnell it had been turned into one of the side roads and
taken a cross-country route to some unknown destination.

I said nothing, but to me it was quite apparent that the


object of the attempt upon my safe was the mysterious
bronze cylinder, which I held in trust from Melvill Arnold.

When alone in the room I opened the safe with my key, and
to my satisfaction saw the battered ancient object still
reposing there, together with the letters and the translation
of the hieroglyphics.

Once again I took out the heavy cylinder, the greatest


treasure of the strange old fellow who had deliberately
destroyed a fortune, and held it in my hand filled with
wonder and bewilderment. What could it contain that would
astonish the world? Surely nothing nowadays astonishes
this matter-of-fact world of ours. We have become used to
the demonstrations of wonders, from the use of steam to
the development of aviation, the telephonic discovery and
the application of wireless telegraphy.

How I longed to call in a blacksmith, cut through the metal,


and ascertain what was therein contained. But I did not
dare. I held the thing in trust for some unknown person
who, on Thursday, the third day of November, would come
to me and demand its possession.

All that I had been told of the misfortunes which had fallen
upon its possessor, and the mysterious fate which would
overtake any who attempted to tamper with it, flashed
through my brain. Indeed, in such train did my thoughts run
that I began to wonder if possession of the thing had any
connection with the appearance of that mysterious hand.

Presently, however, I put the cylinder back into its place and
relocked the safe, for the police from Newport Pagnell had
arrived, and I bade them enter.

They made a minute examination of the room and took


possession of the objects left behind by the intruders, but
upon them no finger-prints could be found. My visitors were
evidently expert thieves, for they had worn gloves. And
they had, no doubt, been in the house a full hour before
they had tried the safe handle and unconsciously set off the
alarm.

Had they applied the powerful jet to the steel door, and
fused a hole through it, then they might have accomplished
their object without disarranging the alarm at all.

Next day, however, packing the cylinder, the old newspaper,


and the letters in the bag, I took them up to London, where
I placed them in a box in the Safe Deposit Company’s vaults
in Chancery Lane. Afterwards I lunched at my club and
returned again to Upton End the same evening.

Suddenly it occurred to me while I sat alone eating my


dinner that night that if Harvey Shaw and Mrs Olliffe were
actually friends then the latter would probably be aware of
his whereabouts.
The suggestion aroused me to activity, and it being a fine
bright evening with the prospect of a full moon later, I got
out my thick motor-coat, packed a small bag, and after
tuning up the car set out on the long run towards Bath.

My way lay through Fenny Stratford and Bicester, through


Oxford, and down to Newbury. When I passed the Jubilee
clock in the latter town it was a quarter-past two, while in
the broad street of Marlborough, eighteen miles farther on,
I stopped to examine the near tyre. It had, as I expected, a
puncture. Therefore I leisurely put on my Stepney, and with
thirty odd miles before me drove out upon the old highway
over the hill through Calne, and up Black Dog Hill, to
Chippenham, where in the market-place stood a constable,
with whom I exchanged greetings.

There is a certain weird charm in motoring at night, when


every town and village is dark and in slumber. Yet it is
surprising how many people are out at an early hour. Even
ere the first flush of dawn one finds sturdy men going to
work with their day’s food in the bag upon their backs and
teams of horses being driven to the fields.

It was nearly half-past five when I sped down the steep


incline of Box Hill, and, slipping through Box Village and
Batheaston, found myself winding round that leafy road
with the city of Bath lying picturesquely below.

At six I was once again at the York House Hotel, and after a
wash went for an early-morning stroll in the town. Then,
after breakfast, I took my hat and stick and strolled out for
nearly three miles along the road to the inn at Kelston,
where I called for a glass of ale, and sat down to chat with
the white-bearded landlord, who at once recognised me as
having been a customer on a previous occasion.
For a long time, as I sat in the cosy little parlour, the table
of which was dark and polished with the ale of generations
spilt upon it, we chatted about the weather, the prospects of
harvest, and the latest iniquity of taxation, until in a
careless way I remarked—

“I suppose in summer you have lots of visitors down from


London.—I mean the people who have big houses about
here entertain a lot?”

“Oh, I dunno!” replied the old fellow, sipping his glass which
he was taking with me. “The Joiceys do have a lot o’
visitors, and so do the Strongs, but Mrs Olliffe’s been away,
an’ has only just come back.”

“And Mr King?”

“He’s been away too. Ridgehill’s been shut up and half the
servants away on ’oliday.”

“And they are back now?”

“Yes; Mrs Olliffe’s been abroad—so the butler told me


yesterday. But there—” and his lips closed suddenly, as
though he had something to say, but feared to utter it.

“Rather a funny lot—so I’ve heard, eh?” I remarked.

“Yes. Nobody can quite make ’em out—to tell the truth.
Only the night before last, or, rather, about a quarter to five
in the morning, Mrs Olliffe, her brother and another
gentleman went by ’ere in a car on their way ’ome. They’d
been out all night, so the chauffeur told me yesterday. Mr
King drove the car.”

“Out all night!” I echoed, in sudden wonder.


“Yes. And they’d been a long way, judging from the
appearance of the car. I ’appened to get up to see the time,
and looked out o’ my window just as they came past. It
isn’t the first time either that they’ve been out all night. The
village knows it, and every one is asking where they go to,
and what takes ’em out o’ their beds like that.”

“Who was the gentleman with them?” I inquired eagerly.

“Ah! I couldn’t see ’im very well. He was in a big frieze coat,
and wore a black-and-white check cap. I didn’t catch his
face, but, by his clothes, he was a stranger to me.”

“You’ve only seen him on that occasion.”

“Only that once, sir. The chauffeur told me, however, that ’e
isn’t staying at Ridgehill, and that nobody saw him. So ’e
must ’ave got out after passing through the village. Perhaps
it was somebody they were givin’ a lift to. I’ve seen Mrs
Olliffe a-takin’ notice of some queer people sometimes. And
funnily enough, only yesterday a gentleman came in ’ere
and was a-making a lot of inquiries after her. ’E was a
foreigner—a Frenchman, I think.”

“A Frenchman!” I cried. “What was he like?”

“Oh! Like most Frenchman. ’E ’ad finnikin’ ways, was


middle-aged, with a brown beard which he seemed always
a-strokin’. ’E ’ad lunch ’ere, and stayed all the afternoon
smokin’ cigarettes and lookin’ through this window as
though he hoped to see ’er pass. ’E was so inquisitive that I
was glad when ’e’d gone. I suppose,” the man added, “’e’s
somebody she’s met abroad, eh?”

But I knew the truth. His inquisitive visitor was Victor


Tramu!
Chapter Twenty Four.
A Woman’s Word.

A hot, dusty walk took me beside the telegraph wires back


to Bath, and the remainder of the day I spent in idleness in
the hotel.

If the great French detective were in the vicinity then I had


no desire to be seen by him. Therefore I deemed it best to
lie quite low until nightfall.

At four o’clock, after great delay I got on to Tucker on the


telephone, and inquired if there had been any letters or
messages for me.

“The police have been here again, and there’s a telephone


message, sir,” replied the old man’s voice. “It came about
eleven o’clock, from a lady, sir. I took it down.”

“Read it over,” I said.

Then, listening intently, I heard the old man’s voice say—

“The message, sir, is: ‘Please ask Mr Kemball to ring up, if


possible, 802 Bournemouth—the Royal Bath Hotel—at six
o’clock this evening—from Miss Seymour.’”

My heart gave a bound of delight.

“Nothing else, Tucker?”

“No, sir. That’s all the lady said. She seemed very anxious
indeed to speak to you.”
“All right, Tucker. I’ll be back in a day or two. By the way,
send on my letters to the Grand Hotel, Bournemouth.”

“Very well, sir.”

“And tell the police not to worry any further over the
burglary. Tell them I will see the inspector in Newport
Pagnell on my return.”

“All right, sir.”

And then I hung up the receiver and rang off.

Asta was at Bournemouth! My first impulse was to start at


once to see her, but recollecting the reason I had come
there to Bath, I managed to curb my impatience, eat my
dinner in the quiet, old-fashioned coffee-room, and
afterwards wait until darkness fell.

I had no fixed plans, except to approach the Manor-House


unobserved. I longed to call boldly upon the woman whom I
knew to be an adventuress, but I could not see what benefit
would accrue from it. If any conspiracy were in progress,
she would, of course, deny all knowledge of Shaw’s
whereabouts.

Therefore I bought some cigars, which I placed in my case,


and when the autumn twilight had deepened into night I put
on my motor-cap, and taking my stick, set out again to
cover the three miles or so which lay between the hotel and
the residence of the wealthy widow.

I did not hurry, and as I approached the village and passed


the inn with the red blinds I kept a wary eye, fearing lest
Tramu might be in the vicinity.
That it was he who had been making inquiry of the landlord
there was no doubt. In what manner the French police had
gained knowledge of the woman Olliffe’s address I knew
not, and why he was in England watching her, was equally a
mystery. One fact was evident—namely, that the Paris
Sûreté had some serious charge against her; and further,
that she must be all unconscious of the presence of the
renowned police-agent.

Should I discover any hint or gain anything by giving her


warning? I asked myself.

No; she was far too clever for that. If, as I had suspected,
she had had any hand in poor Guy’s death, then it was only
right that the inquiries and action of the police should not
be interfered with. Again, was it not a highly suspicious
circumstance that, with her husband—the man King, who
posed as her brother—together with a stranger, she had
returned home at that early hour in a car, a few hours after
a car had left the King’s Wood, half a mile from my own
house?

I passed through the village unobserved, and out again up


the steep hill, until I came to that low wall behind which lay
the part surrounding Ridgehill Manor—that same wall from
which a few weeks before I had obtained my first sight of
the house of the adventuress. Fortunately, the night had
become cloudy, threatening rain, and the moon was hidden.
So, mounting the wall, I entered the park and walked
across towards the broad lawn in front of the manor. A dry
ditch separated the lawn from the park to prevent cattle
from approaching, and this I presently negotiated, at last
standing upon the lawn itself. Near by, I saw a weeping ash,
and beneath its bell-like branches I paused and there
waited.
From where I stood I could see into the big lighted drawing-
room, the blinds of which were up, but there was no one
within, though the French windows stood open.

I could hear voices—of the servants, most probably—and


the clatter of dishes being washed after dinner. But the
night was very still; not a leaf stirred in the dark belt of firs
which lay on my left, and which presently afforded me
better shelter, allowing me to approach nearer the house.

The night-mists were rising, and the air had become chilly.
Certainly this woman of many adventures, even though she
were a convicted criminal, managed to live amid delightful
surroundings.

As the evening wore on I caught a glimpse of her crossing


the room in a black low-cut dinner-dress edged with silver—
a truly handsome gown. She swept up to the piano, and
next moment there fell upon my ear the music of one of the
latest waltzes of musical comedy.

Then her husband, cigar in hand and in well-cut evening-


dress, came to the French window, looked out upon the
night, and retired again.

But after that I saw nothing until an hour later, when the
butler closed the window carefully and bolted it, and then
one by one the lights in the lower portion of the fine
mansion disappeared and those upstairs were lit. Two
windows, evidently the double windows of a corner-room
opposite me, were lit brilliantly behind a green holland
blind, but half an hour later they also were extinguished.

I glanced at my watch. It was then half-past eleven, and


the house was in total darkness. Yet I still waited,
wondering vaguely if Tramu were still in the vicinity.
I found an old tree-stump, and sitting upon it, waited in
watchful patience, wondering if the agent of French police
would make his appearance. Suddenly, however, a bright
stream of light, evidently from an electric torch, shot from
one of the upstairs windows, and continued for some
seconds. Then it was shut off again, only to be renewed
about a minute later.

It was a signal, and could be seen from the high road!

My curiosity was now thoroughly aroused, and I moved


cautiously across the lawn to such a position that I could
see any one leaving or approaching the house by the drive.

Again I waited for fully twenty minutes, when a slight


movement caused me to turn, and I saw the figure of a
woman hurrying along the side of the lawn in the shadow of
the belt of firs. At first I was puzzled as to who it might be,
but presently, when she was compelled to pass out of the
shadow into the grey light cast by the clouded moon, I saw
that it was the woman who called herself Olliffe. She wore a
dark dress with a dark shawl thrown over her head.

In her eager hurry she had not noticed my presence as I


stood there in the shadow; therefore, when she had passed
out into the misty park with its dark clump of trees, I
quickly followed with noiseless tread over the dewy grass.

She had evidently signalled to somebody, unknown to her


husband!

Straight across the wide grass-lands I followed until she


gained a spot where a stile gave entrance to a dark wood
on the opposite side of the park. There she halted, and I
was only just in time to draw back in the shadow and hide
myself.
I watched, and a few minutes later I was startled at hearing
that peculiar whistle of Shaw’s, and next moment he
emerged from the wood and joined her.

“Well, what’s the fear?” I heard him ask her quickly. “I had
your wire this morning, and got to Bath by the last train.
Couldn’t you have written?”

“No; it was highly dangerous,” was her low response; and


then she uttered some quick explanation which I could not
catch.

Was it possible that she had learnt of Tramu’s visit, for I


distinctly heard him cry—

“You fool! Why did you bring me here? Why weren’t you
more wary?”

But in her reply she turned her back upon me, so that I
could not distinguish her words.

They stood close together in the darkness, conversing in


low tones, as though in earnest consultation, while I,
holding my breath, strove in vain to catch their words.

The only other sound was the mournful hooting of an owl in


the trees above; for the dead stillness of the night was now
upon everything.

“Exactly,” I heard the woman say. “My own opinion is that


he suspects. Therefore you must act quickly—as before.”

“I—I am hesitating,” the man’s voice replied. “I can’t bring


myself to do it. I really can’t!”

“Bosh! Then leave it to me,” she urged, in a hard, rasping


voice. “You’re becoming timid—chicken-hearted. It isn’t like
you, surely.”

“I’m not timid,” he protested. “Only I foresee danger—great


danger.”

“So do I—if you don’t act promptly. Get her away from
Bournemouth. Go anywhere else you like.”

They were speaking of Asta! I strained my ears, but her


further words were inaudible.

In a moment, however, I became conscious of a slight


stealthy movement in the bushes near where I was
standing, and turned my head quickly.

The next second I realised that only a few yards distant


from me the dark figure of a man had come up through the
undergrowth, but so carefully that he had made no noise.

He stood ten yards away, peering out at the pair, but all
unconscious of my presence there. He was watching
intently, and by his silhouette in the darkness I recognised
the bearded face of none other than the great agent of the
Paris Sûreté, Victor Tramu!
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like