Example usage for java.nio IntBuffer put

List of usage examples for java.nio IntBuffer put

Introduction

In this page you can find the example usage for java.nio IntBuffer put.

Prototype

public abstract IntBuffer put(int index, int i);

Source Link

Document

Write a int to the specified index of this buffer; the position is not changed.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntBuffer bb = IntBuffer.allocate(10);
    bb.put(1, 100);
    System.out.println(bb.arrayOffset());

}

From source file:edu.iu.daal_pca.Service.java

private static KeyValueDataCollection computeOutBlocks(DaalContext context, int nNodes,
        CSRNumericTable dataBlock, long[] dataBlockPartition) {
    long nRows = dataBlock.getNumberOfRows();
    int iNRows = (int) nRows;
    boolean[] blockIdFlags = new boolean[iNRows * nNodes];
    for (int i = 0; i < iNRows * nNodes; i++) {
        blockIdFlags[i] = false;//  w  w  w.j av a2  s .com
    }

    long[] rowOffsets = dataBlock.getRowOffsetsArray();
    long[] colIndices = dataBlock.getColIndicesArray();

    for (long i = 0; i < nRows; i++) {
        for (long j = rowOffsets[(int) i] - 1; j < rowOffsets[(int) i + 1] - 1; j++) {
            for (int k = 1; k < nNodes + 1; k++) {
                if (dataBlockPartition[k - 1] <= colIndices[(int) j] - 1
                        && colIndices[(int) j] - 1 < dataBlockPartition[k]) {
                    blockIdFlags[(k - 1) * iNRows + (int) i] = true;
                }
            }
        }
    }

    long[] nNotNull = new long[nNodes];
    for (int i = 0; i < nNodes; i++) {
        nNotNull[i] = 0;
        for (int j = 0; j < iNRows; j++) {
            if (blockIdFlags[i * iNRows + j]) {
                nNotNull[i] += 1;
            }
        }
    }
    KeyValueDataCollection result = new KeyValueDataCollection(context);

    for (int i = 0; i < nNodes; i++) {
        HomogenNumericTable indicesTable = new HomogenNumericTable(context, Integer.class, 1, nNotNull[i],
                NumericTable.AllocationFlag.DoAllocate);
        IntBuffer indicesBuffer = IntBuffer.allocate((int) nNotNull[i]);
        indicesBuffer = indicesTable.getBlockOfRows(0, nNotNull[i], indicesBuffer);
        int indexId = 0;
        for (int j = 0; j < iNRows; j++) {
            if (blockIdFlags[i * iNRows + j]) {
                indicesBuffer.put(indexId, j);
                indexId++;
            }
        }
        indicesTable.releaseBlockOfRows(0, nNotNull[i], indicesBuffer);
        result.set(i, indicesTable);
    }
    return result;
}

From source file:Main.java

static void scaleHalf(IntBuffer in, int w, int h, IntBuffer out, int rotate) {
    for (int i = 0; i < w / 2; ++i) {
        for (int j = 0; j < h / 2; ++j) {
            int k = w * 2 * j + 2 * i;
            int pixel00 = in.get(k);
            int pixel01 = in.get(k + 1);
            int pixel10 = in.get(k + w);
            int pixel11 = in.get(k + w + 1);

            if (rotate != 0) {
                pixel00 = Integer.rotateLeft(pixel00, rotate);
                pixel01 = Integer.rotateLeft(pixel01, rotate);
                pixel10 = Integer.rotateLeft(pixel10, rotate);
                pixel11 = Integer.rotateLeft(pixel11, rotate);
            }/*from w  ww.j  av  a2  s  . c  o m*/

            int pixel = average4RGBA(pixel00, pixel01, pixel10, pixel11);

            if (rotate != 0) {
                pixel = Integer.rotateRight(pixel, rotate);
            }

            out.put(w / 2 * j + i, pixel);
        }
    }
}

From source file:com.l2jfree.gameserver.geodata.pathfinding.geonodes.GeoPathFinding.java

private void LoadPathNodeFile(byte rx, byte ry) {
    String fname = "./data/pathnode/" + rx + "_" + ry + ".pn";
    short regionoffset = getRegionOffset(rx, ry);
    _log.info("PathFinding Engine: - Loading: " + fname + " -> region offset: " + regionoffset + "X: " + rx
            + " Y: " + ry);
    File Pn = new File(fname);
    int node = 0, size, index = 0;
    FileChannel roChannel = null;
    try {/*w ww  .j  a  v  a 2  s. c o m*/
        // Create a read-only memory-mapped file
        roChannel = new RandomAccessFile(Pn, "r").getChannel();
        size = (int) roChannel.size();
        MappedByteBuffer nodes;
        if (Config.FORCE_GEODATA) //Force O/S to Loads this buffer's content into physical memory.
            //it is not guarantee, because the underlying operating system may have paged out some of the buffer's data
            nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size).load();
        else
            nodes = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, size);

        // Indexing pathnode files, so we will know where each block starts
        IntBuffer indexs = IntBuffer.allocate(65536);

        while (node < 65536) {
            byte layer = nodes.get(index);
            indexs.put(node++, index);
            index += layer * 10 + 1;
        }
        _pathNodesIndex.set(regionoffset, indexs);
        _pathNodes.set(regionoffset, nodes);
    } catch (Exception e) {
        _log.warn("Failed to Load PathNode File: " + fname + "\n", e);
    } finally {
        try {
            if (roChannel != null)
                roChannel.close();
        } catch (Exception e) {
        }
    }

}