From 983942712af46c0d18e11b0781db5c195c997e12 Mon Sep 17 00:00:00 2001 From: Kyle Isom Date: Wed, 8 Nov 2017 23:46:37 -0800 Subject: [PATCH] Initial import. --- CMakeLists.txt | 64 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 16 ++++++++++++ notes/chapter1.txt | 22 ++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 notes/chapter1.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..a0d3833 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,64 @@ +SET(MAKE_VERBOSE_MAKEFILE ON) +SET(CMAKE_BUILD_TYPE Debug CACHE STRING "default to debug" FORCE) +set(CXX_EXTENSIONS OFF) + +# Basic project setup. +cmake_minimum_required(VERSION 3.5) # Xenial's CMake version. +project(ods) +set (${PROJECT_NAME}_VERSION_MAJOR 0) +set (${PROJECT_NAME}_VERSION_MINOR 1) + +# Require clang. +set(CC clang) +set(CXX clang++) + +# Set C++ compile flags for all builds. +add_compile_options(-Wall -Wextra -pedantic -Wshadow -Wpointer-arith) +add_compile_options(-Wcast-align -Wwrite-strings -Wmissing-declarations) +add_compile_options(-Werror -Wunused-variable -fno-elide-constructors) + +# These might be contentious. +add_compile_options(-Weffc++) +# add_compile_options(-std=c++14) + +if(CMAKE_BUILD_TYPE MATCHES DEBUG) +add_compile_options(-O0) +endif() + +if (CMAKE_BUILD_TYPE MATCHES RELEASE) +add_compile_options(-O2) +endif() + +if(CMAKE_GENERATOR MATCHES "Unix Makefiles") +SET(CMAKE_COLOR_MAKEFILE ON) +SET(CMAKE_VERBOSE_MAKEFILE ON) +endif() + +file(GLOB_RECURSE SOURCES src/*.cc src/*.cpp) +file(GLOB_RECURSE HEADERS include/*.h) +file(GLOB HEADIRS include/*) # ha ha ha + +include_directories(include test/include) + +# Build shared library that can be reloaded while testing. +add_library(${PROJECT_NAME} SHARED ${SOURCES}) + +# Add static library for inclusion in final builds. +add_library(${PROJECT_NAME}-static STATIC ${SOURCES}) + +# Require C++14. +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 14) +set_property(TARGET ${PROJECT_NAME}-static PROPERTY CXX_STANDARD 14) + +set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET ${PROJECT_NAME}-static PROPERTY CXX_STANDARD_REQUIRED ON) + +# Set up the library installation target. +install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME}) +install(TARGETS ${PROJECT_NAME}-static DESTINATION lib/${PROJECT_NAME}) + +# Install the headers. +install(DIRECTORY ${HEADIRS} DESTINATION include/${PROJECT_NAME}) + +# include(CMakeTests.txt) +# include(CMakePack.txt) \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..ffd05b2 --- /dev/null +++ b/README.md @@ -0,0 +1,16 @@ +# ODS +## Open Data Structures + +This is an implementation and playground for the code in the +[Open Data Structures](http://opendatastructures.org/) books. +It contains both the C++ and Python repos. + +Tree: + +``` +. +├── include # C++ headers +├── notes # notes from the text +├── ods # Python sources +└── src # C++ sources +``` diff --git a/notes/chapter1.txt b/notes/chapter1.txt new file mode 100644 index 0000000..af54fcc --- /dev/null +++ b/notes/chapter1.txt @@ -0,0 +1,22 @@ +# Chapter 1 + +## Efficiency + +Concerns: +1. Number of operations +2. Processor speeds +3. Storage space + +## Interfaces + +* Interface / abstract data type + +### Queue interface + +* `add(x)` (aka `queue`): add `x` to the queue +* `remove()` (aka `dequeue`): remove the next value from queue and return it + +* Normal queue: the first element inserted is removed first +* Priority queue: elements are inserted with a priority, and the smallest + element is removed. This function is usually called `deleteMin`. +* LIFO queue: a stack; add and remove are called `push` and `pop`.