{"id":16693444,"url":"https://github.com/paulross/skiplist","last_synced_at":"2025-04-06T14:11:42.872Z","repository":{"id":57449605,"uuid":"62234099","full_name":"paulross/skiplist","owner":"paulross","description":"A C++ skip list with Python bindings. This can be used to calculate a rolling median - fast!","archived":false,"fork":false,"pushed_at":"2025-02-12T18:37:19.000Z","size":10579,"stargazers_count":48,"open_issues_count":2,"forks_count":8,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-30T13:08:15.491Z","etag":null,"topics":["c-plus-plus","python","python-skiplist","skiplist"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/paulross.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-29T14:52:14.000Z","updated_at":"2025-03-15T10:39:30.000Z","dependencies_parsed_at":"2024-10-12T16:30:43.952Z","dependency_job_id":"572ba4f4-6333-4425-a654-8e18e9f8841e","html_url":"https://github.com/paulross/skiplist","commit_stats":{"total_commits":135,"total_committers":2,"mean_commits":67.5,"dds":"0.059259259259259234","last_synced_commit":"324b5706b1beca589612c1da496ad5c12014686d"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulross%2Fskiplist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulross%2Fskiplist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulross%2Fskiplist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/paulross%2Fskiplist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/paulross","download_url":"https://codeload.github.com/paulross/skiplist/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247492557,"owners_count":20947545,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","python","python-skiplist","skiplist"],"created_at":"2024-10-12T16:30:34.608Z","updated_at":"2025-04-06T14:11:42.849Z","avatar_url":"https://github.com/paulross.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SkipList\n\nThis project contains a SkipList implementation in C++ with Python bindings.\n\nA SkipList behaves as an always sorted list with, typically, O(log(n)) cost for insertion, look-up and removal.\nThis makes it ideal for such operations as computing the rolling median of a large dataset.\n\nSee the full documentation on this project at [ReadTheDocs](http://skiplist.readthedocs.io/en/latest/index.html).\n\nA SkipList is implemented as a singly linked list of ordered nodes where each node participates in a subset of, sparser, linked lists.\nThese additional 'sparse' linked lists provide rapid indexing and mutation of the underlying linked list.\nIt is a probabilistic data structure using a random function to determine how many 'sparse' linked lists any particular node participates in.\nAs such SkipList is an alternative to binary tree, Wikipedia has a introductory page on [SkipLists](\u003chttps://en.wikipedia.org/wiki/Skip_list\u003e).\n\nAn advantage claimed for SkipLists are that the insert and remove logic is simpler (however I do not subscribe to this).\nThe drawbacks of a SkipList include its larger space requirements and its O(log(N)) lookup behaviour compared to other, more restricted and specialised, data structures that may have either faster runtime behaviour or lower space requirements or both.\n\nThis project contains a SkipList implementation in C++ with Python bindings with:\n\n* No capacity restrictions apart from available memory.\n* Works with any C++ type \u003cT\u003e that has meaningful comparison operators.\n* The C++ SkipList can be compiled as thread safe.\n* The Python SkipList is thread safe.\n* The SkipList has exhaustive internal integrity checks.\n* Python SkipLists can be long/float/bytes/object types, the latter can have user defined comparison functions.\n* With Python 3.8+ SkipLists can be combined with the [multiprocessing.shared_memory](https://docs.python.org/3/library/multiprocessing.shared_memory.html#module-multiprocessing.shared_memory) module for concurrent operation on large arrays.\n  For example [concurrent rolling medians](https://skiplist.readthedocs.io/en/latest/rolling_median.html#rolling-median-in-python-with-multiprocessing-shared-memory) which speed up near linearly with the number of cores.\n* The implementation is extensively performance tested in C++ and Python.\n\n\nThere are a some novel features to this implementation:\n\n* A SkipList is a probabilistic data structure but we have deterministic tests that work for any (sane) random number generator. See [Testing a Probabilistic Structure](http://skiplist.readthedocs.io/en/latest/test_notes.html#testing-a-probabilistic-structure)\n* This SkipList can dynamically generate visualisations of its current internal state. See [Visualising a Skip List](http://skiplist.readthedocs.io/en/latest/visualisations.html#skiplist-visualisation-label)\n\n# Credits\n\nOriginally written by Paul Ross with credits to: Wilfred Hughes (AHL), Luke Sewell (AHL) and Terry Tsantagoeds (AHL).\n\n\n# Installation\n\n## C++\n\nThis SkipList requires:\n\n* A C++20 compiler.\n* ``-I\u003cskiplist\u003e/src/cpp`` as an include path.\n* ``\u003cskiplist\u003e/src/cpp/SkipList.cpp`` to be compiled/linked.\n* The macro ``SKIPLIST_THREAD_SUPPORT`` set if you want a thread safe SkipList using C++ mutexes.\n\n## Python\n\nThis SkipList version supports Python 3.8, 3.9, 3.10, 3.11, 3.12, 3.13 (and, probably, some earlier Python 3 versions).\n\n### From PyPi\n\n    $ pip install orderedstructs\n\n### From source\n\n    $ git clone https://github.com/paulross/skiplist.git\n    $ cd \u003cskiplist\u003e\n    $ python setup.py install\n\n\n# Testing\n\n\nThis SkipList has extensive tests for correctness and performance.\n\n## C++\n\nTo run all the C++ functional and performance tests:\n\n    $ cd \u003cskiplist\u003e/src/cpp\n    $ make release\n    $ ./SkipList_R.exe\n\nTo run the C++ functional tests with agressive internal integrity checks:\n\n    $ cd \u003cskiplist\u003e/src/cpp\n    $ make debug\n    $ ./SkipList_D.exe\n\nTo run all the C++ functional and performance tests for a thread safe SkipList:\n\n    $ cd \u003cskiplist\u003e/src/cpp\n    $ make release CXXFLAGS=-DSKIPLIST_THREAD_SUPPORT\n    $ ./SkipList_R.exe\n\n\n## Python\n\nTesting requires ``pytest`` and ``hypothesis``:\n\nTo run all the C++ functional and performance tests:\n\n    $ cd \u003cskiplist\u003e\n    $ py.test -vs tests/\n\n\n# Examples\n\nHere are some examples of using a SkipList in your code:\n\n## C++\n\n\n    #include \"SkipList.h\"\n        \n    // Declare with any type that has sane comparison.\n    OrderedStructs::SkipList::HeadNode\u003cdouble\u003e sl;\n    \n    sl.insert(42.0);\n    sl.insert(21.0);\n    sl.insert(84.0);\n    \n    sl.has(42.0) // true\n    sl.size()    // 3\n    sl.at(1)     // 42.0, throws OrderedStructs::SkipList::IndexError if index out of range\n\n    sl.remove(21.0); // throws OrderedStructs::SkipList::ValueError if value not present\n    \n    sl.size()    // 2\n    sl.at(1)     // 84.0\n\nThe C++ SkipList is thread safe when compiled with the macro ``SKIPLIST_THREAD_SUPPORT``, then a SkipList can then be shared across threads:\n\n    #include \u003cthread\u003e\n    #include \u003cvector\u003e\n    \n    #include \"SkipList.h\"\n\n    void do_something(OrderedStructs::SkipList::HeadNode\u003cdouble\u003e *pSkipList) {\n        // Insert/remove items into *pSkipList\n        // Read items inserted by other threads.\n    }\n\n    OrderedStructs::SkipList::HeadNode\u003cdouble\u003e sl;\n    std::vector\u003cstd::thread\u003e threads;\n\n    for (size_t i = 0; i \u003c thread_count; ++i) {\n        threads.push_back(std::thread(do_something, \u0026sl));\n    }\n    for (auto \u0026t: threads) {\n        t.join();\n    }\n    // The SkipList now contains the totality of the thread actions.\n\n\n## Python\n\nAn example of using a SkipList of always ordered floats:\n\n    import orderedstructs\n    \n    # Declare with a type. Supported types are long/float/bytes/object.\n    sl = orderedstructs.SkipList(float)\n    \n    sl.insert(42.0)\n    sl.insert(21.0)\n    sl.insert(84.0)\n    \n    sl.has(42.0) # True\n    sl.size()    # 3\n    sl.at(1)     # 42.0\n\n    sl.has(42.0) # True\n    sl.size()    # 3\n    sl.at(1)     # 42.0, raises IndexError if index out of range\n\n    sl.remove(21.0); # raises ValueError if value not present\n    \n    sl.size()    # 2\n    sl.at(1)     # 84.0\n\nThe Python SkipList can be used with user defined objects with a user defined sort order.\nIn this example the last name of the person takes precedence over the first name:\n\n    import functools\n    \n    @functools.total_ordering\n    class Person:\n        \"\"\"Simple example of ordering based on last name/first name.\"\"\"\n        def __init__(self, first_name, last_name):\n            self.first_name = first_name\n            self.last_name = last_name\n    \n        def __eq__(self, other):\n            try:\n                return self.last_name == other.last_name and self.first_name == other.first_name\n            except AttributeError:\n                return NotImplemented\n\n        def __lt__(self, other):\n            try:\n                return self.last_name \u003c other.last_name or self.first_name \u003c other.first_name\n            except AttributeError:\n                return NotImplemented\n    \n        def __str__(self):\n            return '{}, {}'.format(self.last_name, self.first_name)\n\n    import orderedstructs\n    \n    sl = orderedstructs.SkipList(object)\n\n    sl.insert(Person('Peter', 'Pan'))\n    sl.insert(Person('Alan', 'Pan'))\n    assert sl.size() == 2\n    assert str(sl.at(0)) == 'Pan, Alan' \n    assert str(sl.at(1)) == 'Pan, Peter' \n\n\nThe Python SkipList is thread safe when using any acceptable Python type even if that type has user defined comparison methods.\nThis uses Pythons mutex machinery which is independent of C++ mutexes.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulross%2Fskiplist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpaulross%2Fskiplist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpaulross%2Fskiplist/lists"}