2 using System.Collections.Generic;
8 readonly Dictionary<TKey, TEntity> _index;
11 _index =
new Dictionary<TKey, TEntity>();
16 _index =
new Dictionary<TKey, TEntity>();
20 public PrimaryEntityIndex(
string name,
IGroup<TEntity> group, Func<TEntity, IComponent, TKey> getKey, IEqualityComparer<TKey> comparer) : base(name, group, getKey) {
21 _index =
new Dictionary<TKey, TEntity>(comparer);
26 _index =
new Dictionary<TKey, TEntity>(comparer);
30 public override void Activate() {
32 indexEntities(_group);
35 public TEntity GetEntity(TKey key) {
37 _index.TryGetValue(key, out entity);
41 public override string ToString() {
42 return "PrimaryEntityIndex(" + name +
")";
45 protected override void clear() {
46 foreach(var entity
in _index.Values) {
48 #if ENTITAS_FAST_AND_UNSAFE 51 if(entity.owners.Contains(
this)) {
60 protected override void addEntity(TKey key, TEntity entity) {
61 if(_index.ContainsKey(key)) {
63 "Entity for key '" + key +
"' already exists!",
64 "Only one entity for a primary key is allowed.");
67 _index.Add(key, entity);
69 #if ENTITAS_FAST_AND_UNSAFE 72 if(!entity.owners.Contains(
this)) {
78 protected override void removeEntity(TKey key, TEntity entity) {
81 #if ENTITAS_FAST_AND_UNSAFE 84 if(entity.owners.Contains(
this)) {