/** * For speed, this method sets bits at the given index, without checking that the bits * are set in strictly ascending order. If the bits are not in ascending order, performance could be adversely affected. * * @param bitToSet index of the bit to set */ public void setWithoutAscendingCheck(final int bitToSet) { this.bitmap.set(bitToSet); }
/** * For speed, this method sets bits at the given index, without checking that the bits * are set in strictly ascending order. If the bits are not in ascending order, performance could be adversely affected. * * @param bitToSet index of the bit to set */ public void setWithoutAscendingCheck(final int bitToSet) { this.bitmap.set(bitToSet); }
@Override public void setValue(Object v) { bitmap.set((Integer) v); }
/** * Set the bit at position i to false. * * Though you can clear the bits in any order (e.g., clear(100), clear(10), clear(1), * you will typically get better performance if you clear the bits in increasing order (e.g., clear(1), clear(10), clear(100)). * * Clearing a bit that is larger than the biggest bit is a constant time operation. * Clearing a bit that is smaller than the biggest bit can require time proportional * to the compressed size of the bitmap, as the bitmap may need to be rewritten. * * Since this modifies the bitmap, this method is not thread-safe. * * @param i the index * @return true if the value was unset * @throws IndexOutOfBoundsException if i is negative or greater than Integer.MAX_VALUE - 64 */ public boolean clear(final int i) { return set(i, false); }
/** * Set the bit at position i to true. * * Though you can set the bits in any order (e.g., set(100), set(10), set(1), * you will typically get better performance if you set the bits in increasing order (e.g., set(1), set(10), set(100)). * * Setting a bit that is larger than any of the current set bit * is a constant time operation. Setting a bit that is smaller than an * already set bit can require time proportional to the compressed * size of the bitmap, as the bitmap may need to be rewritten. * * Since this modifies the bitmap, this method is not thread-safe. * * @param i the index * @return true if the value was set * @throws IndexOutOfBoundsException if i is negative or greater than Integer.MAX_VALUE - 64 */ public boolean set(final int i) { return set(i, true); }
/** * Set the bit at position i to false. * * Though you can clear the bits in any order (e.g., clear(100), clear(10), clear(1), * you will typically get better performance if you clear the bits in increasing order (e.g., clear(1), clear(10), clear(100)). * * Clearing a bit that is larger than the biggest bit is a constant time operation. * Clearing a bit that is smaller than the biggest bit can require time proportional * to the compressed size of the bitmap, as the bitmap may need to be rewritten. * * Since this modifies the bitmap, this method is not thread-safe. * * @param i the index * @return true if the value was unset * @throws IndexOutOfBoundsException if i is negative or greater than Integer.MAX_VALUE - 64 */ public boolean clear(final int i) { return set(i, false); }
/** * Set the bit at position i to true. * * Though you can set the bits in any order (e.g., set(100), set(10), set(1), * you will typically get better performance if you set the bits in increasing order (e.g., set(1), set(10), set(100)). * * Setting a bit that is larger than any of the current set bit * is a constant time operation. Setting a bit that is smaller than an * already set bit can require time proportional to the compressed * size of the bitmap, as the bitmap may need to be rewritten. * * Since this modifies the bitmap, this method is not thread-safe. * * @param i the index * @return true if the value was set * @throws IndexOutOfBoundsException if i is negative or greater than Integer.MAX_VALUE - 64 */ public boolean set(final int i) { return set(i, true); }
/** * Return a bitmap with the bit set to true at the given positions. The * positions should be given in sorted order. * * (This is a convenience method.) * * @param setBits list of set bit positions * @return the bitmap * @since 0.4.5 */ public static EWAHCompressedBitmap bitmapOf(int... setBits) { EWAHCompressedBitmap a = new EWAHCompressedBitmap(); for (int k : setBits) a.set(k); return a; }
/** * Return a bitmap with the bit set to true at the given positions. The * positions should be given in sorted order. * * (This is a convenience method.) * * @param setBits list of set bit positions * @return the bitmap * @since 0.4.5 */ public static EWAHCompressedBitmap bitmapOf(int... setBits) { EWAHCompressedBitmap a = new EWAHCompressedBitmap(); for (int k : setBits) a.set(k); return a; }
/** * add a click to the click maps * @param user the user that clicked * @param item the item that was clicked */ private void updateMap(long user, long item){ //if the user is unknown, generate an integer ID for the user //because EWAHCompressedBitmap cannot store long. if(!userMap.containsKey(user)){ userMap.put(user, ++currentUserCounter); userItemMap.put(currentUserCounter, new LongOpenHashSet()); } //extract the integer id the user int userInt = userMap.get(user); //extract the bitmap of clicks for this item EWAHCompressedBitmap itemClicks = itemClickMap.get(item); //if the bitmap does not exist, create it if(itemClicks==null){ itemClicks = new EWAHCompressedBitmap(); itemClickMap.put(item, itemClicks); } //put the current click in the click map itemClicks.set(userInt); //also update the reverse lookup userItemMap.get(userInt).add(item); }
/** * Set the bit at the given index. Throws an exception if bits are not set in strictly ascending order. * For performance reasons, bits must be set in ascending order. * * @param bitToSet The index of the bit to set. */ public void set(final int bitToSet) { // Check that we are setting bits in ascending order (equality with the last value is OK). if (this.bitmap.cardinality() > 0 && bitToSet < this.bitmap.toArray()[this.bitmap.cardinality() - 1]) { throw new IllegalArgumentException("Must set bits in strictly ascending order."); } this.bitmap.set(bitToSet); }
@Override protected void trainInternal(List<Item> items, List<ClickData> transactions) { //iterate over all newly published items for (Item item : items) { //if the keywords of the item are not null, create a keyword map an save it if(item.keywords!=null){ //create an empty bitmap of keyword IDs EWAHCompressedBitmap itemKeywords = new EWAHCompressedBitmap(); itemKeywordMap.put(item.id, itemKeywords); //iterate over the item's keywords for (String keyword : item.keywords.keySet()) { //if the keyword is unknown, generate a new INT id for it if(!keywordMap.containsKey(keyword)){ keywordMap.put(keyword, ++currentKeywordCounter); keywordItemMap.put(currentKeywordCounter, new LongOpenHashSet()); } //extract the id of the keyword int keywordInt = keywordMap.get(keyword); //set the bit for this keyword in the item's bitmap itemKeywords.set(keywordInt); //also set the item in the keyword's reverse lookup map keywordItemMap.get(keywordInt).add(item.id); } } } }
/** * Set the bit at the given index. Throws an exception if bits are not set in strictly ascending order. * For performance reasons, bits must be set in ascending order. * * @param bitToSet The index of the bit to set. */ public void set(final int bitToSet) { // Check that we are setting bits in ascending order (equality with the last value is OK). if (this.bitmap.cardinality() > 0 && bitToSet < this.bitmap.toArray()[this.bitmap.cardinality() - 1]) { throw new IllegalArgumentException("Must set bits in strictly ascending order."); } this.bitmap.set(bitToSet); }