You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.4 KiB
52 lines
1.4 KiB
2 years ago
|
/*
|
||
|
* Copyright 2023 jacqueline <me@jacqueline.id.au>
|
||
|
*
|
||
|
* SPDX-License-Identifier: GPL-3.0-only
|
||
|
*/
|
||
|
|
||
2 years ago
|
#include "track.hpp"
|
||
2 years ago
|
|
||
2 years ago
|
#include <komihash.h>
|
||
2 years ago
|
|
||
2 years ago
|
namespace database {
|
||
|
|
||
2 years ago
|
/* Helper function to update a komihash stream with a std::string. */
|
||
2 years ago
|
auto HashString(komihash_stream_t* stream, std::string str) -> void {
|
||
|
komihash_stream_update(stream, str.c_str(), str.length());
|
||
|
}
|
||
|
|
||
2 years ago
|
/*
|
||
|
* Uses a komihash stream to incrementally hash tags. This lowers the function's
|
||
|
* memory footprint a little so that it's safe to call from any stack.
|
||
|
*/
|
||
2 years ago
|
auto TrackTags::Hash() const -> uint64_t {
|
||
|
// TODO(jacqueline): this function doesn't work very well for tracks with no
|
||
2 years ago
|
// tags at all.
|
||
2 years ago
|
komihash_stream_t stream;
|
||
|
komihash_stream_init(&stream, 0);
|
||
|
HashString(&stream, title.value_or(""));
|
||
|
HashString(&stream, artist.value_or(""));
|
||
|
HashString(&stream, album.value_or(""));
|
||
|
return komihash_stream_final(&stream);
|
||
|
}
|
||
|
|
||
2 years ago
|
auto TrackData::UpdateHash(uint64_t new_hash) const -> TrackData {
|
||
|
return TrackData(id_, filepath_, new_hash, play_count_, is_tombstoned_);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
auto TrackData::Entomb() const -> TrackData {
|
||
|
return TrackData(id_, filepath_, tags_hash_, play_count_, true);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
auto TrackData::Exhume(const std::string& new_path) const -> TrackData {
|
||
|
return TrackData(id_, new_path, tags_hash_, play_count_, false);
|
||
2 years ago
|
}
|
||
|
|
||
2 years ago
|
void swap(Track& first, Track& second) {
|
||
|
Track temp = first;
|
||
2 years ago
|
first = second;
|
||
|
second = temp;
|
||
|
}
|
||
|
|
||
2 years ago
|
} // namespace database
|