Skip to content

Commit

Permalink
Restructure package (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen Engels <[email protected]>
  • Loading branch information
amitaibu and jfmengels authored Apr 26, 2022
1 parent 46f0fb2 commit c73bbfb
Show file tree
Hide file tree
Showing 11 changed files with 2,648 additions and 295 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
tests/VerifyExamples
elm-stuff/
.idea
.idea
node_modules
28 changes: 4 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,8 @@
language: elm
elm: 0.19.0
elm-test: 0.19.0-rev6
elm-format: 0.8.3
node_js: '10' # latest 10.x

os:
- linux

env:
- PATH=$TRAVIS_BUILD_DIR/node_modules/.bin:$TRAVIS_BUILD_DIR/sysconfcpus/bin:$PATH

cache:
directories:
- sysconfcpus

before_install:
- echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
language: node_js
node_js: 17

install:
- node --version
- npm --version
- npm install -g [email protected]
- npm install

script:
- elm-format --validate src
- elm make
- ./execute-tests
- npm test
90 changes: 86 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,78 @@

# Radix tree

Read more about the use cases in the package's docs.
Radix tree is defined in Wikipedia: <https://en.wikipedia.org/wiki/Radix_tree>

A data structure that represents a space-optimized trie (prefix tree) in which
each node that is the only child is merged with its parent.

Under the hood, the Tree structure is managed with
[elm-rosetree](https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/)

In this package we have two kinds of implementations, one is ordered and the
other is unordered. It's possible that the unordered isn't called "Radix tree"
but the author of the package doesn't know of a better name.

It would be easier to follow by example, or try it on a helpful app like
this one: <https://www.cs.usfca.edu/~galles/visualization/RadixTree.html>

## Ordered Radix Tree

Say we have the following list of chars:

```elm
[ [ "r", "o", "m", "a", "n", "e" ]
, [ "r", "o", "m", "u", "l", "u", "s" ]
, [ "r", "u", "b", "e", "n", "s" ]
, [ "r", "u", "b", "e", "r" ]
, [ "r", "u", "b", "i", "c", "o", "n" ]
, [ "r", "u", "b", "i", "c", "u", "n", "d", "u", "s" ]
]
```

We would like to represent this as a Radix tree where letters that repeat are
in parent nodes, and the rest are in child nodes.

It would look like this:

- r
- ub
- ic
- undus
- on
- e
- r
- ns
- om
- ulus
- ane

This package allows inserting values to the tree in an Ordered and Un-ordered manner.
The ordered one is presented above. The "order" is in relation to the position of each
letter. That is, when we look for the letter "r" that is the beginning of the list,
on an Ordered list, we match it only to other "r" letters that are also at the beginning.

## Un-Ordered Radix Tree

An Un-ordered insert on the other hand doesn't care about the position of the chars, but rather if they exist or not.

Here's an example of how an unordered insert would result, assuming we have this list
of Int.

```elm
[ [ 1, 2, 3 ]
, [ 2, 1, 4 ]
, [ 4, 5, 6 ]
]
```

This will result with:

- 1, 2
- 3
- 4
- 5
- 6

## Example

Expand All @@ -13,9 +84,20 @@ You can see the package in action with the example provided

Then navigate to http://localhost:8000/example/src/Example.elm

## Tests
## Tests & Code Quality

npm install
npm test

This will execute:

1. [Elm verify examples](https://github.com/stoeffel/elm-verify-examples) and [Elm test](https://github.com/elm-explorations/test)
2. Validate `elm-format`
3. Analyze with `elm-review`

Executes [Elm verify examples](https://github.com/stoeffel/elm-verify-examples) and [Elm test](https://github.com/elm-explorations/test)
## Related Packages

./execute-tests
- [elm-tries](https://package.elm-lang.org/packages/elm-scotland/elm-tries/latest) -
The reason we have this package is for being able to have unordered Radix trees as-well,
and for being able to work with the very handy [elm-rosetree](https://package.elm-lang.org/packages/zwilias/elm-rosetree/latest/)
Tree's API.
3 changes: 2 additions & 1 deletion elm.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"license": "BSD-3-Clause",
"version": "1.0.1",
"exposed-modules": [
"RadixTree"
"RadixTree",
"UnorderedRadixTree"
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
Expand Down
Loading

0 comments on commit c73bbfb

Please sign in to comment.