Git Product home page Git Product logo

indexedcollection's Introduction

Indexed Collection

Indexed collection is an extended version of dictionary collection for cases where Dictionary is not enough and full fledged database is too much.
Indexed collection allows you to create one-to-one and one-to-many indexes with a o(1) retrival and forcibly or lazyly rebuild indexes.

Available indexes:

Type Description
Index By Key Groups all values by key retrieved by a selector
Index One To One Creates dictionary where every value has a unique calculated key retrieved by selector
Index By Type Lazily creates indexes for the whole type hierarchy of values
class Dispatcher
{
	private readonly IndexedCollection<Subscription> _untargetedSubscriptions = new();
	
	private IndexedCollection<Subscription>.IndexByKey<IListener> _untargetedByListener;
	private IndexedCollection<Subscription>.IndexByType           _untargetedByForType;

    public Dispatcher()
    {
        _untargetedByListener = _untargetedSubscriptions.CreateIndexByKey(p => p.ListenerContext.Listener);
        _untargetedByForType = _untargetedSubscriptions.CreateIndexByType(p => p.ForType);
    }
	
	public void AddSubscription(Subscription subscription)
    {
        _untargetedSubscriptions.Add(subscription);
    }
		
	public void InjectSubscriptions(IEntity entity)
    {
        foreach(var entry in _untargetedByForType.Get(entity.GetType()))
        {
            AddSubscriptions(entity, entry.Item);
        }
    }
	
	internal void RemoveListener(IListener listener)
    {
        _untargetedByListener.RemoveByKey(listener);
    }
}

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.