GithubHelp home page GithubHelp logo

andriiklymchuk / lexorank_ex Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fastindian84/lexorank_ex

1.0 0.0 0.0 29 KB

LexoRank on Elixir. An implementation of a list ordering system.

Elixir 100.00%

lexorank_ex's Introduction

LexorankEx

Module Version Hex Docs

LexoRank on Elixir. An implementation of a list ordering system.

The base62: (0-9A-Za-z) pre-generated symbol table are used where minimum value is 0 and maximum value is z

Installation

The package can be installed by adding lexorank_ex to your list of dependencies in mix.exs:

def deps do
  [
    {:lexorank_ex, "~> 0.1.5"}
  ]
end

Usage

# Generates middle string between max and min value for provided division

divison = 8
LexorankEx.middle(divison) => "Uzzzzzzz"

# Default step is 8

# Finds next, lexically greater value:

LexorankEx.next("00000") == "00008"
LexorankEx.next("00000", 1) == "00001"

LexorankEx.next("a") == "i"
LexorankEx.next("a", 1) == "b"

# Finds previous, lexically lesser value:

LexorankEx.prev("00008") == "00000"
LexorankEx.prev("00008", 1) == "00007"

LexorankEx.prev("i") == "a"
LexorankEx.prev("b", 1) == "a"

# Finds middle point between maximum and minimum value. Order doesn't matter:
LexorankEx.between("a", "b") == "aV"
LexorankEx.between("a", "c") == "b"
LexorankEx.between("aaaaz", "zzzzz") == "nIIIU"


# Finds the distance between two values

LexorankEx.distance("V0000007", "V000000F") == 8
LexorankEx.distance("00", "zz") == 3843
LexorankEx.distance("aa", "bb") == 63
LexorankEx.distance("00", "010") == 62
LexorankEx.distance("a0", "b") == 62
LexorankEx.distance("a0", "b1") == 63
LexorankEx.distance("a", "b") == 1

Buckets

Usually all ranks are unique. But if you need to rebalance your set, Buckets will help you. Bucket API is the same, but for all generated ranks it will add bucket prefix.

alias LexorankEx.Bucket

Bucket.middle(8) == "1|Uzzzzzzz"
Bucket.next("1|a") == "1|i"
Bucket.next("1|00000") == "1|00008"
Bucket.prev("3|b0007") == "3|azzzz"
Bucket.between("2|aaaaz", "2|zzzzz") == "2|nIIIT"
Bucket.distance("1|00", "1|010") == 62

Bucket.new("1|00000") == "2|00000"
Bucket.new("2|00000") == "3|00000"
Bucket.new("3|00000") == "1|00000"

Bucket.new("3|00000", :middle) == "1|Uzzzzzzz"

References

Thanks to the mudderjs and its explanation of the algorithm

lexorank_ex's People

Contributors

fastindian84 avatar andriiklymchuk avatar

Stargazers

Andrea Azzini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.