<commit_before>using System;
using System.Collections.Generic;
using Svelto.DataStructures;

namespace Svelto.ECS.Internal
{
    class EntityViewsDB : IEntityViewsDB
    {
        internal EntityViewsDB(  Dictionary<Type, ITypeSafeList> entityViewsDB,
                                 Dictionary<Type, ITypeSafeList> metaEntityViewsDB,
                                Dictionary<Type, ITypeSafeDictionary> entityViewsDBdic,
                                 Dictionary<Type, ITypeSafeDictionary> metaEntityViewsDBdic,
                                Dictionary<int, Dictionary<Type, ITypeSafeList>>  groupEntityViewsDB)
        {
            _entityViewsDB = entityViewsDB;
            _metaEntityViewsDB = metaEntityViewsDB;
            
            _entityViewsDBdic = entityViewsDBdic;
            _metaEntityViewsDBdic = metaEntityViewsDBdic;
            
            _groupEntityViewsDB = groupEntityViewsDB;
        }

        public FasterReadOnlyList<T> QueryEntityViews<T>() where T:EntityView
        {
            var type = typeof(T);

            ITypeSafeList entityViews;

            if (_entityViewsDB.TryGetValue(type, out entityViews) == false)
                return RetrieveEmptyEntityViewList<T>();

            return new FasterReadOnlyList<T>((FasterList<T>)entityViews);
        }

        public FasterReadOnlyList<T> QueryGroupedEntityViews<T>(int @group) where T:EntityView
        {
            Dictionary<Type, ITypeSafeList> entitiesInGroupPerType;

            if (_groupEntityViewsDB.TryGetValue(group, out entitiesInGroupPerType) == false)
                return RetrieveEmptyEntityViewList<T>();
            
            return new FasterReadOnlyList<T>((FasterList<T>) entitiesInGroupPerType[typeof(T)]);
        }

        public T[] QueryEntityViewsAsArray<T>(out int count) where T : IEntityView
        {
            var type = typeof(T);
            count = 0;
            
            ITypeSafeList entityViews;

            if (_entityViewsDB.TryGetValue(type, out entityViews) == false)
                return RetrieveEmptyEntityViewArray<T>();
            
            return FasterList<T>.NoVirt.ToArrayFast((FasterList<T>)entityViews, out count);<commit_msg>fixed wrong code behaviour<commit_after>using System;
using System.Collections.Generic;
using Svelto.DataStructures;

namespace Svelto.ECS.Internal
{
    class EntityViewsDB : IEntityViewsDB
    {
        internal EntityViewsDB(  Dictionary<Type, ITypeSafeList> entityViewsDB,
                                 Dictionary<Type, ITypeSafeList> metaEntityViewsDB,
                                Dictionary<Type, ITypeSafeDictionary> entityViewsDBdic,
                                 Dictionary<Type, ITypeSafeDictionary> metaEntityViewsDBdic,
                                Dictionary<int, Dictionary<Type, ITypeSafeList>>  groupEntityViewsDB)
        {
            _entityViewsDB = entityViewsDB;
            _metaEntityViewsDB = metaEntityViewsDB;
            
            _entityViewsDBdic = entityViewsDBdic;
            _metaEntityViewsDBdic = metaEntityViewsDBdic;
            
            _groupEntityViewsDB = groupEntityViewsDB;
        }

        public FasterReadOnlyList<T> QueryEntityViews<T>() where T:EntityView
        {
            var type = typeof(T);

            ITypeSafeList entityViews;

            if (_entityViewsDB.TryGetValue(type, out entityViews) == false)
                return RetrieveEmptyEntityViewList<T>();

            return new FasterReadOnlyList<T>((FasterList<T>)entityViews);
        }

        public FasterReadOnlyList<T> QueryGroupedEntityViews<T>(int @group) where T:EntityView
        {
            Dictionary<Type, ITypeSafeList> entitiesInGroupPerType;

            if (_groupEntityViewsDB.TryGetValue(group, out entitiesInGroupPerType) == false)
                return RetrieveEmptyEntityViewList<T>();

            ITypeSafeList outList;
            if (entitiesInGroupPerType.TryGetValue(typeof(T), out outList) == false)
                return RetrieveEmptyEntityViewList<T>();
            
            return new FasterReadOnlyList<T>((FasterList<T>) outList);
        }

        public T[] QueryEntityViewsAsArray<T>(out int count) where T : IEntityView
        {
            var type = typeof(T);
            count = 0;
            
            ITypeSafeList entityViews;

            if (_entityViewsDB.TryGetValue(type, out entityViews) == false)
                return RetrieveEmptyEntityViewArray<T>();
            
            return FasterList<T>.NoVirt.ToArrayFast((FasterList<T>)entityViews, out count);
{'fraction_non_alphanumeric': 0.07522414170129019, 'fraction_numerical': 0.0004373496610540127, 'mean_word_length': 2.1852367688022283, 'pattern_counts': {'":': 0, '<': 46, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4638031', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1180, 'n_words': 221}