Prev: Socket Buffered*putStream Threads and Full-duplex communication
Next: Cross Platform/Browser way to send PNG file to Webserver
From: avoidingspam2001 on 16 Mar 2010 10:48 How does one get a Java enum class to support hamming distance? Regards, Ken Asbury
From: avoidingspam2001 on 16 Mar 2010 10:57 On Mar 16, 10:52 am, r...(a)zedat.fu-berlin.de (Stefan Ram) wrote: > avoidingspam2...(a)yahoo.com writes: > >How does one get a Java enum class to support hamming distance? > > By implementing the appropriate methods. An ideal insider's answer... Terse, true and absolutely meaningless to me, an obvious novice. But thanks, anyway. Regards, Ken Asbury
From: Thomas Pornin on 16 Mar 2010 11:00 According to <avoidingspam2001(a)yahoo.com>: > How does one get a Java enum class to support hamming distance? I suppose that your question means the following: "Given two sets of flags, I want to compute the sum n1+n2, where n1 is the number of flags which are in the first set and not in the second, and n2 is the number of flags which are in the second set and not in the first. How can one do that if flags are enumeration constants ?" Then I may give this answer: Sets of flags, when flags are constants from an 'enum' construction, are represented by a java.util.EnumSet instance. This method shall then yield the Hamming distance between sets e1 and e2: static <E extends Enum<E>> int hammingDistance( EnumSet<E> e1, EnumSet<E> e2) { EnumSet<E> f1 = e1.clone(); f1.removeAll(e2); EnumSet<E> f2 = e2.clone(); f2.removeAll(e1); return f1.size() + f2.size(); } (This is untested.) --Thomas Pornin
From: avoidingspam2001 on 16 Mar 2010 11:03 On Mar 16, 11:00 am, Thomas Pornin <por...(a)bolet.org> wrote: > According to <avoidingspam2...(a)yahoo.com>: > > > How does one get a Java enum class to support hamming distance? > > I suppose that your question means the following: "Given two sets of > flags, I want to compute the sum n1+n2, where n1 is the number of flags > which are in the first set and not in the second, and n2 is the number > of flags which are in the second set and not in the first. How can one > do that if flags are enumeration constants ?" > > Then I may give this answer: > > Sets of flags, when flags are constants from an 'enum' construction, > are represented by a java.util.EnumSet instance. This method shall > then yield the Hamming distance between sets e1 and e2: > > static <E extends Enum<E>> int hammingDistance( > EnumSet<E> e1, EnumSet<E> e2) > { > EnumSet<E> f1 = e1.clone(); > f1.removeAll(e2); > EnumSet<E> f2 = e2.clone(); > f2.removeAll(e1); > return f1.size() + f2.size(); > } > > (This is untested.) > > --Thomas Pornin Thanks! Ken
From: avoidingspam2001 on 16 Mar 2010 11:54
On Mar 16, 11:03 am, avoidingspam2...(a)yahoo.com wrote: > On Mar 16, 11:00 am, Thomas Pornin <por...(a)bolet.org> wrote: > > > > > > > According to <avoidingspam2...(a)yahoo.com>: > > > > How does one get a Java enum class to support hamming distance? > > > I suppose that your question means the following: "Given two sets of > > flags, I want to compute the sum n1+n2, where n1 is the number of flags > > which are in the first set and not in the second, and n2 is the number > > of flags which are in the second set and not in the first. How can one > > do that if flags are enumeration constants ?" > > > Then I may give this answer: > > > Sets of flags, when flags are constants from an 'enum' construction, > > are represented by a java.util.EnumSet instance. This method shall > > then yield the Hamming distance between sets e1 and e2: > > > static <E extends Enum<E>> int hammingDistance( > > EnumSet<E> e1, EnumSet<E> e2) > > { > > EnumSet<E> f1 = e1.clone(); > > f1.removeAll(e2); > > EnumSet<E> f2 = e2.clone(); > > f2.removeAll(e1); > > return f1.size() + f2.size(); > > } > > > (This is untested.) > > > --Thomas Pornin > > Thanks! > > Ken- Hide quoted text - > > - Show quoted text - I'm told that Java enum types dont have an integer value so there cant be any Hamming Distance between them. I'm not sure, in my obviously advanced state of Java ignorance, how one prevents a damaged memory bit from causing an inappropriate decision path from being taken in a switch/case or if/else satement. In hardware, or in less abstracted programming languages such as ASM, C,C++, etc., it's relatively simple to create a set of discriminating values with suitable Hamming separation to avoid almost any defined concern. Rather than expending any more of your valuable (and highly valued!) time, is there a resource that discusses this at my level? Again, thanks. Ken |