Search Unity

Will There Ever Be A "dynamichashmap"?

Discussion in 'Entity Component System' started by Abbrew, Apr 11, 2019.

  1. Abbrew

    Abbrew

    Joined:
    Jan 1, 2018
    Posts:
    417
    Right now DynamicBuffer solves the issue of storing multiple of the same component in an entity. However, performing operations on them usually takes O(n) time. A DynamicHashMap would allow constant time manipulation of component data. Understandably it would be hard to implement, but it would be very useful
     
  2. Spy-Shifty

    Spy-Shifty

    Joined:
    May 5, 2011
    Posts:
    546
    Maybe you can write extensions for this by your self.
    Code (CSharp):
    1. static class MyBufferExtension {    
    2.        public static void Add(this DynamicBuffer<T> buffer, T Value)  where T : struct, IBufferElementData, IHashable {
    3.                  int hash = T.GetHashSomeHash();
    4.                  // do quicksearch by hash
    5.                  // do some insert              
    6.         }
    7. }
    You can also use custom item container or what ever.
    Code (CSharp):
    1.  
    2. struct HashItem<T> : IBufferElementData where T : struct {
    3.      public int Hash;
    4.      public T Value;
    5. }
    6. static class MyBufferExtension {  
    7.        public static void Add(this DynamicBuffer<HashItem<T>> buffer, T Value)  where T : struct {
    8.                  int hash = T.GetHashSomeHash();
    9.                  // do quicksearch by hash
    10.                  // do some insert              
    11.         }
    12. }
    Anyway yes you are right. It would be nice to have something like that.
     
    Abbrew likes this.