Coder Social home page Coder Social logo

pluscollections's Introduction

+Collections

+Collections is a set of extra data structures and functions to support edge cases that are not well covered by the standard collections.

Table - Order-preserving bidirectional multi-key map

Table is an implementation of a multiple-key bidirectional map. Unlike Dictionary and other traditional key-value maps, Table links two or more keys together. Groups of related keys are inserted as a "row" that can accessed by any key. Insertion order is preserved and respected for all key columns. Overloaded, generic implementations exist for 2, 3, 4, 5, and 6 key tables. More keys can be trivially added, but single-key tables are not supported (just use an ordered set).

Performance

  • Table operates in constant time (except for iteration), but constant overhead scales linearly based on the number of keys per row. For example, Table<Key1, Key2>.Add() will require a bit more than twice as much time as Dictionary<Key, Value>.Add(). Table<Key1, Key2, Key3>.Add() will take three times as long, and so on.
  • Insert / Delete complexity - O(K) where K is the number of keys supported by the implementation.
  • Update complexity - O(K^2) where K is the number of keys supported by the implementation. In cases where only one key is changed, complexity returns to O(K).
  • Lookup complexity - O(1) (equal to Dictionary[key])
  • Iteration complexity - O(n) (equal to walking a linked list)

Implementations

Namespace Class Description
PlusCollections.Table Table<TKey1, TKey2> Two-key implementation
PlusCollections.Table Table<TKey1, TKey2, TKey3> Three-key implementation
PlusCollections.Table Table<TKey1, TKey2, TKey3, TKey4> Four-key implementation
PlusCollections.Table Table<TKey1, TKey2, TKey3, TKey4, TKey5> Five-key implementation
PlusCollections.Table Table<TKey1, TKey2, TKey3, TKey4, TKey5, TKey6> Six-key implementation

MaxOrDefault - Max() with support for empty collections

EnumerableExtensions implements a new version of IEnumerable<T>.Max that does not throw if the collection is empty. Instead, it returns the element type's default value or a user-provided placeholder.

Overloads:

  • EnumerableExtensions.MaxOrDefault<TIn, TOut>(enumerable, def, callback) - If the stream is empty, then returns def. Otherwise, passes callback to the standard implementation of IEnumerable.Max and returns the result.
  • EnumerableExtensions.MaxOrDefault<T>(enumerable, def) - If the stream is empty, then returns def. Otherwise calls the default implementation of IEnumerable.Max.
  • EnumerableExtensions.MaxOrDefault<TIn, TOut>(enumerable, callback) - If the steam is empty, then returns default(TOut). Otherwise passes callback to IEnumerable.Max.
  • EnumerableExtensions.MaxOrDefault<T>(enumerable) - If the stream is empty, the returns default(T). Otherwise calls the default implementation of IEnumerable.Max.

ListExtensions - Additional variations of Contains()

ListExtensions implements new variations of IList<T>.Contains that assert not only inclusion, but also position within the list. Four methods are available:

  • ListExtensions.ContainsFirst(list, target) - returns true only if target is the first item in list.
  • ListExtensions.ContainsLast(list, target) - returns true only if target is the last item in list.
  • ListExtensions.ContainsNotFirst(list, target) - return true only if target is in list but is not the first item.
  • ListExtensions.ContainsNotLast(list, target) - returns true only if target is in list but is not the last item.

pluscollections's People

Contributors

warriordog avatar

Stargazers

Soar avatar

Watchers

James Cloos avatar  avatar  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.