Search Results

Search found 2 results on 1 pages for 'threenplusone'.

Page 1/1 | 1 

  • Java HashSet using a specified method

    - by threenplusone
    I have a basic class 'HistoryItem' like so: public class HistoryItem private Date startDate; private Date endDate; private Info info; private String details; @Override public int hashCode() { int hash = (startDate == null ? 0 : startDate.hashCode()); hash = hash * 31 + (endDate == null ? 0 : endDate.hashCode()); return hash; } } I am currently using a HashSet to remove duplicates from an ArrayList on the startDate & endDate fields, which is working correctly. However I also need to remove duplicates on different fields (info & details). My question is this. Is there a way to specify a different method which HashSet will use in place of hashCode()? Something like this: public int hashCode_2() { int hash = (info == null ? 0 : info.hashCode()); hash = hash * 31 + (details == null ? 0 : details.hashCode()); return hash; } Set<HistoryItem> removeDups = new HashSet<HistoryItem>(); removeDups.setHashMethod(hashCode_2); Or is there another way that I should be doing this?

    Read the article

  • Complexity of subset product

    - by threenplusone
    I have a set of numbers produced using the following formula with integers 0 < x < a. f(x) = f(x-1)^2 % a For example starting at 2 with a = 649. {2, 4, 16, 256, 636, 169, 5, 25, 649, 576, 137, ...} I am after a subset of these numbers that when multiplied together equals 1 mod N. I believe this problem by itself to be NP-complete (based on similaries to Subset-Sum problem). However starting with any integer (x) gives the same solution pattern. Eg. a = 649 {2, 4, 16, 256, 636, 169, 5, 25, 649, 576, 137, ...} = 16 * 5 * 576 = 1 % 649 {3, 9, 81, 71, 498, 86, 257, 500, 135, 53, 213, ...} = 81 * 257 * 53 = 1 % 649 {4, 16, 256, 636, 169, 5, 25, 649, 576, 137, 597, ...} = 256 * 25 * 137 = 1 % 649 I am wondering if this additional fact makes this problem solvable faster? Or if anyone has run into this problem previously or has any advice?

    Read the article

1