-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsongStore.cpp
More file actions
83 lines (72 loc) · 1.8 KB
/
Copy pathsongStore.cpp
File metadata and controls
83 lines (72 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
using namespace std;
class Artist {
public:
string ArtistName;
vector<int> MusicId;
Artist(string name, vector<int> id) {
ArtistName = name;
MusicId = id;
}
};
class SongNode {
public:
string SongName;
int Aartist;
string Genre;
SongNode(string name, int art, string gen) {
SongName = name;
Aartist = art;
Genre = gen;
}
};
unordered_map<int, SongNode*> songmp; // Song Id, Song Node Info
unordered_map<int, Artist*> atmp; // Aritst Id, Aritst Node Info
unordered_map<string, int> artId;
void loadSongsFromCSV() {
int vars = 1;
vector<string> row;
string line, word, temp;
fstream fin;
fin.open("data.csv", ios::in);
int var = 0;
while (fin >> temp) {
row.clear();
getline(fin, line);
stringstream s(line);
while (getline(s, word, ',')) {
row.push_back(word);
}
for(auto it : row){
cout << it << " ";
}
cout << endl;
// Assign the Artist an ID
if (artId.find(row[2]) == artId.end()) {
artId[row[2]] = var++;
}
// Create a song Node with songName, ArtId, Genre
SongNode* sn = new SongNode(row[1], artId[row[2]], row[3]);
songmp[vars] = sn;
if (atmp.find(artId[row[2]]) == atmp.end()) {
vector<int> temp;
temp.push_back(vars);
Artist* ar = new Artist(row[2], temp);
atmp[artId[row[2]]] = ar;
}
else {
atmp[artId[row[2]]]->MusicId.push_back(vars);
}
vars++;
}
}
void print(int id) {
for (auto i : atmp[id]->MusicId) {
cout << i << " " << songmp[i]->SongName << endl;
}
}
int main() {
loadSongsFromCSV();
print(1);
return 0;
}