Exemplo n.º 1
0
        /// <summary>
        /// Finds all entries by specified field.
        /// </summary>
        public DatabaseQuery <T> Find <K>(string field)
        {
            // Ignore find if required.
            if (ShouldIgnore)
            {
                return(this);
            }

            // Find the index tree
            IndexTree <K, uint> index = indexUtils.GetNormalIndex <K>(field);

            if (index != null)
            {
                // Enumerate through all keys
                foreach (var entry in index.GetAll(isAscending))
                {
                    // Add indexes to temp list.
                    tempIndexes.Add(entry.Item2);
                }

                // Intersect indexes
                IntersectIndexes();
            }

            return(this);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Creates a new unique index tree for Guid.
 /// </summary>
 public void CreateUniqueIndex()
 {
     uniqueIndexStream = database.GetNewIndexStream("_id");
     UniqueIndex       = new IndexTree <Guid, uint>(
         database.GetNewNodeManager(
             new GuidSerializer(),
             new UintSerializer(),
             new RecordStorage(new BlockStorage(uniqueIndexStream)),
             256
             )
         );
 }
Exemplo n.º 3
0
        /// <summary>
        /// Finds entries with exact field data.
        /// </summary>
        public DatabaseQuery <T> Find <K>(string field, K key)
        {
            // Ignore find if required.
            if (ShouldIgnore)
            {
                return(this);
            }

            // Find the index tree
            IndexTree <K, uint> index = indexUtils.GetNormalIndex <K>(field);

            if (index != null)
            {
                // Get comparer
                var comparer = Comparer <K> .Default;

                // Enumerate through matched entries
                foreach (var entry in index.GetExactMatch(key, isAscending))
                {
                    // If not matching key, finish immediately
                    int compare = comparer.Compare(entry.Item1, key);
                    if (compare != 0)
                    {
                        break;
                    }

                    // Add indexes to temp list.
                    tempIndexes.Add(entry.Item2);
                }

                // Intersect indexes
                IntersectIndexes();
            }

            return(this);
        }