File indexing completed on 2024-04-28 15:39:56
0001 // SPDX-FileCopyrightText: 2003 - 2012 Jesper K. Pedersen <blackie@kde.org> 0002 // SPDX-FileCopyrightText: 2005, 2007 Dirk Mueller <mueller@kde.org> 0003 // SPDX-FileCopyrightText: 2007 Laurent Montel <montel@kde.org> 0004 // SPDX-FileCopyrightText: 2008 Henner Zeller <h.zeller@acm.org> 0005 // SPDX-FileCopyrightText: 2008, 2010 Tuomas Suutari <tuomas@nepnep.net> 0006 // SPDX-FileCopyrightText: 2013 Dominik Broj <broj.dominik@gmail.com> 0007 // SPDX-FileCopyrightText: 2020 Robert Krawitz <rlk@alum.mit.edu> 0008 // SPDX-FileCopyrightText: 2013 - 2023 Johannes Zarl-Zierl <johannes@zarl-zierl.at> 0009 // 0010 // SPDX-License-Identifier: GPL-2.0-or-later 0011 0012 #ifndef IMAGEDATECOLLECTION_H 0013 #define IMAGEDATECOLLECTION_H 0014 #include "ImageDate.h" 0015 0016 #include <QExplicitlySharedDataPointer> 0017 #include <qmap.h> 0018 namespace DB 0019 { 0020 class ImageInfoList; 0021 0022 /** 0023 * @brief The ImageCount struct represents a count of exact and range matches. 0024 */ 0025 struct ImageCount { 0026 ImageCount(int exact, int rangeMatch) 0027 : mp_exact(exact) 0028 , mp_rangeMatch(rangeMatch) 0029 { 0030 } 0031 ImageCount() 0032 : mp_exact(0) 0033 , mp_rangeMatch(0) 0034 { 0035 } 0036 0037 /** 0038 * @brief mp_exact counts images which were contained in the queried date range. 0039 */ 0040 int mp_exact; 0041 /** 0042 * @brief mp_rangeMatch counts images which have a fuzzy date which overlaps with the queried date range. 0043 */ 0044 int mp_rangeMatch; 0045 }; 0046 0047 /** 0048 * @brief The ImageDateCollection class implements an efficient way to the images in a given set that fall withing a given date range. 0049 * The class is optimized for repeated queries on the same set of images but for a different date range (as is required for building a histogram like the one in the DateBar). 0050 * 0051 */ 0052 class ImageDateCollection : public QSharedData 0053 { 0054 public: 0055 /** 0056 * @brief ImageDateCollection constructs an ImageDateCollection for the given image list. 0057 * @param list 0058 */ 0059 explicit ImageDateCollection(const DB::ImageInfoList &list); 0060 /** 0061 * @brief count all images in the collection that match the given ImageDate. 0062 * Usually, the ImageDate is a fuzzy date defining a date range. 0063 * @param range 0064 * @return a count of exact and range matches 0065 */ 0066 ImageCount count(const ImageDate &range); 0067 /** 0068 * @brief lowerLimit 0069 * @return the date/tme of the earliest starting image in the ImageDateCollection, ignoring null dates. 0070 */ 0071 Utilities::FastDateTime lowerLimit() const; 0072 /** 0073 * @brief upperLimit 0074 * @return the date/time of the latest ending image in the ImageDateCollection, ignoring null dates 0075 */ 0076 Utilities::FastDateTime upperLimit() const; 0077 0078 private: 0079 typedef QMultiMap<Utilities::FastDateTime, DB::ImageDate> StartIndexMap; 0080 typedef QMap<Utilities::FastDateTime, StartIndexMap::ConstIterator> EndIndexMap; 0081 0082 // Build index, after all elements have been added. 0083 void buildIndex(); 0084 0085 // Cache for past successful range lookups. 0086 QMap<DB::ImageDate, DB::ImageCount> m_cache; 0087 0088 // Elements ordered by start time. 0089 // 0090 // Start index is sorted by start time of the ImageDate, mapping 0091 // to the actual ImageDate; this is a multimap. 0092 StartIndexMap m_startIndex; 0093 0094 // Pointers to start index ordered by end time. 0095 // 0096 // This maps the end date to an iterator into the startIndex. The 0097 // iterator points to the lowest element in startIndex whose end-time 0098 // is greater or equal to the key-time. Thus is points to the start 0099 // where its worth looking. 0100 EndIndexMap m_endIndex; 0101 }; 0102 0103 } 0104 0105 #endif /* IMAGEDATECOLLECTION_H */ 0106 0107 // vi:expandtab:tabstop=4 shiftwidth=4: