/// <summary>
 /// Gets the pages that may have catalog leaves within the provided commit timestamp bounds. The result is
 /// sorted by commit timestamp.
 /// </summary>
 /// <param name="catalogIndex">The catalog index to fetch pages from.</param>
 /// <param name="minCommitTimestamp">The exclusive lower time bound on <see cref="CatalogPageItem.CommitTimestamp"/>.</param>
 /// <param name="maxCommitTimestamp">The inclusive upper time bound on <see cref="CatalogPageItem.CommitTimestamp"/>.</param>
 public static List <CatalogPageItem> GetPagesInBounds(
     this CatalogIndex catalogIndex,
     DateTimeOffset minCommitTimestamp,
     DateTimeOffset maxCommitTimestamp)
 {
     return(catalogIndex
            .GetPagesInBoundsLazy(minCommitTimestamp, maxCommitTimestamp)
            .ToList());
 }
        private static IEnumerable <CatalogPageItem> GetPagesInBoundsLazy(
            this CatalogIndex catalogIndex,
            DateTimeOffset minCommitTimestamp,
            DateTimeOffset maxCommitTimestamp)
        {
            // Filter out pages that fall entirely before the minimum commit timestamp and sort the remaining pages by
            // commit timestamp.
            var upperRange = catalogIndex
                             .Items
                             .Where(x => x.CommitTimestamp > minCommitTimestamp)
                             .OrderBy(x => x.CommitTimestamp);

            // Take pages from the sorted list until the commit timestamp goes past the maximum commit timestamp. This
            // essentially LINQ's TakeWhile plus one more element.
            foreach (var page in upperRange)
            {
                yield return(page);

                if (page.CommitTimestamp > maxCommitTimestamp)
                {
                    break;
                }
            }
        }