nus-yam/ex-repair huggingface dataset:
Program: 1360
Project: 1360
Buggy source:
private void processMovement(long delta){
  if (getParent() != null) {
    if (Keyboard.isKeyDown(Keyboard.KEY_R)) {
      resetPlayer();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_T)) {
      parent.generateTrees();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
      walkForward();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
      walkBackwards();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
      strafeLeft();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
      strafeRight();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
      jump();
    }
    if (!parent.isHitting(new Vector3f(getPosition().x,getPosition().y - PLAYER_HEIGHT,getPosition().z))) {
      if (gravity > -MAX_GRAVITY) {
        gravity-=1;
      }
      getPosition().y+=(gravity / 1000.0f) * delta;
    }
 else     if (gravity > 0.0f) {
      getPosition().y+=(gravity / 1000.0f) * delta;
    }
    if (isObjectInFrontOfPlayer()) {
      accX=0;
      accZ=0;
    }
    getPosition().x+=(accX / 1000.0f) * delta;
    getPosition().z+=(accZ / 1000.0f) * delta;
    accX=0;
    accZ=0;
  }
}

Fixed version (ground truth):
private void processMovement(long delta){
  if (getParent() != null) {
    if (Keyboard.isKeyDown(Keyboard.KEY_R)) {
      resetPlayer();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_T)) {
      parent.generateTrees();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_W)) {
      walkForward();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_S)) {
      walkBackwards();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_A)) {
      strafeLeft();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_D)) {
      strafeRight();
    }
    if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
      jump();
    }
    boolean hitting=parent.isHitting(new Vector3f(getPosition().x + 0.5f,getPosition().y - PLAYER_HEIGHT,getPosition().z + 0.5f));
    if (!hitting) {
      if (gravity > -MAX_GRAVITY) {
        gravity-=0.5f;
      }
      getPosition().y+=(gravity / 1000.0f) * delta;
    }
 else     if (gravity > 0.0f) {
      getPosition().y+=(gravity / 1000.0f) * delta;
    }
 else {
      gravity=0.0f;
    }
    Vector2f dir=new Vector2f((float)accX,(float)accZ);
    try {
      dir.normalise();
    }
 catch (    Exception e) {
    }
    if (checkForCollision(new Vector3f(getPosition().x + dir.x * 0.1f,getPosition().y - PLAYER_HEIGHT + 1,getPosition().z + dir.y * 0.1f))) {
      accX=0;
      accZ=0;
    }
    getPosition().x+=(accX / 1000.0f) * delta;
    getPosition().z+=(accZ / 1000.0f) * delta;
    accX=0;
    accZ=0;
  }
}
Program: 1361
Project: 1361
Buggy source:
public void init(){
  updateThread.start();
  Sphere s=new Sphere();
  displayListSun=glGenLists(1);
  glNewList(displayListSun,GL_COMPILE);
  glColor4f(1.0f,0.8f,0.0f,1.0f);
  s.draw(120.0f,16,32);
  glEndList();
}

Fixed version (ground truth):
public void init(){
  updateThread.start();
  Sphere s=new Sphere();
  displayListSun=glGenLists(1);
  glNewList(displayListSun,GL_COMPILE);
  glColor4f(1.0f,0.8f,0.0f,1.0f);
  s.draw(256.0f,16,32);
  glEndList();
}
Program: 1362
Project: 1362
Buggy source:
/** 
 * @return the player
 */
public Player getPlayer(){
  return player;
}

Fixed version (ground truth):
/** 
 * TODO
 */
public Player getPlayer(){
  return player;
}
Program: 1363
Project: 1363
Buggy source:
/** 
 * Sets the type of a block at a given position.
 * @param pos
 * @param type
 */
public final void setBlock(Vector3f pos,int type){
  Vector3f chunkPos=calcChunkPos(pos);
  Vector3f blockCoord=calcBlockPos(pos,chunkPos);
  try {
    Chunk c=chunks[(int)chunkPos.x][(int)chunkPos.y][(int)chunkPos.z];
    if (c == null) {
      c=new Chunk(this,new Vector3f(chunkPos.x,chunkPos.y,chunkPos.z));
      chunks[(int)chunkPos.x][(int)chunkPos.y][(int)chunkPos.z]=c;
    }
    c.setBlock(blockCoord,type,true);
    chunkUpdateQueue.add(c);
  }
 catch (  Exception e) {
    return;
  }
}

Fixed version (ground truth):
/** 
 * Sets the type of a block at a given position.
 */
public final void setBlock(Vector3f pos,int type){
  Vector3f chunkPos=calcChunkPos(pos);
  Vector3f blockCoord=calcBlockPos(pos,chunkPos);
  try {
    Chunk c=chunks[(int)chunkPos.x][(int)chunkPos.y][(int)chunkPos.z];
    Chunk c1=chunks[(int)chunkPos.x - 1][(int)chunkPos.y][(int)chunkPos.z];
    Chunk c2=chunks[(int)chunkPos.x + 1][(int)chunkPos.y][(int)chunkPos.z];
    Chunk c3=chunks[(int)chunkPos.x][(int)chunkPos.y][(int)chunkPos.z - 1];
    Chunk c4=chunks[(int)chunkPos.x][(int)chunkPos.y][(int)chunkPos.z + 1];
    c.setBlock(blockCoord,type,true);
    if ((int)blockCoord.x == 0) {
      c1.dirty=true;
      chunkUpdateQueue.add(c1);
    }
 else     if ((int)blockCoord.x == (int)Chunk.chunkDimensions.x - 1) {
      c2.dirty=true;
      chunkUpdateQueue.add(c2);
    }
    if ((int)blockCoord.z == 0) {
      c3.dirty=true;
      chunkUpdateQueue.add(c3);
    }
 else     if ((int)blockCoord.z == (int)Chunk.chunkDimensions.z - 1) {
      c4.dirty=true;
      chunkUpdateQueue.add(c4);
    }
    chunkUpdateQueue.add(c);
  }
 catch (  Exception e) {
    return;
  }
}
Program: 1364
Project: 1364
Buggy source:
/** 
 * Calculate the position of a world-block within a specific chunk.
 */
private Vector3f calcBlockPos(Vector3f pos,Vector3f chunkPos){
  return new Vector3f(pos.x - (chunkPos.x * Chunk.chunkDimensions.x),pos.y - (chunkPos.y * Chunk.chunkDimensions.y),pos.z - (chunkPos.z * Chunk.chunkDimensions.z));
}

Fixed version (ground truth):
/** 
 * Calculate the position of a world-block within a specific chunk.
 */
private Vector3f calcBlockPos(Vector3f pos,Vector3f chunkPos){
  if (pos != null && chunkPos != null) {
    return new Vector3f(pos.x - (chunkPos.x * Chunk.chunkDimensions.x),pos.y - (chunkPos.y * Chunk.chunkDimensions.y),pos.z - (chunkPos.z * Chunk.chunkDimensions.z));
  }
  return null;
}
Program: 1365
Project: 1365
Buggy source:
/** 
 * Calculate the corresponding chunk for a given position within the world.
 */
private Vector3f calcChunkPos(Vector3f pos){
  return new Vector3f((int)(pos.x / Chunk.chunkDimensions.x),(int)(pos.y / Chunk.chunkDimensions.y),(int)(pos.z / Chunk.chunkDimensions.z));
}

Fixed version (ground truth):
/** 
 * Calculate the corresponding chunk for a given position within the world.
 */
private Vector3f calcChunkPos(Vector3f pos){
  if (pos != null) {
    return new Vector3f((int)(pos.x / Chunk.chunkDimensions.x),(int)(pos.y / Chunk.chunkDimensions.y),(int)(pos.z / Chunk.chunkDimensions.z));
  }
  return null;
}
Program: 1366
Project: 1366
Buggy source:
@Override public void render(){
  glPushMatrix();
  glDisable(GL_FOG);
  glTranslatef(Configuration.viewingDistanceInChunks.x * Chunk.chunkDimensions.x,Configuration.viewingDistanceInChunks.y * Chunk.chunkDimensions.y * 2f,Configuration.viewingDistanceInChunks.z * Chunk.chunkDimensions.z);
  glCallList(displayListSun);
  glEnable(GL_FOG);
  glPopMatrix();
  for (int x=0; x < Configuration.viewingDistanceInChunks.x; x++) {
    for (int y=0; y < Configuration.viewingDistanceInChunks.y; y++) {
      for (int z=0; z < Configuration.viewingDistanceInChunks.z; z++) {
        Chunk c=chunks[x][y][z];
        if (c != null) {
          c.render();
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override public void render(){
  glPushMatrix();
  glDisable(GL_FOG);
  glTranslatef(Configuration.viewingDistanceInChunks.x * Chunk.chunkDimensions.x * 1.5f,Configuration.viewingDistanceInChunks.y * Chunk.chunkDimensions.y,Configuration.viewingDistanceInChunks.z * Chunk.chunkDimensions.z * 1.5f);
  glCallList(displayListSun);
  glEnable(GL_FOG);
  glPopMatrix();
  for (int x=0; x < Configuration.viewingDistanceInChunks.x; x++) {
    for (int y=0; y < Configuration.viewingDistanceInChunks.y; y++) {
      for (int z=0; z < Configuration.viewingDistanceInChunks.z; z++) {
        Chunk c=chunks[x][y][z];
        if (c != null) {
          c.render();
        }
      }
    }
  }
}
Program: 1367
Project: 1367
Buggy source:
private HyperLogLogPlus(int p,int sp,int[] sparseSet,RegisterSet registerSet){
  if ((p < 4) || ((p > sp) && (sp != 0))) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sp > 32) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.p=p;
  m=1 << p;
  format=Format.NORMAL;
  this.registerSet=registerSet;
  if (registerSet == null) {
    if (sp > 0) {
      format=Format.SPARSE;
      this.sp=sp;
      sm=1 << sp;
      if (sparseSet == null) {
        this.sparseSet=EMPTY_SPARSE;
      }
 else {
        this.sparseSet=sparseSet;
      }
      sparseSetThreshold=(int)(m * 0.75);
    }
 else {
      this.registerSet=new RegisterSet(1 << p);
    }
  }
  this.alphaMM=HyperLogLog.getAlphaMM(p,m);
}

Fixed version (ground truth):
private HyperLogLogPlus(int p,int sp,int[] sparseSet,RegisterSet registerSet){
  if ((p < 4) || ((p > sp) && (sp != 0))) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  if (sp > 32) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  this.p=p;
  m=p > 30 ? Integer.MAX_VALUE : 1 << p;
  format=Format.NORMAL;
  this.registerSet=registerSet;
  if (registerSet == null) {
    if (sp > 0) {
      format=Format.SPARSE;
      this.sp=sp;
      sm=sp > 30 ? Integer.MAX_VALUE : 1 << sp;
      if (sparseSet == null) {
        this.sparseSet=EMPTY_SPARSE;
      }
 else {
        this.sparseSet=sparseSet;
      }
      sparseSetThreshold=(int)(m * 0.75);
    }
 else {
      this.registerSet=new RegisterSet(m);
    }
  }
  this.alphaMM=HyperLogLog.getAlphaMM(p,m);
}
Program: 1368
Project: 1368
Buggy source:
@Override public boolean equals(Object obj){
  if (!(obj instanceof HyperLogLogPlus)) {
    return false;
  }
  HyperLogLogPlus other=(HyperLogLogPlus)obj;
  if (other.format != format) {
    return false;
  }
  if (format == Format.NORMAL) {
    return Arrays.equals(registerSet.readOnlyBits(),other.registerSet.readOnlyBits());
  }
 else {
    mergeTempList();
    other.mergeTempList();
    return Arrays.equals(sparseSet,sparseSet);
  }
}

Fixed version (ground truth):
@Override public boolean equals(Object obj){
  if (!(obj instanceof HyperLogLogPlus)) {
    return false;
  }
  HyperLogLogPlus other=(HyperLogLogPlus)obj;
  if (other.format != format) {
    return false;
  }
  if (format == Format.NORMAL) {
    return Arrays.equals(registerSet.readOnlyBits(),other.registerSet.readOnlyBits());
  }
 else {
    mergeTempList();
    other.mergeTempList();
    return Arrays.equals(sparseSet,other.sparseSet);
  }
}
Program: 1369
Project: 1369
Buggy source:
@Test public void testAccuracyStrings(){
  int seed=7364181;
  Random r=new Random(seed);
  int numItems=1000000;
  String[] xs=new String[numItems];
  int maxScale=20;
  for (int i=0; i < xs.length; ++i) {
    int scale=r.nextInt(maxScale);
    xs[i]=RandomStringUtils.random(scale);
  }
  double epsOfTotalCount=0.0001;
  double confidence=0.99;
  CountMinSketch sketch=new CountMinSketch(epsOfTotalCount,confidence,seed);
  for (  String x : xs) {
    sketch.add(x,1);
  }
  Map<String,Long> actualFreq=new HashMap<String,Long>();
  for (  String x : xs) {
    Long val=actualFreq.get(x);
    if (val == null) {
      actualFreq.put(x,1L);
    }
 else {
      actualFreq.put(x,val + 1L);
    }
  }
  sketch=CountMinSketch.deserialize(CountMinSketch.serialize(sketch));
  int numErrors=0;
  for (int i=0; i < actualFreq.size(); ++i) {
    Long value=actualFreq.get(i);
    long lvalue=(value == null) ? 0 : value;
    double ratio=1.0 * (sketch.estimateCount(i) - lvalue) / xs.length;
    if (ratio > 1.0001) {
      numErrors++;
    }
  }
  double pCorrect=1 - 1.0 * numErrors / actualFreq.size();
  assertTrue("String_Node_Str" + confidence + "String_Node_Str"+ pCorrect,pCorrect > confidence);
}

Fixed version (ground truth):
@Test public void testAccuracyStrings(){
  int seed=7364181;
  Random r=new Random(seed);
  int numItems=1000000;
  int absentItems=numItems * 10;
  String[] xs=new String[numItems];
  int maxScale=20;
  for (int i=0; i < numItems; i++) {
    int scale=r.nextInt(maxScale);
    xs[i]=RandomStringUtils.random(scale);
  }
  double epsOfTotalCount=0.0001;
  double confidence=0.99;
  CountMinSketch sketch=new CountMinSketch(epsOfTotalCount,confidence,seed);
  for (  String x : xs) {
    sketch.add(x,1);
  }
  Map<String,Long> actualFreq=new HashMap<String,Long>();
  for (  String x : xs) {
    Long val=actualFreq.get(x);
    if (val == null) {
      actualFreq.put(x,1L);
    }
 else {
      actualFreq.put(x,val + 1L);
    }
  }
  sketch=CountMinSketch.deserialize(CountMinSketch.serialize(sketch));
  int numErrors=0;
  for (  Map.Entry<String,Long> entry : actualFreq.entrySet()) {
    String key=entry.getKey();
    long count=entry.getValue();
    double ratio=((double)(sketch.estimateCount(key) - count)) / numItems;
    if (ratio > epsOfTotalCount) {
      numErrors++;
    }
  }
  for (int i=0; i < absentItems; i++) {
    int scale=r.nextInt(maxScale);
    String key=RandomStringUtils.random(scale);
    Long value=actualFreq.get(key);
    long count=(value == null) ? 0L : value;
    double ratio=((double)(sketch.estimateCount(key) - count)) / numItems;
    if (ratio > epsOfTotalCount) {
      numErrors++;
    }
  }
  double pCorrect=1.0 - ((double)numErrors) / (numItems + absentItems);
  System.out.println(pCorrect);
  assertTrue("String_Node_Str" + confidence + "String_Node_Str"+ pCorrect,pCorrect > confidence);
  assertTrue("String_Node_Str" + confidence + "String_Node_Str"+ pCorrect,pCorrect > confidence);
}
Program: 1370
Project: 1370
Buggy source:
@Test public void testAccuracy(){
  int seed=7364181;
  Random r=new Random(seed);
  int numItems=1000000;
  int[] xs=new int[numItems];
  int maxScale=20;
  for (int i=0; i < xs.length; ++i) {
    int scale=r.nextInt(maxScale);
    xs[i]=r.nextInt(1 << scale);
  }
  double epsOfTotalCount=0.0001;
  double confidence=0.99;
  CountMinSketch sketch=new CountMinSketch(epsOfTotalCount,confidence,seed);
  for (  int x : xs) {
    sketch.add(x,1);
  }
  int[] actualFreq=new int[1 << maxScale];
  for (  int x : xs) {
    actualFreq[x]++;
  }
  sketch=CountMinSketch.deserialize(CountMinSketch.serialize(sketch));
  int numErrors=0;
  for (int i=0; i < actualFreq.length; ++i) {
    double ratio=1.0 * (sketch.estimateCount(i) - actualFreq[i]) / xs.length;
    if (ratio > 1.0001) {
      numErrors++;
    }
  }
  double pCorrect=1 - 1.0 * numErrors / actualFreq.length;
  assertTrue("String_Node_Str" + confidence + "String_Node_Str"+ pCorrect,pCorrect > confidence);
}

Fixed version (ground truth):
@Test public void testAccuracy(){
  int seed=7364181;
  Random r=new Random(seed);
  int numItems=1000000;
  int[] xs=new int[numItems];
  int maxScale=20;
  for (int i=0; i < numItems; i++) {
    int scale=r.nextInt(maxScale);
    xs[i]=r.nextInt(1 << scale);
  }
  double epsOfTotalCount=0.0001;
  double confidence=0.99;
  CountMinSketch sketch=new CountMinSketch(epsOfTotalCount,confidence,seed);
  for (  int x : xs) {
    sketch.add(x,1);
  }
  int[] actualFreq=new int[1 << maxScale];
  for (  int x : xs) {
    actualFreq[x]++;
  }
  sketch=CountMinSketch.deserialize(CountMinSketch.serialize(sketch));
  int numErrors=0;
  for (int i=0; i < actualFreq.length; ++i) {
    double ratio=((double)(sketch.estimateCount(i) - actualFreq[i])) / numItems;
    if (ratio > epsOfTotalCount) {
      numErrors++;
    }
  }
  double pCorrect=1.0 - ((double)numErrors) / actualFreq.length;
  assertTrue("String_Node_Str" + confidence + "String_Node_Str"+ pCorrect,pCorrect > confidence);
}
Program: 1371
Project: 1371
Buggy source:
private void compressFully(){
  Long[] allNodes=node2count.keySet().toArray(new Long[node2count.size()]);
  for (  long node : allNodes) {
    compressDownward(node);
  }
}

Fixed version (ground truth):
private void compressFully(){
  Long[] allNodes=node2count.keySet().toArray(new Long[node2count.size()]);
  for (  long node : allNodes) {
    if (!isRoot(node)) {
      compressDownward(node);
    }
  }
}
Program: 1373
Project: 1373
Buggy source:
@Override public byte[] getBytes() throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataOutputStream dos=new DataOutputStream(baos);
  dos.writeInt(-VERSION);
  dos.write(Varint.writeUnsignedVarInt(p));
  dos.write(Varint.writeUnsignedVarInt(sp));
switch (format) {
case NORMAL:
    dos.write(Varint.writeUnsignedVarInt(0));
  dos.write(Varint.writeUnsignedVarInt(registerSet.size * 4));
for (int x : registerSet.bits()) {
  dos.writeInt(x);
}
break;
case SPARSE:
dos.write(Varint.writeUnsignedVarInt(1));
mergeTempList();
dos.write(Varint.writeUnsignedVarInt(sparseSet.length));
int prevMergedDelta=0;
for (int k : sparseSet) {
dos.write(deltaAdd(k,prevMergedDelta));
prevMergedDelta=k;
}
break;
}
return baos.toByteArray();
}

Fixed version (ground truth):
@Override public byte[] getBytes() throws IOException {
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  DataOutputStream dos=new DataOutputStream(baos);
  dos.writeInt(-VERSION);
  Varint.writeUnsignedVarInt(p,dos);
  Varint.writeUnsignedVarInt(sp,dos);
switch (format) {
case NORMAL:
    Varint.writeUnsignedVarInt(0,dos);
  Varint.writeUnsignedVarInt(registerSet.size * 4,dos);
for (int x : registerSet.bits()) {
  dos.writeInt(x);
}
break;
case SPARSE:
Varint.writeUnsignedVarInt(1,dos);
mergeTempList();
Varint.writeUnsignedVarInt(sparseSet.length,dos);
int prevMergedDelta=0;
for (int k : sparseSet) {
Varint.writeUnsignedVarInt(k - prevMergedDelta,dos);
prevMergedDelta=k;
}
break;
}
return baos.toByteArray();
}
Program: 1374
Project: 1374
Buggy source:
private static HyperLogLogPlus decodeBytes(DataInputStream oi) throws IOException {
  int p=Varint.readUnsignedVarInt(oi);
  int sp=Varint.readUnsignedVarInt(oi);
  int formatType=Varint.readUnsignedVarInt(oi);
  if (formatType == 0) {
    int size=Varint.readUnsignedVarInt(oi);
    byte[] longArrayBytes=new byte[size];
    oi.readFully(longArrayBytes);
    HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(p,sp,new RegisterSet((int)Math.pow(2,p),Bits.getBits(longArrayBytes)));
    hyperLogLogPlus.format=Format.NORMAL;
    return hyperLogLogPlus;
  }
 else {
    int[] rehydratedSparseSet=new int[Varint.readUnsignedVarInt(oi)];
    int prevDeltaRead=0;
    for (int i=0; i < rehydratedSparseSet.length; i++) {
      int nextVal=HyperLogLogPlus.deltaRead(Varint.readUnsignedVarInt(oi),prevDeltaRead);
      rehydratedSparseSet[i]=nextVal;
      prevDeltaRead=nextVal;
    }
    HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(p,sp,rehydratedSparseSet);
    hyperLogLogPlus.format=Format.SPARSE;
    return hyperLogLogPlus;
  }
}

Fixed version (ground truth):
private static HyperLogLogPlus decodeBytes(DataInputStream oi) throws IOException {
  int p=Varint.readUnsignedVarInt(oi);
  int sp=Varint.readUnsignedVarInt(oi);
  int formatType=Varint.readUnsignedVarInt(oi);
  if (formatType == 0) {
    int size=Varint.readUnsignedVarInt(oi);
    byte[] longArrayBytes=new byte[size];
    oi.readFully(longArrayBytes);
    HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(p,sp,new RegisterSet((int)Math.pow(2,p),Bits.getBits(longArrayBytes)));
    hyperLogLogPlus.format=Format.NORMAL;
    return hyperLogLogPlus;
  }
 else {
    int[] rehydratedSparseSet=new int[Varint.readUnsignedVarInt(oi)];
    int prevDeltaRead=0;
    for (int i=0; i < rehydratedSparseSet.length; i++) {
      int nextVal=Varint.readUnsignedVarInt(oi) + prevDeltaRead;
      rehydratedSparseSet[i]=nextVal;
      prevDeltaRead=nextVal;
    }
    HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(p,sp,rehydratedSparseSet);
    hyperLogLogPlus.format=Format.SPARSE;
    return hyperLogLogPlus;
  }
}
Program: 1375
Project: 1375
Buggy source:
/** 
 * Merge this HLL++ instance with another! The power of friends! <p/> This works very similarly to the merge with temp list function. <p/> However, in this case, both lists will need their own delta decoding and neither will have to worry about consuming duplicates.
 * @param other
 * @return the new sparse set
 */
private int[] mergeEstimators(HyperLogLogPlus other){
  other.mergeTempList();
  int[] tmp=other.getSparseSet();
  mergeTempList();
  int[] set=sparseSet;
  List<Integer> newSet=new ArrayList<Integer>();
  int seti=0;
  int tmpi=0;
  while (seti < set.length || tmpi < tmp.length) {
    if (seti >= set.length) {
      newSet.add(tmp[tmpi++]);
    }
 else     if (tmpi >= tmp.length) {
      newSet.add(set[seti++]);
    }
 else {
      int setVal=set[seti];
      int tmpVal=tmp[tmpi];
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        newSet.add(Math.min(setVal,tmpVal));
        tmpi++;
        seti++;
      }
 else       if (setVal < tmpVal) {
        newSet.add(setVal);
        seti++;
      }
 else {
        newSet.add(tmpVal);
        tmpi++;
      }
    }
  }
  return toIntArray(newSet);
}

Fixed version (ground truth):
/** 
 * Merge this HLL++ instance with another! The power of friends! <p/> This works very similarly to the merge with temp list function. <p/> However, in this case, both lists will need their own delta decoding and neither will have to worry about consuming duplicates.
 * @param other
 * @return the new sparse set
 */
private int[] mergeEstimators(HyperLogLogPlus other){
  other.mergeTempList();
  int[] tmp=other.getSparseSet();
  mergeTempList();
  int[] set=sparseSet;
  List<Integer> newSet=new ArrayList<Integer>();
  int seti=0;
  int tmpi=0;
  while (seti < set.length || tmpi < tmp.length) {
    if (seti >= set.length) {
      newSet.add(tmp[tmpi++]);
    }
 else     if (tmpi >= tmp.length) {
      newSet.add(set[seti++]);
    }
 else {
      int setVal=set[seti];
      int tmpVal=tmp[tmpi];
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        newSet.add(Math.min(setVal,tmpVal));
        tmpi++;
        seti++;
      }
 else       if (getSparseIndex(setVal) < getSparseIndex(tmpVal)) {
        newSet.add(setVal);
        seti++;
      }
 else {
        newSet.add(tmpVal);
        tmpi++;
      }
    }
  }
  return toIntArray(newSet);
}
Program: 1376
Project: 1376
Buggy source:
private double getBias(int[] nearestNeighbors){
  double[] biasVector=biasData[p - 4];
  double biasTotal=0.0d;
  for (  int nearestNeighbor : nearestNeighbors) {
    biasTotal+=biasVector[nearestNeighbor];
  }
  return biasTotal / (biasVector.length);
}

Fixed version (ground truth):
private double getBias(int[] nearestNeighbors){
  double[] biasVector=biasData[p - 4];
  double biasTotal=0.0d;
  for (  int nearestNeighbor : nearestNeighbors) {
    biasTotal+=biasVector[nearestNeighbor];
  }
  return biasTotal / (nearestNeighbors.length);
}
Program: 1377
Project: 1377
Buggy source:
public static QDigest unionOf(QDigest a,QDigest b){
  if (a.compressionFactor != b.compressionFactor) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + a.compressionFactor + "String_Node_Str"+ "String_Node_Str"+ b.compressionFactor);
  }
  if (a.capacity > b.capacity) {
    return unionOf(b,a);
  }
  QDigest res=new QDigest(a.compressionFactor);
  res.capacity=a.capacity;
  for (  long k : a.node2count.keySet()) {
    res.node2count.put(k,a.node2count.get(k));
  }
  if (b.capacity > res.capacity) {
    res.rebuildToCapacity(b.capacity);
  }
  for (  long k : b.node2count.keySet()) {
    res.node2count.put(k,b.get(k) + res.get(k));
  }
  res.compressFully();
  return res;
}

Fixed version (ground truth):
public static QDigest unionOf(QDigest a,QDigest b){
  if (a.compressionFactor != b.compressionFactor) {
    throw new IllegalArgumentException("String_Node_Str" + "String_Node_Str" + a.compressionFactor + "String_Node_Str"+ "String_Node_Str"+ b.compressionFactor);
  }
  if (a.capacity > b.capacity) {
    return unionOf(b,a);
  }
  QDigest res=new QDigest(a.compressionFactor);
  res.capacity=a.capacity;
  res.size=a.size + b.size;
  for (  long k : a.node2count.keySet()) {
    res.node2count.put(k,a.node2count.get(k));
  }
  if (b.capacity > res.capacity) {
    res.rebuildToCapacity(b.capacity);
  }
  for (  long k : b.node2count.keySet()) {
    res.node2count.put(k,b.get(k) + res.get(k));
  }
  res.compressFully();
  return res;
}
Program: 1378
Project: 1378
Buggy source:
@Override public void offer(long value){
  if (value < 0 || value == Long.MAX_VALUE) {
    throw new IllegalArgumentException("String_Node_Str" + (Long.MAX_VALUE - 1));
  }
  if (value >= capacity) {
    rebuildToCapacity(Long.highestOneBit(value) << 1);
  }
  long leaf=value2leaf(value);
  node2count.put(leaf,get(leaf) + 1);
  size++;
  compressUpward(leaf);
  if (node2count.size() > 3 * compressionFactor) {
    compressFully();
  }
}

Fixed version (ground truth):
@Override public void offer(long value){
  if (value < 0 || value > Long.MAX_VALUE / 2) {
    throw new IllegalArgumentException("String_Node_Str" + Long.MAX_VALUE / 2 + "String_Node_Str" + value);
  }
  if (value >= capacity) {
    rebuildToCapacity(Long.highestOneBit(value) << 1);
  }
  long leaf=value2leaf(value);
  node2count.put(leaf,get(leaf) + 1);
  size++;
  compressUpward(leaf);
  if (node2count.size() > 3 * compressionFactor) {
    compressFully();
  }
}
Program: 1379
Project: 1379
Buggy source:
@Override public long getQuantile(double q){
  List<long[]> ranges=toAscRanges();
  long s=0;
  for (  long[] r : ranges) {
    if (s > q * size) {
      return r[1];
    }
    s+=r[2];
  }
  return ranges.get(ranges.size() - 1)[1];
}

Fixed version (ground truth):
@Override public long getQuantile(double q){
  List<long[]> ranges=toAscRanges();
  long s=0;
  for (  long[] r : ranges) {
    s+=r[2];
    if (s > q * size) {
      return r[1];
    }
  }
  return ranges.get(ranges.size() - 1)[1];
}
Program: 1380
Project: 1380
Buggy source:
private double getBias(int[] nearestNeighbors){
  double[] biasVector=biasData[p - 4];
  double biasTotal=0.0d;
  for (  int nearestNeighbor : nearestNeighbors) {
    biasTotal+=biasVector[nearestNeighbor];
  }
  return biasTotal / (biasVector.length);
}

Fixed version (ground truth):
private double getBias(int[] nearestNeighbors){
  double[] biasVector=biasData[p - 4];
  double biasTotal=0.0d;
  for (  int nearestNeighbor : nearestNeighbors) {
    biasTotal+=biasVector[nearestNeighbor];
  }
  return biasTotal / nearestNeighbors.length;
}
Program: 1382
Project: 1382
Buggy source:
private List<byte[]> mergeEstimators(List<byte[]> set,HyperLogLogPlus other){
  List<byte[]> tmp=other.sparseSet;
  List<byte[]> newSet=new ArrayList<byte[]>();
  Map<Integer,Integer> indexMap=new HashMap<Integer,Integer>();
  int seti=0;
  int tmpi=0;
  while (seti < set.size() || tmpi < tmp.size()) {
    if (seti >= set.size()) {
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      conditionalAdd(indexMap,tmpVal,newSet);
      tmpi++;
    }
 else     if (tmpi >= tmp.size()) {
      int setVal=unzipInt(set.get(seti));
      conditionalAdd(indexMap,setVal,newSet);
      seti++;
    }
 else {
      int setVal=unzipInt(set.get(seti));
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        int max=Math.max(setVal,tmpVal);
        conditionalAdd(indexMap,max,newSet);
        tmpi++;
        seti++;
      }
 else       if (setVal < tmpVal) {
        conditionalAdd(indexMap,setVal,newSet);
        seti++;
      }
 else {
        conditionalAdd(indexMap,tmpVal,newSet);
        tmpi++;
      }
    }
  }
  old_delta=delta;
  return newSet;
}

Fixed version (ground truth):
private List<byte[]> mergeEstimators(HyperLogLogPlus other){
  other.mergeTmp();
  mergeTmp();
  List<byte[]> set=sparseSet;
  List<byte[]> tmp=other.sparseSet;
  List<byte[]> newSet=new ArrayList<byte[]>();
  Map<Integer,Integer> indexMap=new HashMap<Integer,Integer>();
  int seti=0;
  int tmpi=0;
  while (seti < set.size() || tmpi < tmp.size()) {
    if (seti >= set.size()) {
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      conditionalAdd(indexMap,tmpVal,newSet);
      tmpi++;
    }
 else     if (tmpi >= tmp.size()) {
      int setVal=unzipInt(set.get(seti));
      conditionalAdd(indexMap,setVal,newSet);
      seti++;
    }
 else {
      int setVal=unzipInt(set.get(seti));
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        int min=Math.min(setVal,tmpVal);
        conditionalAdd(indexMap,min,newSet);
        tmpi++;
        seti++;
      }
 else       if (setVal < tmpVal) {
        conditionalAdd(indexMap,setVal,newSet);
        seti++;
      }
 else {
        conditionalAdd(indexMap,tmpVal,newSet);
        tmpi++;
      }
    }
  }
  old_delta=delta;
  return newSet;
}
Program: 1383
Project: 1383
Buggy source:
@Override public ICardinality merge(ICardinality... estimators) throws CardinalityMergeException {
  if (estimators == null || estimators.length == 0) {
    return this;
  }
  int size=this.sizeof();
  for (  ICardinality estimator : estimators) {
    if (!(estimator instanceof HyperLogLogPlus)) {
      throw new HyperLogLogPlusMergeException("String_Node_Str");
    }
    if (estimator.sizeof() != size) {
      throw new HyperLogLogPlusMergeException("String_Node_Str");
    }
    HyperLogLogPlus hll=(HyperLogLogPlus)estimator;
    if (format == Format.SPARSE) {
      if (hll.format == Format.SPARSE) {
        if (sparseSet.size() + hll.sparseSet.size() > MaxThreshold) {
          convertToNormal();
          hll.convertToNormal();
        }
 else {
          mergeTmp();
          hll.mergeTmp();
          sparseSet=mergeEstimators(sparseSet,hll);
        }
      }
 else {
        convertToNormal();
      }
    }
 else {
      if (hll.format == Format.SPARSE) {
        hll.convertToNormal();
      }
    }
    if (format != Format.SPARSE) {
      for (int b=0; b < registerSet.count; b++) {
        registerSet.set(b,Math.max(registerSet.get(b),hll.registerSet.get(b)));
      }
    }
  }
  if (format == Format.SPARSE) {
    return new HyperLogLogPlus(p,sp,sparseSet);
  }
  HyperLogLogPlus outEst=new HyperLogLogPlus(p,sp,registerSet);
  outEst.format=Format.NORMAL;
  return outEst;
}

Fixed version (ground truth):
@Override public ICardinality merge(ICardinality... estimators) throws CardinalityMergeException {
  if (estimators == null || estimators.length == 0) {
    return this;
  }
  int size=this.sizeof();
  for (  ICardinality estimator : estimators) {
    if (!(estimator instanceof HyperLogLogPlus)) {
      throw new HyperLogLogPlusMergeException("String_Node_Str");
    }
    if (estimator.sizeof() != size) {
      throw new HyperLogLogPlusMergeException("String_Node_Str");
    }
    HyperLogLogPlus hll=(HyperLogLogPlus)estimator;
    if (format == Format.SPARSE) {
      if (hll.format == Format.SPARSE) {
        if (sparseSet.size() + hll.sparseSet.size() > MaxThreshold) {
          convertToNormal();
          hll.convertToNormal();
        }
 else {
          sparseSet=mergeEstimators(hll);
        }
      }
 else {
        convertToNormal();
      }
    }
 else {
      if (hll.format == Format.SPARSE) {
        hll.convertToNormal();
      }
    }
    if (format != Format.SPARSE) {
      for (int b=0; b < registerSet.count; b++) {
        registerSet.set(b,Math.max(registerSet.get(b),hll.registerSet.get(b)));
      }
    }
  }
  if (format == Format.SPARSE) {
    return new HyperLogLogPlus(p,sp,sparseSet);
  }
  HyperLogLogPlus outEst=new HyperLogLogPlus(p,sp,registerSet);
  outEst.format=Format.NORMAL;
  return outEst;
}
Program: 1384
Project: 1384
Buggy source:
private int encodeHash(long x,int p,int sp){
  int idx=(int)(x >>> (64 - sp));
  int zeroTest=idx << (7 + p);
  if (zeroTest == 0) {
    long rho=x & ((1l << (31 - sp)) - 1);
    return (int)(idx << 6 | (Long.numberOfLeadingZeros(rho)) << 1 | 1l);
  }
 else {
    return idx << 7;
  }
}

Fixed version (ground truth):
private int encodeHash(long x,int p,int sp){
  int idx=(int)(x >>> (64 - sp));
  int zeroTest=idx << (7 + p);
  if (zeroTest == 0) {
    final int runLength=Long.numberOfLeadingZeros((x << this.p) | (1 << (this.p - 1))) + 1;
    int invrl=runLength ^ 63;
    return (((idx << 6) | invrl) << 1) | 1;
  }
 else {
    return idx << 7;
  }
}
Program: 1385
Project: 1385
Buggy source:
private int decodeRunLength(int k){
  if ((k & 1) != 0) {
    return ((k & 127) + (sp - p));
  }
 else {
    return Integer.numberOfLeadingZeros(k << p) + 1;
  }
}

Fixed version (ground truth):
private int decodeRunLength(int k){
  if ((k & 1) != 0) {
    return ((k >>> 1) & 63) ^ 63;
  }
 else {
    return Integer.numberOfLeadingZeros(k << p) + 1;
  }
}
Program: 1386
Project: 1386
Buggy source:
public HyperLogLogPlus(int p,int sp,List<byte[]> Set,RegisterSet registerSet){
  this.p=p;
  this.sp=sp;
  this.m=(int)Math.pow(2,p);
  this.sm=(int)Math.pow(2,sp);
  this.registerSet=registerSet;
  this.sparseSet=Set;
switch (p) {
case 4:
    alphaMM=0.673 * m * m;
  break;
case 5:
alphaMM=0.697 * m * m;
break;
case 6:
alphaMM=0.709 * m * m;
break;
default :
alphaMM=(0.7213 / (1 + 1.079 / m)) * m * m;
}
}

Fixed version (ground truth):
public HyperLogLogPlus(int p,int sp,List<byte[]> sparseSet,RegisterSet registerSet){
  this.p=p;
  this.sp=sp;
  this.m=(int)Math.pow(2,p);
  this.sm=(int)Math.pow(2,sp);
  this.registerSet=registerSet;
  this.sparseSet=sparseSet;
switch (p) {
case 4:
    alphaMM=0.673 * m * m;
  break;
case 5:
alphaMM=0.697 * m * m;
break;
case 6:
alphaMM=0.709 * m * m;
break;
default :
alphaMM=(0.7213 / (1 + 1.079 / m)) * m * m;
}
}
Program: 1387
Project: 1387
Buggy source:
private boolean conditionalAdd(Map<Integer,Integer> tmpElementMap,int next,List<byte[]> newSet){
  int idx=getSparseIndex(next);
  int r=decodeRunLength(next);
  if (tmpElementMap.containsKey(idx) && tmpElementMap.get(idx) >= r) {
    return false;
  }
  tmpElementMap.put(idx,r);
  if (newSet.size() == 0) {
    delta=next;
  }
  newSet.add(zipInt(next));
  return true;
}

Fixed version (ground truth):
private boolean conditionalAdd(Map<Integer,Integer> tmpElementMap,int next,List<byte[]> newSet){
}
Program: 1388
Project: 1388
Buggy source:
@Test public void testMerge_ManySparse() throws CardinalityMergeException {
  int numToMerge=20;
  int bits=18;
  int cardinality=10000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  assertTrue(mergedEstimate >= expectedCardinality - (3 * se));
  assertTrue(mergedEstimate <= expectedCardinality + (3 * se));
}

Fixed version (ground truth):
@Test public void testMerge_ManySparse() throws CardinalityMergeException {
  int numToMerge=20;
  int bits=18;
  int cardinality=10000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  double err=Math.abs(mergedEstimate - expectedCardinality) / (double)expectedCardinality;
  System.out.println(err);
  assertTrue(err < .1);
  assertTrue(mergedEstimate >= expectedCardinality - (3 * se));
  assertTrue(mergedEstimate <= expectedCardinality + (3 * se));
}
Program: 1389
Project: 1389
Buggy source:
public void mergeTmp(){
  if (tmpSet.size() != 0) {
    Collections.sort(tmpSet);
    sparseSet=merge(sparseSet,tmpSet);
    tmpSet.clear();
  }
}

Fixed version (ground truth):
public void mergeTmp(){
  if (tmpSet.size() != 0) {
    resetDelta();
    Collections.sort(tmpSet);
    sparseSet=merge(sparseSet,tmpSet);
    tmpSet.clear();
  }
}
Program: 1390
Project: 1390
Buggy source:
private List<byte[]> mergeEstimators(HyperLogLogPlus other){
  other.mergeTmp();
  mergeTmp();
  List<byte[]> set=sparseSet;
  List<byte[]> tmp=other.sparseSet;
  List<byte[]> newSet=new ArrayList<byte[]>();
  Map<Integer,Integer> indexMap=new HashMap<Integer,Integer>();
  int seti=0;
  int tmpi=0;
  while (seti < set.size() || tmpi < tmp.size()) {
    if (seti >= set.size()) {
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      conditionalAdd(indexMap,tmpVal,newSet);
      tmpi++;
    }
 else     if (tmpi >= tmp.size()) {
      int setVal=unzipInt(set.get(seti));
      conditionalAdd(indexMap,setVal,newSet);
      seti++;
    }
 else {
      int setVal=unzipInt(set.get(seti));
      int tmpVal=other.unzipInt(tmp.get(tmpi));
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        int min=Math.min(setVal,tmpVal);
        conditionalAdd(indexMap,min,newSet);
        tmpi++;
        seti++;
      }
 else       if (setVal < tmpVal) {
        conditionalAdd(indexMap,setVal,newSet);
        seti++;
      }
 else {
        conditionalAdd(indexMap,tmpVal,newSet);
        tmpi++;
      }
    }
  }
  old_delta=delta;
  return newSet;
}

Fixed version (ground truth):
private List<byte[]> mergeEstimators(HyperLogLogPlus other){
  other.mergeTmp();
  mergeTmp();
  resetDelta();
  other.resetDelta();
  List<byte[]> set=sparseSet;
  List<byte[]> tmp=other.sparseSet;
  List<byte[]> newSet=new ArrayList<byte[]>();
  int seti=0;
  int tmpi=0;
  while (seti < set.size() || tmpi < tmp.size()) {
    if (seti >= set.size()) {
      int tmpVal=other.deltaRead(tmp,tmpi);
      deltaAdd(newSet,tmpVal);
      tmpi++;
    }
 else     if (tmpi >= tmp.size()) {
      int setVal=deltaRead(set,seti);
      deltaAdd(newSet,setVal);
      seti++;
    }
 else {
      int setVal=deltaRead(set,seti);
      int tmpVal=other.deltaRead(tmp,tmpi);
      if (getSparseIndex(setVal) == getSparseIndex(tmpVal)) {
        int min=Math.min(setVal,tmpVal);
        deltaAdd(newSet,min);
        tmpi++;
        seti++;
      }
 else       if (setVal < tmpVal) {
        deltaAdd(newSet,setVal);
        seti++;
      }
 else {
        deltaAdd(newSet,tmpVal);
        tmpi++;
      }
    }
  }
  return newSet;
}
Program: 1391
Project: 1391
Buggy source:
private void convertToNormal(){
  mergeTmp();
  for (  byte[] bytes : sparseSet) {
    int k=unzipInt(bytes);
    int idx=getIndex(k,p);
    int r=decodeRunLength(k);
    if (registerSet.get(idx) < r) {
      registerSet.set(idx,r);
    }
  }
  format=Format.NORMAL;
  tmpSet.clear();
  sparseSet=null;
}

Fixed version (ground truth):
private void convertToNormal(){
  mergeTmp();
  resetDelta();
  for (int i=0; i < sparseSet.size(); i++) {
    int k=deltaRead(sparseSet,i);
    int idx=getIndex(k,p);
    int r=decodeRunLength(k);
    if (registerSet.get(idx) < r) {
      registerSet.set(idx,r);
    }
  }
  format=Format.NORMAL;
  tmpSet.clear();
  sparseSet=null;
}
Program: 1392
Project: 1392
Buggy source:
/** 
 * @throws IllegalArgumentException if variable-length value does not terminateafter 5 bytes have been read
 * @throws IOException if {@link DataInput} throws {@link IOException}
 * @see #readSignedVarLong(DataInput)
 */
public static int readSignedVarInt(DataInput in) throws IOException {
  int raw=readUnsignedVarInt(in);
  int temp=(((raw << 31) >> 31) ^ raw) >> 1;
  return temp ^ (raw & (1 << 31));
}

Fixed version (ground truth):
public static int readSignedVarInt(byte[] bytes){
  int raw=readUnsignedVarInt(bytes);
  int temp=(((raw << 31) >> 31) ^ raw) >> 1;
  return temp ^ (raw & (1 << 31));
}
Program: 1393
Project: 1393
Buggy source:
/** 
 * @see #writeSignedVarLong(long,DataOutput)
 */
public static void writeSignedVarInt(int value,DataOutput out) throws IOException {
  writeUnsignedVarInt((value << 1) ^ (value >> 31),out);
}

Fixed version (ground truth):
public static byte[] writeSignedVarInt(int value){
  return writeUnsignedVarInt((value << 1) ^ (value >> 31));
}
Program: 1394
Project: 1394
Buggy source:
@Test public void testMerge_Sparse() throws CardinalityMergeException {
  int numToMerge=4;
  int bits=18;
  int cardinality=1000000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  double err=Math.abs(mergedEstimate - expectedCardinality) / (double)expectedCardinality;
  System.out.println(err);
  assertTrue(err < .1);
}

Fixed version (ground truth):
@Test public void testMerge_Sparse() throws CardinalityMergeException {
  int numToMerge=4;
  int bits=18;
  int cardinality=1000000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  double err=Math.abs(mergedEstimate - expectedCardinality) / (double)expectedCardinality;
  System.out.println("String_Node_Str" + err);
  assertTrue(err < .1);
  assertTrue(mergedEstimate >= expectedCardinality - (3 * se));
  assertTrue(mergedEstimate <= expectedCardinality + (3 * se));
}
Program: 1395
Project: 1395
Buggy source:
@Test public void testMerge_ManySparse() throws CardinalityMergeException {
  int numToMerge=20;
  int bits=18;
  int cardinality=10000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  double err=Math.abs(mergedEstimate - expectedCardinality) / (double)expectedCardinality;
  System.out.println(err);
  assertTrue(err < .1);
  assertTrue(mergedEstimate >= expectedCardinality - (3 * se));
  assertTrue(mergedEstimate <= expectedCardinality + (3 * se));
}

Fixed version (ground truth):
@Test public void testMerge_ManySparse() throws CardinalityMergeException {
  int numToMerge=20;
  int bits=18;
  int cardinality=10000;
  HyperLogLogPlus[] hyperLogLogs=new HyperLogLogPlus[numToMerge];
  HyperLogLogPlus baseline=new HyperLogLogPlus(bits,25);
  for (int i=0; i < numToMerge; i++) {
    hyperLogLogs[i]=new HyperLogLogPlus(bits,25);
    for (int j=0; j < cardinality; j++) {
      double val=Math.random();
      hyperLogLogs[i].offer(val);
      baseline.offer(val);
    }
  }
  long expectedCardinality=numToMerge * cardinality;
  HyperLogLogPlus hll=hyperLogLogs[0];
  hyperLogLogs=Arrays.asList(hyperLogLogs).subList(1,hyperLogLogs.length).toArray(new HyperLogLogPlus[0]);
  long mergedEstimate=hll.merge(hyperLogLogs).cardinality();
  double se=expectedCardinality * (1.04 / Math.sqrt(Math.pow(2,bits)));
  System.out.println("String_Node_Str" + mergedEstimate + "String_Node_Str"+ (expectedCardinality - (3 * se))+ "String_Node_Str"+ (expectedCardinality + (3 * se)));
  assertTrue(mergedEstimate >= expectedCardinality - (3 * se));
  assertTrue(mergedEstimate <= expectedCardinality + (3 * se));
}
Program: 1396
Project: 1396
Buggy source:
@Test public void testHighCardinality(){
  long start=System.currentTimeMillis();
  HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(18,25);
  int size=10000000;
  for (int i=0; i < size; i++) {
    hyperLogLogPlus.offer(TestICardinality.streamElement(i));
  }
  System.out.println("String_Node_Str" + size + "String_Node_Str"+ hyperLogLogPlus.cardinality()+ "String_Node_Str"+ (System.currentTimeMillis() - start));
  long estimate=hyperLogLogPlus.cardinality();
  double err=Math.abs(estimate - size) / (double)size;
  System.out.println(err);
  assertTrue(err < .1);
}

Fixed version (ground truth):
@Test public void testHighCardinality(){
  long start=System.currentTimeMillis();
  HyperLogLogPlus hyperLogLogPlus=new HyperLogLogPlus(18,25);
  int size=10000000;
  for (int i=0; i < size; i++) {
    hyperLogLogPlus.offer(TestICardinality.streamElement(i));
  }
  System.out.println("String_Node_Str" + size + "String_Node_Str"+ hyperLogLogPlus.cardinality()+ "String_Node_Str"+ (System.currentTimeMillis() - start));
  long estimate=hyperLogLogPlus.cardinality();
  double err=Math.abs(estimate - size) / (double)size;
  System.out.println("String_Node_Str" + err);
  assertTrue(err < .1);
}
Program: 1397
Project: 1397
Buggy source:
private int getIndex(int k,int p){
  if ((k & 1) != 0) {
    return (k >>> 6 & ((1 << p) - 1));
  }
 else {
    return (k >>> 1 & ((1 << p) - 1));
  }
}

Fixed version (ground truth):
private int getIndex(int k,int p){
  if ((k & 1) != 0) {
    return (k >>> 6 & ((1 << p) - 1));
  }
 else {
    return (k >>> (1 + (sp - p)));
  }
}
Program: 1398
Project: 1398
Buggy source:
private int decodeRunLength(int k){
  if ((k & (1L)) != 0) {
    return ((k >>> 1) & ((1 << 7) - 1)) + (sp - p);
  }
 else {
    return Integer.numberOfLeadingZeros((k >>> 1) & ((1 << (sp - p - 1)) - 1)) + 1;
  }
}

Fixed version (ground truth):
private int decodeRunLength(int k){
  if ((k & (1L)) != 0) {
    return ((k >>> 1) & ((1 << 7) - 1)) + (sp - p);
  }
 else {
    return Integer.numberOfLeadingZeros((k >>> 1) & ((1 << (sp - p)) - 1)) + 1;
  }
}