File indexing completed on 2022-09-27 12:25:39

0001 /*
0002     This file is part of Kiten, a KDE Japanese Reference Tool
0003     SPDX-FileCopyrightText: 2006 Joseph Kerian <jkerian@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #include <tuple>
0009 
0010 #include "radical.h"
0011 
0012 Radical::Radical()
0013 : strokeCount( 0 )
0014 {
0015 }
0016 
0017 Radical::Radical( const QString &irad, unsigned int strokes, unsigned int index )
0018 : string( irad.at( 0 ) )
0019 , strokeCount( strokes )
0020 , idx( index )
0021 {
0022 }
0023 
0024 QString Radical::toString() const
0025 {
0026   return string;
0027 }
0028 
0029 void Radical::addKanji( const QSet<QString> &newKanji )
0030 {
0031   kanji += newKanji;
0032 }
0033 
0034 const QSet<QString>& Radical::getKanji() const
0035 {
0036   return kanji;
0037 }
0038 
0039 unsigned int Radical::strokes() const
0040 {
0041   return strokeCount;
0042 }
0043 
0044 bool Radical::compareIndices( const Radical &a, const Radical &b )
0045 {
0046   return a.idx < b.idx;
0047 }
0048 
0049 bool Radical::compareFrequencies( const Radical &a, const Radical &b )
0050 {
0051   // Negative frequency results in a descending order
0052   return std::make_tuple( - a.getKanji().size(), a.idx ) <
0053          std::make_tuple( - b.getKanji().size(), b.idx );
0054 }