org.sonar.duplications.index
Class PackedMemoryCloneIndex

java.lang.Object
  extended by org.sonar.duplications.index.AbstractCloneIndex
      extended by org.sonar.duplications.index.PackedMemoryCloneIndex
All Implemented Interfaces:
CloneIndex

public class PackedMemoryCloneIndex
extends AbstractCloneIndex

Provides an index optimized by memory.

Each object in Java has an overhead - see "HOWTO: Determine the size of a Java Object or Class". So to optimize memory consumption, we use flat arrays, however this increases time of queries. During usual detection of duplicates most time consuming method is a getByResourceId(String): around 50% of time spent in this class and number of invocations of this method is 1% of total invocations, however total time spent in this class less than 1 second for small projects and around 2 seconds for projects like JDK.

Note that this implementation currently does not support deletion, however it's possible to implement.


Constructor Summary
PackedMemoryCloneIndex()
           
PackedMemoryCloneIndex(int hashBytes, int initialCapacity)
           
 
Method Summary
 Collection<Block> getByResourceId(String resourceId)
          Performs search of blocks for specified resource.
 Collection<Block> getBySequenceHash(ByteArray sequenceHash)
          Performs search of blocks for specified hash value.
 void insert(Block block)
          Adds specified block into index.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PackedMemoryCloneIndex

public PackedMemoryCloneIndex()

PackedMemoryCloneIndex

public PackedMemoryCloneIndex(int hashBytes,
                              int initialCapacity)
Parameters:
hashBytes - size of hash in bytes
initialCapacity - the initial capacity
Method Detail

getByResourceId

public Collection<Block> getByResourceId(String resourceId)
Performs search of blocks for specified resource.

Note that this implementation does not guarantee that blocks would be sorted by index.

Returns:
collection of blocks from index for specified resource and empty collection if nothing found

getBySequenceHash

public Collection<Block> getBySequenceHash(ByteArray sequenceHash)
Performs search of blocks for specified hash value.

Returns:
collection of blocks from index with specified hash and empty collection if nothing found

insert

public void insert(Block block)
Adds specified block into index.

Note that this implementation allows insertion of two blocks with same index for one resource.



Copyright © 2009-2012 SonarSource. All Rights Reserved.