All Projects → helins → rktree.cljc

helins / rktree.cljc

Licence: MPL-2.0 License
Trees where leaves are located both in time and space

Programming Languages

clojure
4091 projects
shell
77523 projects
HTML
75241 projects

Projects that are alternatives of or similar to rktree.cljc

array-sort-by
Powerful mechanism to sort arrays or array of objects by one or more properties. You can also specify a custom comparer function.
Stars: ✭ 37 (+146.67%)
Mutual labels:  ordering
TASNET
Time-domain Audio Separation Network (IN PYTORCH)
Stars: ✭ 18 (+20%)
Mutual labels:  time
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (+93.33%)
Mutual labels:  time
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (+573.33%)
Mutual labels:  time
react-time-ago
Localized relative date/time formatting in React
Stars: ✭ 88 (+486.67%)
Mutual labels:  time
type-comparator
Useful comparator functions written on Typescript
Stars: ✭ 56 (+273.33%)
Mutual labels:  ordering
akka-mock-scheduler
A mock Akka scheduler to simplify testing scheduler-dependent code
Stars: ✭ 86 (+473.33%)
Mutual labels:  time
kick-off-web-scraping-python-selenium-beautifulsoup
A tutorial-based introduction to web scraping with Python.
Stars: ✭ 18 (+20%)
Mutual labels:  time
hast-util-reading-time
utility to estimate the reading time
Stars: ✭ 55 (+266.67%)
Mutual labels:  time
priora
An Object Prioritization Utility for Ruby
Stars: ✭ 30 (+100%)
Mutual labels:  prioritization
timezz
With this plugin, you can easily make a stopwatch or timer on your site. Just init, style and enjoy.
Stars: ✭ 35 (+133.33%)
Mutual labels:  time
ad-alexatalkingclock
Alexa (or other Smart Speakers) tell you the time without asking every hour. Please ⭐️if you like my app :)
Stars: ✭ 30 (+100%)
Mutual labels:  time
tm
timers and timeline
Stars: ✭ 31 (+106.67%)
Mutual labels:  time
oncoEnrichR
Cancer-dedicated gene set interpretation
Stars: ✭ 35 (+133.33%)
Mutual labels:  prioritization
cftime
Time-handling functionality from netcdf4-python.
Stars: ✭ 53 (+253.33%)
Mutual labels:  time
Shell-Scripts
Shell scripts about some basic topics, current time, calculator, sorting, restaurant and more.
Stars: ✭ 100 (+566.67%)
Mutual labels:  time
react-picky-date-time
A react component for date time picker. Online demo examples
Stars: ✭ 41 (+173.33%)
Mutual labels:  time
time-api
Nodejs API for Wobbly Time Tracker for the Teams
Stars: ✭ 24 (+60%)
Mutual labels:  time
JqueryDataTablesServerSideDemo
Jquery DataTables with Asp.Net Core server side multi column sorting and searching Demo Project.
Stars: ✭ 43 (+186.67%)
Mutual labels:  ordering
canon-generator
Create and visualize temporal canons a'la Conlon Nancarrow
Stars: ✭ 31 (+106.67%)
Mutual labels:  time

Ranked trees

Clojars Project

cljdoc badge

CircleCI

Compatible with Clojurescript.

Feel free to clone this repo, the examples below located are in the dvlopt.rktree.example namespace. See the "Development" section at the end of this document.

Usage

A ranked tree is a peculiar but interesting data structure. It is a form of nested maps where leaves are located both in time and space. It comes in handy for problems that needs some form of prioritization.

More specifically, it is a complex of nested maps where former levels are sorted and latter levels are unsorted.

Following this definition, the following qualifies as a ranked tree:

(def my-tree
     (sorted-map 0 (sorted-map 1 {:a {:b 'leaf-1}})
                 5 {:a {:d {:e 'leaf-2}}}))

Each leaf has two paths, one "horizontal" and one "vertical" (borrowing vocabulary from the litterature). We shall rather talk (respectively) about ranks providing a notion of time and a path providing a notion of space.

Thus, 'leaf-1 is said to be located at [:a :b] and ranked at [0 1]. Similarly, 'leaf-2 is said to be located at [:c :d :e] and ranked at [5]. We specify both the ranks and the path when we want to get something out of this tree:

(require '[dvlopt.rktree :as rktree])

(= 'leaf-1
   (rktree/get my-tree
               [0 1]
               [:a :b]))

Ranks provid prioritization, a lower rank meaning a higher priority, 0 being the highest priority. When we pop the tree, we receive whatever resides at the ranks with the highest priority. More precisely, we receive [popped-tree ranks unsorted-node]:

(= (rktree/pop my-tree)

   [(sorted-map 5 {:a {:d {:e 'leaf-2}}})
    [0 1]
    {:a {:b 'leaf-1}}])

Interestingly, as you might have noticed, different leaves can have ranks of different length. This library handles that automagically. Remember we already have 'leaf-1 located at [:a :b] and ranked at [0 1]. What if we assoc something past those ranks?

(def my-tree-2
     (rktree/assoc my-tree
                   [0 1 0 0 0 5]
                   [:possible?]
                   true))

;; Notice that 'leaf has been re-prioritized from [0 1] to [0 1 0 0 0 0].
;; Order is actually maintained as before, but we can account for the new
;; addition above.

(= 'leaf-1
   (rktree/get my-tree-2
               [0 1 0 0 0 0]
               [:a :b]))

;; But notice that we can still use the original ranks!

(= 'leaf-1
   (rktree/get my-tree-2
               [0 1]
               [:a :b]))

We have discovered a few recognizable functions such as assoc and get. The API provide other ones (dissoc, update, and friends), all acting on this idea of having ranks and a path.

Serialization

Some serializers make a distinction between sorted maps and unsorted ones. For instance, Nippy does.

But Transit does not.

The user can add the following dependency along side Transit-clj or Transit-cljs:

Clojars Project

This package provides a read handler and a write handler for sorted maps:

(require '[dvlopt.rktree.transit :as rktree.transit])

rktree.transit/read-handler

rktree.transit/write-handler

Running tests

On the JVM, using Kaocha:

$ ./bin/test/jvm/run
$ ./bin/test/jvm/watch

On NodeJS, using Kaocha-CLJS:

$ ./bin/test/node/run
$ ./bin/test/node/watch

In the browser, using Chui:

$ ./bin/test/browser/compile
# Then open ./resources/chui/index.html

# For testing an advanced build
$ ./bin/test/browser/advanced

Development

Starting in Clojure JVM mode, mentioning an additional deps alias (here, a local setup of NREPL):

$ ./bin/dev/clojure :nrepl

Starting in CLJS mode using Shadow-CLJS:

$ ./bin/dev/cljs
# Then open ./resources/public/index.html

License

Copyright © 2020 Adam Helinski

Licensed under the term of the Mozilla Public License 2.0, see LICENSE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].