Switch HashTable to shared_ptr and add missing returns

Use std::shared_ptr<Track> in HashTable to avoid raw pointer ownership
issues. Also add missing return statements in Database ID lookup helpers.
This commit is contained in:
2026-06-25 11:33:29 +02:00
parent 00c8d9b843
commit 2849183f1f
4 changed files with 12 additions and 10 deletions
+3 -3
View File
@@ -108,7 +108,7 @@ std::ptrdiff_t ht::probe ( const std::string &key, uint64_t hash, bool insert )
#endif
} // probe
void ht::ht_insert( const std::string& key, Track* t ) {
void ht::ht_insert( const std::string& key, std::shared_ptr<Track> t ) {
//double loadFactor = static_cast<double> ( size_ ) / static_cast<double> ( ctrl_.size());
if ( loadFactor_ > MAX_LOAD ) rehash( ctrl_.size() * 2 );
@@ -121,7 +121,7 @@ void ht::ht_insert( const std::string& key, Track* t ) {
tmp.key = key;
tmp.hash = hash;
tmp.track = t;
entries_.at( idx ) = std::move( tmp );
entries_.at( idx ) = std::move(tmp);
++size_;
} else {
entries_.at( idx ).track = t;
@@ -129,7 +129,7 @@ void ht::ht_insert( const std::string& key, Track* t ) {
ctrl_.at( idx ) = fingerprint( hash );
}
Track* ht::ht_lookup( const std::string& key ) const {
std::shared_ptr<Track> ht::ht_lookup( const std::string& key ) const {
uint64_t hash = hashString( key );
auto idx = probe( key, hash, false );
if ( idx != -1 ) return entries_.at( static_cast<std::size_t> ( idx )).track;