Fix incorrect pairing function

This commit is contained in:
mitteneer 2025-07-14 14:01:48 -04:00
parent 6aac0bff2b
commit cd8c798bd4
2 changed files with 5 additions and 3 deletions

View file

@ -177,12 +177,14 @@ pub fn post(request: *jetzig.Request) !jetzig.View {
} }
} }
std.log.debug("\nSkipped {} tracks\nFiltered {} tracks by date", .{ skipped_tracks, limited_tracks }); std.log.debug("Skipped {} tracks\nFiltered {} tracks by date", .{ skipped_tracks, limited_tracks });
try job.schedule(); try job.schedule();
return request.render(.created); return request.render(.created);
} }
// Cantor Pairing Function
// https://en.wikipedia.org/wiki/Pairing_function
fn pair(a: u64, b: u64) u64 { fn pair(a: u64, b: u64) u64 {
return @divFloor((a +% b) *% (a +% b +% 1) +% b, 2); return @mod(@divFloor((a +% b) *% (a +% b +% 1), 2) +% b, std.math.maxInt(u64));
} }

View file

@ -64,7 +64,7 @@ const ScrobbleFields = enum {
ms_played, // Spotify playtime ms_played, // Spotify playtime
reason_end, // Spotify reason end,1_000 reason_end, // Spotify reason end,1_000
@"@attr", // LastFM now playing @"@attr", // LastFM now playing
irrelevant, irrelevant, // Not a field I care about
}; };
pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.UnifiedScrobble { pub fn scrobbleIngest(allocator: std.mem.Allocator, input: []const u8) ![]Data.UnifiedScrobble {