Files
CSCI-1200/hws/tiktok_trends/VideoInfo.h
JamesFlare1212 a109046498 solve hw-9
2025-04-15 22:10:48 -04:00

37 lines
1.2 KiB
C++

#pragma once
#include <string>
#include <algorithm>
#include "Constants.h"
struct VideoInfo {
const std::string* videoId = nullptr;
const std::string* coverUrl = nullptr;
const std::string* webVideoUrl = nullptr;
long playCount = 0;
int inputOrder = -1;
VideoInfo() = default;
VideoInfo(const std::string* id, const std::string* cover, const std::string* web,
long plays, int order)
: videoId(id), coverUrl(cover), webVideoUrl(web), playCount(plays), inputOrder(order) {}
static bool compareForFinalSort(const VideoInfo& a, const VideoInfo& b) {
if (a.playCount != b.playCount) return a.playCount > b.playCount;
if (a.videoId && b.videoId && *a.videoId != *b.videoId) return *a.videoId < *b.videoId;
return a.inputOrder < b.inputOrder;
}
bool operator<(const VideoInfo& other) const {
if (playCount != other.playCount) return playCount > other.playCount;
return inputOrder < other.inputOrder;
}
};
struct VideoCompareWorse {
bool operator()(const VideoInfo& a, const VideoInfo& b) const {
if (a.playCount != b.playCount) return a.playCount > b.playCount;
return a.inputOrder < b.inputOrder;
}
};