0

I have a n-line text file:

1st: 1,2,...1,1

2nd: 1,2,...0,1

3rd: 2,1,...,1,0

4th: 2,2,....,0,1

....

n th:1,2,....,1,1

Each line has 40 numbers, divided by comma. These numbers are indexed from 1 to 40. E.g the 1st line 1,2,...0,1; 1 is indexed 1, 2 is indexed 2, 0 is indexed 39, the last 1 is indexed 40.

I want to create equivalence classes for each index, e.g.

index 1: [1st,2nd][3rd,4th][nth]

index 2: [1st,2nd,4th,nth][3rd]

index 39:[1st,3rd,nth][2nd,4th]

index 40:[1st,2nd,4th,nth][3rd]

I am thinking of using HashMap<Integer,List<String>> but by this way, I need to maintain 40 arraylists in memory. This is difficult because the text file is a little big (n = millions of lines)

Since I am new to Java, I do not know if the above way is efficient or not? Or is there any better way to achieve that. Only idea is sufficient.

Thank you very much.

cdt
  • 85
  • 10
  • 1
    If you have space problems you could do one index after the other, i.e. read the file 40 times. – Henry Jul 10 '18 at 04:11
  • If you're trying to solve a problem in a programming competition then you're not supposed to store the input in memory, but process it in pieces and discard it. Java is perfectly capable of storing your map of lists, it depends on how much memory that you've assigned to it. Most likely in an algorithmic problem, memory requirement would be exponential space, which means there's usually a cleverer way to do it. – 11thdimension Jul 10 '18 at 04:13
  • @Henry already provided an effective method. If you wanna check the real-time memory usage, you can try to use `visualvm` to monitor it. – Hearen Jul 10 '18 at 04:16
  • Got it. Thank all of you for the supports. :) – cdt Jul 11 '18 at 14:11

0 Answers0