track: Use a linear map to store files by format.

This commit is contained in:
Paul Lietar 2016-05-04 10:03:46 +01:00
parent c76b7b472f
commit ed14c3469b
5 changed files with 13 additions and 4 deletions

6
Cargo.lock generated
View file

@ -14,6 +14,7 @@ dependencies = [
"lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)", "libpulse-sys 0.0.0 (git+https://github.com/astro/libpulse-sys)",
"librespot-protocol 0.1.0", "librespot-protocol 0.1.0",
"linear-map 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "lmdb-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
@ -275,6 +276,11 @@ dependencies = [
"pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "pnacl-build-helper 1.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
] ]
[[package]]
name = "linear-map"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "lmdb-rs" name = "lmdb-rs"
version = "0.7.0" version = "0.7.0"

View file

@ -23,6 +23,7 @@ getopts = "~0.2.14"
hyper = { version = "0.9.1", default-features = false } hyper = { version = "0.9.1", default-features = false }
#json_macros = "~0.3.0" #json_macros = "~0.3.0"
lazy_static = "~0.2.0" lazy_static = "~0.2.0"
linear-map = "1.0"
lmdb-rs = "0.7.0" lmdb-rs = "0.7.0"
num = "~0.1.30" num = "~0.1.30"
protobuf = "~1.0.15" protobuf = "~1.0.15"

View file

@ -16,6 +16,7 @@ extern crate crypto;
extern crate eventual; extern crate eventual;
extern crate getopts; extern crate getopts;
extern crate hyper; extern crate hyper;
extern crate linear_map;
extern crate lmdb_rs; extern crate lmdb_rs;
extern crate num; extern crate num;
extern crate protobuf; extern crate protobuf;

View file

@ -1,4 +1,5 @@
use eventual::{Async, Future}; use eventual::{Async, Future};
use linear_map::LinearMap;
use protobuf; use protobuf;
use protocol; use protocol;
@ -37,7 +38,7 @@ pub struct Track {
pub name: String, pub name: String,
pub album: SpotifyId, pub album: SpotifyId,
pub artists: Vec<SpotifyId>, pub artists: Vec<SpotifyId>,
pub files: Vec<(FileId, FileFormat)>, pub files: LinearMap<FileFormat, FileId>,
pub alternatives: Vec<SpotifyId>, pub alternatives: Vec<SpotifyId>,
pub available: bool, pub available: bool,
} }
@ -85,7 +86,7 @@ impl MetadataTrait for Track {
.map(|file| { .map(|file| {
let mut dst = [0u8; 20]; let mut dst = [0u8; 20];
dst.clone_from_slice(&file.get_file_id()); dst.clone_from_slice(&file.get_file_id());
(FileId(dst), file.get_format()) (file.get_format(), FileId(dst))
}) })
.collect(); .collect();

View file

@ -196,8 +196,8 @@ fn load_track(session: &Session, track_id: SpotifyId) -> Option<vorbis::Decoder<
let file_id = match track.files.iter().find(|&&(_, f)| f == format) { let file_id = match track.files.get(&format) {
Some(&(file_id, _)) => file_id, Some(&file_id) => file_id,
None => { None => {
warn!("Track \"{}\" is not available in format {:?}", track.name, format); warn!("Track \"{}\" is not available in format {:?}", track.name, format);
return None; return None;