Hi all,
I have my 2nd assignment for C++ class which includes Markov chains, The assignment is simple but I'm not able to figure out what is the best implementation when reading chars from files I have a file around 300k, one of the rules for the assignment is to use Map and Vector classes in Map (key is only string) and values will be the Vectors. When im reading from file, I need to start collecting key pairs Example:
File1.txt
1234567890
1234567890
If Select Markov k=3 I should have in my Map:
key vector
123 -> 4
456 -> 7
789 -> 0
0/n1 -> 2
234 -> 5
567 -> 8
890 -> /n
/n -> NULL
Professor suggestion is to read char by char so my algorithm is the following
while (readchar != EOF){
tempstring += readchar
increment index
if index == Markovlevel {
get nextchar if =!EOF
insert nextchar value in vector
insert tempstring to Map and assign vector
unget char
}
}
I omit other details, my main question is that if I have 318,000 characters I will be doing the conditional every time which slows down my computer a lot (brand new MAC pro) sample program from professor executes this file in around 5 seconds Not able to figure out whats the best method to read fixed lenght words from a text file in c++.
Thanks!