int[] or List<Integer>?

Hi there! I'm having some trouble deciding on what to do with this, so I'd appreciate some help. The problem is this: I'm writing a program that encodes/decodes messages into/from series of bits (you code 'a' as 010011, decode 010011 as 'a'). For this, I had aHashMap<Character, int[]> for the coding and aHashMap<int[], Character> for the decoding, but it wouldn't work becauseint[] doesn't work for the key searches on the map (the decoding map). So I changedint[] toArrayList<Integer>.

And this is where the problem arises: for the coding and decoding processes it was quite convenient to have the codes asint[], since I have multiply this codes by matrices (which are currentlyint[][]), etc, and it's more immediate to do so withint[].

Changing the matrices toList<List><Integer>> would make the code a mess (in my opinion), since instead of doingm[j][k], I'd have to dom.get(j).get(k), etc, which isn't *that* bad, but I don't like it.

On the other hand, if I don't change them toList<List><Integer>> I'm facing a code in which items of apparently the same nature have different types.

So, what would you do in my place? Would you change them toList<List><Integer>>? Is there any other way?

Thanks a lot.

Sorry about my English :P

[1461 byte] By [black_blizzarda] at [2007-11-27 5:46:26]
# 1
How many ints make up one char according to your codec algorithm?
quittea at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 2
Encapsulate the array of integers in a class that is more meaningful, and provide that class with equals and hashCode methods. Then use this class instead of an array in the Map.
jsalonena at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 3

> How many ints make up one char according to your codec

> algorithm?

It's up to the user.

> Encapsulate the array of integers in a class that is

> more meaningful, and provide that class with equals

> and hashCode methods. Then use this class instead of

> an array in the Map.

Yeah, I'd thought about that, but wasn't especially fond of the idea, among other things because in Java you can't redefine operators, so I can't use operator[] anymore with my matrices. I can't, anyway, if I use List<Integer>, but... Dunno. Thank you, in any case!

I'll probably end up doing this, but I'd still like to hear other opinions.

black_blizzarda at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 4
bump
black_blizzarda at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 5
Well, I don't know why, but I think that the best way is to do with the List<List><Integer>>, because I think you will get more control with the key searches, even if the code gets messed up (in your opinion) ;)
Guilherme_Jra at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 6
Thanks for your opinion!I think I'll end up doing what jsalonen suggested, though, but I haven't made up my mind yet... Pity the key search doesn't work with int[]. It would be the ideal solution.
black_blizzarda at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 7

> Yeah, I'd thought about that, but wasn't especially

> fond of the idea, among other things because in Java

> you can't redefine operators, so I can't use

> operator[] anymore with my matrices. I can't, anyway,

> if I use List<Integer>, but... Dunno.

You can expose the array through a public variable or an accessor method.

This means that the class won't be mutable anymore so you'll have to be careful when you use it as a map key.

jsalonena at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 8
Hmm... Ok, sold. Thanks so much.
black_blizzarda at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 9
> This means that the class won't be mutableI meant immutable.
jsalonena at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...
# 10

> Hi there! I'm having some trouble deciding on what to

> do with this, so I'd appreciate some help. The

> problem is this: I'm writing a program that

> encodes/decodes messages into/from series of bits

> (you code 'a' as 010011, decode 010011 as 'a'). For

> this, I had a HashMap<Character, int[]>

Based entirely on the data you provided then I would use a array - nothing else.

If your character set must deal with one of the bigger sets that might not be practical but even then it might be.

It is much faster than any other method.

jschella at 2007-7-12 15:29:15 > top of Java-index,Java Essentials,Java Programming...