Hamming Distance

G

Guest

  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
 
G

Guest

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
 
G

Guest

Thanks!

Ken- Hide quoted text -

- Show quoted text -

I'm told that Java enum types don’t have an integer value – so there
can’t 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
 
J

Joshua Cranmer

An ideal insider's answer... Terse, true and absolutely meaningless to
me, an obvious novice.

It is an appropriately vague answer for an appropriately vague question.
Hamming distance is the difference between two strings... of what?
Besides, there can be some differences between what is precisely meant
by "support" and also "get a Java enum class":
* Write a static utility method to do X for inputs of some type T
extends Enum<T>.
* Write a method for an enum X that supports this.
* Make a method on Enum itself that does this.
etc.
 
R

Roedy Green

An ideal insider's answer... Terse, true and absolutely meaningless to
me, an obvious novice.

He is poking fun at the extremely vague question.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, “How would I develop if it were my money?” I’m amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
 
R

Roedy Green

How does one get a Java enum class to support hamming distance?

Hamming distance is a very general term. You will have to be more
specific about the definition you are using.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, “How would I develop if it were my money?” I’m amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top