Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
eugnsp committed Nov 28, 2019
1 parent 438209b commit c087793
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 24 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ This is a library of usefull and interesting references – web pages, video
* :keycap_ten: [Bit algorithms](data_structures_and_algorithms/bit_algorithms.md)
* :exclamation: [Combinatorial algorithms](data_structures_and_algorithms/combinatorics.md)
* :pushpin: [Dynamic programming](data_structures_and_algorithms/dynamic_programming.md)
* :game_die: [Game theory](data_structures_and_algorithms/game_theory.md)
* :spades: [Game theory](data_structures_and_algorithms/game_theory.md)
* :triangular_ruler: [Geometric algorithms](data_structures_and_algorithms/geometric.md)
* :curly_loop: [Graphs](data_structures_and_algorithms/graphs.md)
* :hash: [Hash tables](data_structures_and_algorithms/hash_tables.md)
* :left_right_arrow: [Lists](data_structures_and_algorithms/lists.md)
* :heavy_plus_sign: [Numeric algorithms](data_structures_and_algorithms/numeric.md)
* :symbols: [Parsing algorithms](data_structures_and_algorithms/parsing.md)
* :game_die: [Randomized algorithms](data_structures_and_algorithms/random.md)
* :1234: [Sequence algorithms](data_structures_and_algorithms/sequence.md)
* :signal_strength: [Sorting](data_structures_and_algorithms/sorting.md)
* :abc: [String algorithms](data_structures_and_algorithms/string.md)
Expand Down
34 changes: 31 additions & 3 deletions cpp/core_language.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [Storage class specifiers](#storage-class-specifiers)
- [Exceptions](#exceptions)
- [Expressions](#expressions)
- [Canonical implementations of operators](#canonical-implementations-of-operators)
- [Operators](#operators)
- [Order of evaluation](#order-of-evaluation)
- [Type conversions](#type-conversions)
- [`dynamic_cast`](#dynamic_cast)
Expand All @@ -38,6 +38,7 @@
- [Types](#types)
- [Aggregate, trivial and POD types](#aggregate-trivial-and-pod-types)
- [Floating-point types](#floating-point-types)
- [`__float128`](#__float128)
- [Function types](#function-types)
- [Integral types](#integral-types)
- [Opaque typedefs](#opaque-typedefs)
Expand Down Expand Up @@ -159,6 +160,10 @@ See [Relocation – Memory – Optimization and hardware](optimization_a

### `constexpr`

:link:

- [*Why is a `constexpr` function on a reference not `constexpr`?*](https://stackoverflow.com/questions/54124899/why-is-a-constexpr-function-on-a-reference-not-constexpr) – Stack Overflow

:movie_camera:

- S.Schurr. *`constexpr`:* [*Introduction*](https://www.youtube.com/watch?v=fZjYCQ8dzTc), [*Applications*](https://www.youtube.com/watch?v=qO-9yiAOQqc) – CppCon (2015)
Expand Down Expand Up @@ -215,11 +220,16 @@ See [*Friend function templates* – Function templates – Templates](t

## Expressions

### Canonical implementations of operators
### Operators

:link:

- [*What are the basic rules and idioms for operator overloading?*](https://stackoverflow.com/questions/4421706/what-are-the-basic-rules-and-idioms-for-operator-overloading) – Stack Overflow

:anchor:

- [Canonical implementations](https://en.cppreference.com/w/cpp/language/operators#Canonical_implementations) – C++ reference
- [*`operator` overloading*](https://en.cppreference.com/w/cpp/language/operators) – C++ reference
- [*Canonical implementations*](https://en.cppreference.com/w/cpp/language/operators#Canonical_implementations) – C++ reference

### Order of evaluation

Expand Down Expand Up @@ -310,6 +320,7 @@ See [*Friend function templates* – Function templates – Templates](t

- R.Chen. [*Non-capturing C++ lambdas can be converted to a pointer to function, but what about the calling convention?*](https://devblogs.microsoft.com/oldnewthing/20150220-00/?p=44623) (2015)
- A.Allain. [*Lambda functions in C++11 – the definitive guide*](https://www.cprogramming.com/c++11/c++11-lambda-closures.html) (2011)
- [*What is a lambda expression in C++11?*](https://stackoverflow.com/questions/7627098/what-is-a-lambda-expression-in-c11) – Stack Overflow
- [*Why are lambda expressions not allowed in an unevaluated operands but allowed in the unevaluated portions of constant expressions?*](https://stackoverflow.com/questions/22232164/why-are-lambda-expressions-not-allowed-in-an-unevaluated-operands-but-allowed-in) – Stack Overflow
- [*Can we get the type of a lambda argument?*](https://stackoverflow.com/questions/6512019/can-we-get-the-type-of-a-lambda-argument) – Stack Overflow

Expand Down Expand Up @@ -406,6 +417,17 @@ See also [*Floating-point arithmetic* – Numeric data structures and algori

- D.Howard. [*Byte swapping floating point types*](https://web.archive.org/web/20100125081223/http://www.dmh2000.com/cpp/dswap.shtml) (2007)

#### `__float128`

:link:

- [*`long double` (GCC specific) and `__float128`*](https://stackoverflow.com/questions/13516476/long-double-gcc-specific-and-float128) – Stack Overflow
- [*How to use GCC 4.6.0 libquadmath and `__float128` on x86 and x86_64*](https://stackoverflow.com/questions/6457385/how-to-use-gcc-4-6-0-libquadmath-and-float128-on-x86-and-x86-64) – Stack Overflow

:anchor:

- [*Additional floating types*](https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html) – GCC documentation

### Function types

:anchor:
Expand Down Expand Up @@ -481,3 +503,9 @@ See also [*Floating-point arithmetic* – Numeric data structures and algori
https://stackoverflow.com/questions/37618213/when-is-a-private-constructor-not-a-private-constructor
-->


<!-- https://medium.com/@barryrevzin/value-categories-in-c-17-f56ae54bccbe
http://www.stroustrup.com/terminology.pdf
https://stackoverflow.com/questions/20717180/in-c-what-categories-lvalue-rvalue-xvalue-etc-can-expressions-that-prod
-->
12 changes: 12 additions & 0 deletions cpp/optimization_and_hardware.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Floating-point arithmetic](#floating-point-arithmetic)
- [Heap allocation](#heap-allocation)
- [Integeral division](#integeral-division)
- [Memory access](#memory-access)
- [Return value optimization and copy elision](#return-value-optimization-and-copy-elision)
- [Undefined behavior](#undefined-behavior)
- [Strict aliasing rule](#strict-aliasing-rule)
Expand Down Expand Up @@ -71,6 +72,12 @@
- D.W.Jones. [*Reciprocal multiplication, a tutorial*](https://homepage.divms.uiowa.edu/~jones/bcd/divide.html) (1999)
- T.Granlund, P.L.Montgomery. [*Division by invariant integers using multiplication*](https://gmplib.org/~tege/divcnst-pldi94.pdf) (1994)

### Memory access

:link:

- [*Why don’t C++ compilers optimize this conditional boolean assignment as an unconditional assignment?*](https://stackoverflow.com/questions/40303182/why-dont-c-compilers-optimize-this-conditional-boolean-assignment-as-an-uncon) &ndash; Stack Overflow

### Return value optimization and copy elision

:camera:
Expand Down Expand Up @@ -115,6 +122,7 @@ See [*Type-punning* &ndash; Core language](core_language.md#type-punning).
- U.Drepper. [*What every programmer should know about memory*](https://people.freebsd.org/~lstewart/articles/cpumemory.pdf) (2007)
- D.A.Rusling. [Ch. 3: *Memory management*](http://www.tldp.org/LDP/tlk/mm/memory.html) &ndash; [The Linux kernel](http://www.tldp.org/LDP/tlk/tlk-title.html)
- [*Simple benchmark for memory throughput and latency*](https://github.com/ssvb/tinymembench)
- L.Maranget, S.Sarkar, P.Sewell. [*A tutorial introduction to the ARM and POWER relaxed memory models*](https://www.cl.cam.ac.uk/~pes20/ppc-supplemental/test7.pdf) (2012)

<!-- https://web.archive.org/web/20080107035604/http://www.cellperformance.com/mike_acton/2006/05/demystifying_the_restrict_keyw.html -->

Expand All @@ -127,6 +135,10 @@ See [*Type-punning* &ndash; Core language](core_language.md#type-punning).

### Access

:link:

- [*Why is transposing a matrix of `512x512` much slower than transposing a matrix of `513x513`?*](https://stackoverflow.com/questions/11413855/why-is-transposing-a-matrix-of-512x512-much-slower-than-transposing-a-matrix-of) &ndash; Stack Overflow

#### Copying

:link:
Expand Down
8 changes: 8 additions & 0 deletions cpp/std_library.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Sequence containers](#sequence-containers)
- [`std::array`](#stdarray)
- [`std::deque`](#stddeque)
- [`std::vector`](#stdvector)
- [`std::vector<bool>`](#stdvectorbool)
- [Unordered containers](#unordered-containers)
- [Input/output](#inputoutput)
Expand Down Expand Up @@ -221,6 +222,7 @@ V.Reverdy. [*On vectors, tensors, matrices, and hypermatrices*](http://www.open-

:anchor:

- M.Hoemmen et al. [*Historical lessons for C++ linear algebra library standardization*](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1417r0.pdf) &ndash; WG21/P1417R0 (2019)
- G.Davidson, ​B.Steagall. [*A proposal to add linear algebra support to the C++ standard library*](http://open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1385r3.pdf) &ndash; WG21/P1385R3 (2019)
- G.Davidson, ​B.Steagall. [*What do we need from a linear algebra library?*](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1166r0.pdf) &ndash; WG21/P1166R0 (2019)

Expand All @@ -232,6 +234,10 @@ V.Reverdy. [*On vectors, tensors, matrices, and hypermatrices*](http://www.open-
- [*Why is the new random library better than `std::rand()`?*](https://stackoverflow.com/questions/53040940/why-is-the-new-random-library-better-than-stdrand) &ndash; Stack Overflow
- [*Why not just use `random_device`?*](https://stackoverflow.com/questions/39288595/why-not-just-use-random-device) &ndash; Stack Overflow

:movie_camera:

- A.Weis. [*Random numbers are hard*](https://www.youtube.com/watch?v=WDScnjQwEK8) &ndash; Meeting C++ (2019)

---

## Regular expressions
Expand Down Expand Up @@ -362,6 +368,8 @@ V.Reverdy. [*On vectors, tensors, matrices, and hypermatrices*](http://www.open-
:link:

- H.Sutter. [GotW #29: *Strings*](http://www.gotw.ca/gotw/029.htm) &ndash; Guru of the Week (2009)
- [*Why `std::string` does not have `const char*` cast*](https://stackoverflow.com/questions/59076004/why-stdstring-does-not-have-const-char-cast) &ndash; Stack Overflow
- [*Why doesn’t `std::string` provide implicit conversion to `char*`?*](https://stackoverflow.com/questions/492061/why-doesnt-stdstring-provide-implicit-conversion-to-char) &ndash; Stack Overflow

:anchor:

Expand Down
27 changes: 7 additions & 20 deletions data_structures_and_algorithms/combinatorics.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,17 @@
## Table of contents <!-- omit in toc -->

- [Permutations](#permutations)
- [Generating permutations](#generating-permutations)
- [Algorithm L](#algorithm-l)
- [Heap’s algorithm](#heaps-algorithm)
- [Generating random permutations](#generating-random-permutations)
- [Fisher&ndash;Yates algorithm](#fisherndashyates-algorithm)
- [Algorithm L](#algorithm-l)
- [Heap’s algorithm](#heaps-algorithm)
- [Random permutations](#random-permutations)

---

## Permutations

<!-- https://stackoverflow.com/questions/31773203/is-it-possible-to-invert-an-array-with-constant-extra-space -->

### Generating permutations

#### Algorithm L
### Algorithm L

> Algorithm L for the given sequence of `n` initially sorted elements <code>{a<sub>0</sub> &leq; a<sub>1</sub> &leq; ... &leq; a<sub>n-1</sub>}</code>, generates all permutations visiting them in the lexicographic order. Gist of the algorithm: for the current permutation, find the longest descreasing subsequence on the right, <code>{...a<sub>p</sub> &leq; a<sub>i</sub> &gt; a<sub>j</sub> &gt; ... &gt; a<sub>k</sub>}</code>, find the next front element <code>a<sub>f</sub> &gt; a<sub>p</sub></code> with the largest possible `f` in the range `[i, k]`, swap <code>a<sub>f</sub></code> and <code>a<sub>p</sub></code>, and then put the remaining elements in the ascending order, i.e. reverse the subsequence <code>{a<sub>i</sub>...a<sub>p</sub>...a<sub>k</sub>}</code>.
Expand All @@ -33,7 +29,7 @@

- Sec. 7.2.1.2: *Generating all permutations* &ndash; D.E.Knuth. [*The art of computer programming.*](https://www-cs-faculty.stanford.edu/~knuth/taocp.html) *Vol. 4A: Combinatorial algorithms, Part 1* (2011)

#### Heap’s algorithm
### Heap’s algorithm

> Heap’s algorithm generates all possible permutations of `n` objects. The algorithm minimizes movement: it generates each permutation from the previous one by interchanging a single pair of elements; the other `n - 2` elements are not disturbed.
Expand All @@ -42,15 +38,6 @@
- [*Heap’s algorithm*](https://en.wikipedia.org/wiki/Heap%27s_algorithm) &ndash; Wikipedia
- [*Heap algorithm for permutations*](https://stackoverflow.com/questions/31425531/heap-algorithm-for-permutations) &ndash; Stack Overflow

### Generating random permutations

#### Fisher&ndash;Yates algorithm

:memo:

- This algorithm is also known as the Knuth shuffle algorithm or algorithm P.

:link:
### Random permutations

- [*Fisher&ndash;Yates shuffle*](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) &ndash; Wikipedia
- [*Knuth shuffle*](https://www.rosettacode.org/wiki/Knuth_shuffle) &ndash; Rosetta Code
See [*Random shuffling* &ndash; Randomized algorithms](random.md#random-shuffling).
47 changes: 47 additions & 0 deletions data_structures_and_algorithms/random.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Randomized algorithms <!-- omit in toc -->

## Table of contents <!-- omit in toc -->

- [Random sampling](#random-sampling)
- [Selection sampling](#selection-sampling)
- [Reservoir sampling](#reservoir-sampling)
- [Random shuffling](#random-shuffling)
- [Fisher&ndash;Yates algorithm](#fisherndashyates-algorithm)

---

## Random sampling

:book:

- Sec. 3.4.2: *Random sampling and shuffling* &ndash; D.E.Knuth. [*The art of computer programming.*](https://www-cs-faculty.stanford.edu/~knuth/taocp.html) *Vol. 2: Seminumerical algorithms* (1997)

### Selection sampling

:link:

- [*Knuth’s algorithm S*](https://rosettacode.org/wiki/Knuth%27s_algorithm_S) &ndash; Rosetta Code
- B.Rieck. [*A technique for selection sampling (sampling without replacement)*](http://bastian.rieck.me/blog/posts/2017/selection_sampling/)

:page_facing_up:

- J.S.Vitter. [*An efficient algorithm for sequential random sampling*](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.94.1689&rep=rep1&type=pdf) &ndash; [ACM Transactions on Mathematical Software **13**, 58](https://doi.org/10.1145/23002.23003) (1987)

### Reservoir sampling

:link:

- [*Reservoir sampling*](https://en.wikipedia.org/wiki/Reservoir_sampling) &ndash; Wikipedia

## Random shuffling

:book:

- Sec. 3.4.2: *Random sampling and shuffling* &ndash; D.E.Knuth. [*The art of computer programming.*](https://www-cs-faculty.stanford.edu/~knuth/taocp.html) *Vol. 2: Seminumerical algorithms* (1997)

### Fisher&ndash;Yates algorithm

:link:

- [*Fisher&ndash;Yates shuffle*](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) &ndash; Wikipedia
- [*Knuth shuffle*](https://www.rosettacode.org/wiki/Knuth_shuffle) &ndash; Rosetta Code

0 comments on commit c087793

Please sign in to comment.