Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix qHash definitions #2762

Merged
merged 7 commits into from
May 16, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add optional seed = 0 parameter to qHash functions
uklotzde committed May 13, 2020
commit 2feedb2d1b438ecf1fe9b28465d738c72cf71d06
6 changes: 4 additions & 2 deletions src/effects/defs.h
Original file line number Diff line number Diff line change
@@ -22,8 +22,10 @@ enum class SignalProcessingStage {
Postfader
};

inline uint qHash(SignalProcessingStage stage) {
return static_cast<uint>(stage);
inline uint qHash(
SignalProcessingStage stage,
uint seed = 0) {
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
return qHash(static_cast<uint>(stage), seed);
};

enum class EffectChainMixMode {
12 changes: 8 additions & 4 deletions src/engine/channelhandle.h
Original file line number Diff line number Diff line change
@@ -66,8 +66,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandle& h) {
return stream;
}

inline uint qHash(const ChannelHandle& handle) {
return qHash(handle.handle());
inline uint qHash(
const ChannelHandle& handle,
uint seed = 0) {
return qHash(handle.handle(), seed);
}

// Convenience class that mimics QPair<ChannelHandle, QString> except with
@@ -104,8 +106,10 @@ inline QDebug operator<<(QDebug stream, const ChannelHandleAndGroup& g) {
return stream;
}

inline uint qHash(const ChannelHandleAndGroup& handle_group) {
return qHash(handle_group.handle());
inline uint qHash(
const ChannelHandleAndGroup& handle_group,
uint seed = 0) {
return qHash(handle_group.handle(), seed);
}

// A helper class used by EngineMaster to assign ChannelHandles to channel group
13 changes: 9 additions & 4 deletions src/preferences/configobject.h
Original file line number Diff line number Diff line change
@@ -64,8 +64,11 @@ inline QDebug operator<<(QDebug stream, const ConfigKey& configKey) {
}

// QHash hash function for ConfigKey objects.
inline uint qHash(const ConfigKey& key) {
return qHash(key.group) ^ qHash(key.item);
inline uint qHash(
const ConfigKey& key,
uint seed = 0) {
return qHash(key.group, seed) ^
qHash(key.item, seed);
}

// The value corresponding to a key. The basic value is a string, but can be
@@ -97,8 +100,10 @@ inline bool operator!=(const ConfigValue& lhs, const ConfigValue& rhs) {
return !(lhs == rhs);
}

inline uint qHash(const ConfigValue& key) {
return qHash(key.value.toUpper());
inline uint qHash(
const ConfigValue& key,
uint seed = 0) {
return qHash(key.value.toUpper(), seed);
}

class ConfigValueKbd : public ConfigValue {
23 changes: 0 additions & 23 deletions src/soundio/soundmanagerutil.cpp
Original file line number Diff line number Diff line change
@@ -69,14 +69,6 @@ bool ChannelGroup::clashesWith(const ChannelGroup &other) const {
|| m_channelBase == other.m_channelBase;
}

/**
* Generates a hash of this ChannelGroup, so it can act as a key in a QHash.
* @return a hash for this ChannelGroup
*/
unsigned int ChannelGroup::getHash() const {
return 0 | (m_channels << 8) | m_channelBase;
}

/**
* Constructs an AudioPath object (must be called by a child class's
* constructor, AudioPath is abstract).
@@ -119,14 +111,6 @@ bool AudioPath::operator==(const AudioPath &other) const {
&& m_index == other.m_index;
}

/**
* Generates a hash of this AudioPath, so it can act as a key in a QHash.
* @return a hash for this AudioPath
*/
unsigned int AudioPath::getHash() const {
return 0 | (m_type << 8) | m_index;
}

/**
* Checks if this AudioPath's channels clash with another's
* (see ChannelGroup::clashesWith).
@@ -470,13 +454,6 @@ QString SoundDeviceId::debugName() const {
}
}

/**
* Defined for QHash, so ChannelGroup can be used as a QHash key.
*/
unsigned int qHash(const ChannelGroup &group) {
return group.getHash();
}

/**
* Defined for QHash, so AudioOutput can be used as a QHash key.
*/
36 changes: 25 additions & 11 deletions src/soundio/soundmanagerutil.h
Original file line number Diff line number Diff line change
@@ -30,14 +30,21 @@
* Mixxx.
*/
uklotzde marked this conversation as resolved.
Show resolved Hide resolved
class ChannelGroup {
public:
public:
ChannelGroup(unsigned char channelBase, unsigned char channels);
unsigned char getChannelBase() const;
unsigned char getChannelCount() const;
bool operator==(const ChannelGroup &other) const;
bool clashesWith(const ChannelGroup &other) const;
unsigned int getHash() const;
private:
bool operator==(const ChannelGroup& other) const;
bool clashesWith(const ChannelGroup& other) const;

friend uint qHash(
const ChannelGroup& group,
uint seed = 0) {
return qHash(group.m_channelBase, seed) |
qHash(group.m_channels, seed);
}

private:
unsigned char m_channelBase; // base (first) channel used on device
unsigned char m_channels; // number of channels used (s/b 2 in most cases)
};
@@ -71,7 +78,6 @@ class AudioPath {
ChannelGroup getChannelGroup() const;
unsigned char getIndex() const;
bool operator==(const AudioPath &other) const;
unsigned int getHash() const;
bool channelsClash(const AudioPath &other) const;
QString getString() const;
static QString getStringFromType(AudioPathType type);
@@ -88,6 +94,13 @@ class AudioPath {
// AudioPathType.
static unsigned char maxChannelsForType(AudioPathType type);

friend uint qHash(
const AudioPath& path,
uint seed = 0) {
return qHash(static_cast<uint>(path.m_type), seed) ^
qHash(path.m_index, seed);
}

protected:
virtual void setType(AudioPathType type) = 0;
AudioPathType m_type;
@@ -227,17 +240,18 @@ inline bool operator<(const SoundDeviceId& lhs, const SoundDeviceId& rhs) {

Q_DECLARE_METATYPE(SoundDeviceId);

inline unsigned int qHash(const SoundDeviceId& id) {
return qHash(id.name) + qHash(id.alsaHwDevice) + id.portAudioIndex;
inline uint qHash(
const SoundDeviceId& id,
uint seed = 0) {
return qHash(id.name, seed) ^
qHash(id.alsaHwDevice, seed) ^
qHash(id.portAudioIndex, seed);
}

inline QDebug operator<<(QDebug dbg, const SoundDeviceId& soundDeviceId) {
return dbg << QString("SoundDeviceId(" + soundDeviceId.debugName() + ")");
}

// globals for QHash
unsigned int qHash(const ChannelGroup &group);
unsigned int qHash(const AudioOutput &output);
unsigned int qHash(const AudioInput &input);

#endif
4 changes: 3 additions & 1 deletion src/track/trackfile.h
Original file line number Diff line number Diff line change
@@ -124,6 +124,8 @@ inline QDebug operator<<(QDebug debug, const TrackFile& trackFile) {
#endif
}

inline uint qHash(const TrackFile& key, uint seed) {
inline uint qHash(
const TrackFile& key,
uint seed = 0) {
return qHash(key.location(), seed);
}
8 changes: 6 additions & 2 deletions src/track/trackref.h
Original file line number Diff line number Diff line change
@@ -116,6 +116,10 @@ std::ostream& operator<<(std::ostream& os, const TrackRef& trackRef);

QDebug operator<<(QDebug debug, const TrackRef& trackRef);

inline uint qHash(const TrackRef& key, uint seed) {
return qHash(key.getLocation(), seed) ^ qHash(key.getId(), seed);
inline uint qHash(
const TrackRef& key,
uint seed = 0) {
return qHash(
key.getLocation(), seed) ^
qHash(key.getId(), seed);
}
6 changes: 4 additions & 2 deletions src/util/db/dbid.h
Original file line number Diff line number Diff line change
@@ -102,8 +102,10 @@ class DbId {
return debug << dbId.m_value;
}

friend uint qHash(const DbId& dbId) {
return qHash(dbId.m_value);
friend uint qHash(
const DbId& dbId,
uint seed = 0) {
return qHash(dbId.m_value, seed);
}

private: