buffer.getInt()로 다음 값을 읽어 PriorityQueue의 Comparator와 함께 버퍼를 사용하고 있습니다 (스트림 요소를 비교하기 위해). 불행히도, 다음에 그것을 비교할 때, 나는이 값을 잃어 가고 있습니다. 그래서, int에서 java의 버퍼로 돌아갈 수 있습니까? 나는 putInt와 같은 매끈함을 시도했지만 그것은 다르다. 미리 감사드립니다.Java int를 buffer.getInt로 반환합니다.
내가 정렬
package sort;
import java.util.Comparator;
import inputStream.Mapping.*;
public class extComparator implements Comparator<MapInp>{
@Override
public int compare(MapInp o1, MapInp o2) {
Integer a = o1.readNext();
Integer b = o2.readNext();
return a.compareTo(b);
}
}
그리고 외부 합병의 구현에 노력하고, 나는 또 다른 파일을 사용하고 있습니다 :
heap = new PriorityQueue<MapInp>(numOfFilesNM/d, new extComparator());
heap.add(new MapInp("data/inp.data"));
....
int t = heap.peek().readNext(); //so, here I am comparing values and loosing the value
MapInt readNext :
public int readNext() {
if(fileLen-pos-lastPos>bufSize) bufCap = bufSize;
else bufCap = (int) (fileLen-pos-lastPos);
if(buffer.position()==buffer.capacity()) {
lastPos+=pos;
buffer.clear();
try {
buffer = inpCh.map(FileChannel.MapMode.READ_ONLY, lastPos,bufCap);
}
catch (IOException e) {
e.printStackTrace();
}
pos=0;
}
pos+=4;
return buffer.getInt();
}
를 불행하게도, 나는 아직 해결하지 못했습니다. 죄송 합니다만, 전체 코드를 공유하는 것이 더 좋을 수 있습니다 : https://www.dropbox.com/s/zqceyg8j6u9kvg7/test.zip?dl=0
코드를 표시하십시오. https://stackoverflow.com/help/mcve – ThomasEdwin
@ThomasEdwin이 추가되었습니다. 가장 큰 문제는 스트림에서 두 값을 비교하는 방법입니다. 이제 나는 그것을 할 수 있고 느슨한 가치를 가질 수있다. 값을 버퍼로 되돌릴 수 있기를 바랍니다. – Luno