DataBufferWindow
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Các lớp con gián tiếp đã biết |
Một vùng chứa có thể thay đổi để xem một phần của DataBuffer
.
Cửa sổ bộ đệm dữ liệu có kích thước cố định và có thể "slide"
dọc theo bộ đệm để cung cấp các chế độ xem dữ liệu khác nhau mà không cần phân bổ phiên bản bộ đệm mới, giống như offset(long)
. Điều này cải thiện hiệu suất tổng thể khi thao tác này được lặp lại thường xuyên. Ví dụ:
IntDataBuffer bufferA = DataBuffers.ofInts(1024);
// ... init buffer data
IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);
// Return the index of the first occurrence of bufferB in bufferA using a sliding window
DataBufferWindow<IntDataBuffer> windowA = bufferA.window(4);
for (int i = 0; i < bufferA.size() - bufferB.size(); ++i) {
if (windowA.slideTo(i).buffer().equals(bufferB)) {
return i;
}
}
Các phiên bản DataBufferWindow
có trạng thái và không an toàn theo luồng.
Phương pháp công khai
trừu tượng B | bộ đệm () Trả về bộ đệm sao lưu cửa sổ này. |
trừu tượng dài | bù lại () Trả về offset hiện tại của cửa sổ này trong bộ đệm ban đầu. |
trừu tượng dài | kích cỡ () Trả về kích thước của cửa sổ bộ đệm này. |
trừu tượng DataBufferWindow <B> | trượt (bước dài) Di chuyển cửa sổ của các phần tử step trong bộ đệm ban đầu. |
trừu tượng DataBufferWindow <B> | slideTo (chỉ mục dài) Di chuyển cửa sổ tại vị trí đã cho trong bộ đệm ban đầu. |
Phương pháp công khai
Bộ đệm B trừu tượng công khai ()
Trả về bộ đệm sao lưu cửa sổ này.
Mỗi phiên bản cửa sổ có bộ đệm riêng cung cấp chế độ xem trên DataBuffer
gốc. Bộ đệm bị thay đổi khi cửa sổ trượt sang các độ lệch khác nhau. Ví dụ:
IntDataBuffer buffer = DataBuffers.of(0, 1, 2, 3);
DataBufferWindow<IntDataBuffer> window = buffer.window(0, 2);
IntDataBuffer windowBuffer = window.buffer();
assertEquals(0, windowBuffer.getInt(0));
assertEquals(1, windowBuffer.getInt(1));
window.slideTo(2);
assertEquals(2, windowBuffer.getInt(0));
assertEquals(3, windowBuffer.getInt(1));
assertSame(windowBuffer, window.buffer());
phần bù dài trừu tượng công khai ()
Trả về offset hiện tại của cửa sổ này trong bộ đệm ban đầu.
kích thước dài trừu tượng công khai ()
Trả về kích thước của cửa sổ bộ đệm này.
slide trừu tượng công khai DataBufferWindow <B> (bước dài)
Di chuyển cửa sổ của các phần tử step
trong bộ đệm ban đầu.
Kích thước của cửa sổ vẫn giữ nguyên và phần bù của nó được đặt thành offset() + step
. Nếu step
là dương thì cửa sổ sẽ trượt về phía trước. Nếu nó âm, nó sẽ trượt về phía sau.
Thông số
bước chân | giá trị để thêm vào phần bù hiện tại của cửa sổ này |
---|
Ném
IndexOutOfBoundsNgoại lệ | nếu cửa sổ không thể trượt được vì nó vượt quá giới hạn bộ đệm ban đầu |
---|
tóm tắt công khai DataBufferWindow <B> slideTo (chỉ mục dài)
Di chuyển cửa sổ tại vị trí đã cho trong bộ đệm ban đầu.
Kích thước của cửa sổ vẫn giữ nguyên và phần bù của nó được đặt thành index
, do đó việc truy cập giá trị của buffer()
tại chỉ mục x
sẽ trả về giá trị tại index + x
trong bộ đệm ban đầu.
Thông số
chỉ mục | phần bù mới cho cửa sổ này |
---|
Ném
IndexOutOfBoundsNgoại lệ | nếu cửa sổ không thể trượt vì nó vượt quá giới hạn bộ đệm ban đầu |
---|
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],null,["# DataBufferWindow\n\npublic interface **DataBufferWindow** \n\n|---|---|---|\n| Known Indirect Subclasses [AbstractDataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/impl/buffer/AbstractDataBufferWindow)\\\u003cB extends [DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer)\\\u003c?\\\u003e\\\u003e |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---| | [AbstractDataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/impl/buffer/AbstractDataBufferWindow)\\\u003cB extends [DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer)\\\u003c?\\\u003e\\\u003e | | |||\n\nA mutable container for viewing part of a [DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer).\n\nData buffer windows have a fixed size and can [\"slide\"](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#slide(long))\nalong a buffer to provide different views of the data without allocating a new buffer instance,\nlike [offset(long)](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer#offset(long)) does. This improves overall performance when this operation\nis repeated frequently. For example:\n\n IntDataBuffer bufferA = DataBuffers.ofInts(1024);\n // ... init buffer data\n IntDataBuffer bufferB = DataBuffers.ofInts(1, 2, 3, 4);\n\n // Return the index of the first occurrence of bufferB in bufferA using a sliding window\n DataBufferWindow\u003cIntDataBuffer\u003e windowA = bufferA.window(4);\n for (int i = 0; i \u003c bufferA.size() - bufferB.size(); ++i) {\n if (windowA.slideTo(i).buffer().equals(bufferB)) {\n return i;\n \n }\n }\n\n`DataBufferWindow` instances are stateful and not thread-safe.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n### Public Methods\n\n|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| abstract B | [buffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#buffer())() Returns the buffer backing this window. |\n| abstract long | [offset](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#offset())() Returns the current offset of this window in the original buffer. |\n| abstract long | [size](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#size())() Returns the size of this buffer window. |\n| abstract [DataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow)\\\u003cB\\\u003e | [slide](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#slide(long))(long step) Moves the window of `step` elements in the original buffer. |\n| abstract [DataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow)\\\u003cB\\\u003e | [slideTo](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#slideTo(long))(long index) Moves the window at the given position in the original buffer. |\n\nPublic Methods\n--------------\n\n#### public abstract B\n**buffer**\n()\n\nReturns the buffer backing this window.\n\nEach window instance has it's own buffer providing a view onto the original\n[DataBuffer](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBuffer). The buffers are mutated when the window slides to different offsets.\nFor example:\n\n IntDataBuffer buffer = DataBuffers.of(0, 1, 2, 3);\n DataBufferWindow\u003cIntDataBuffer\u003e window = buffer.window(0, 2);\n\n IntDataBuffer windowBuffer = window.buffer();\n assertEquals(0, windowBuffer.getInt(0));\n assertEquals(1, windowBuffer.getInt(1));\n\n window.slideTo(2);\n assertEquals(2, windowBuffer.getInt(0));\n assertEquals(3, windowBuffer.getInt(1));\n assertSame(windowBuffer, window.buffer());\n \n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n##### Returns\n\n- this window's buffer \n\n#### public abstract long\n**offset**\n()\n\nReturns the current offset of this window in the original buffer. \n\n#### public abstract long\n**size**\n()\n\nReturns the size of this buffer window. \n\n#### public abstract [DataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow)\\\u003cB\\\u003e\n**slide**\n(long step)\n\nMoves the window of `step` elements in the original buffer.\n\nThe size of the window remains the same and its offset is set to `offset() + step`.\nIf `step` is positive, then the window will slide forward. If it is negative, it will\nslide backward.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| step | value to add to the current offset of this window |\n|------|---------------------------------------------------|\n\n##### Returns\n\n- this instance \n\n##### Throws\n\n| IndexOutOfBoundsException | if the window cannot be slid because it goes beyond the original buffer limits |\n|---------------------------|--------------------------------------------------------------------------------|\n\n#### public abstract [DataBufferWindow](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow)\\\u003cB\\\u003e\n**slideTo**\n(long index)\n\nMoves the window at the given position in the original buffer.\n\nThe size of the window remains the same and its offset is set to `index`, so that\naccessing the value of [buffer()](/jvm/api_docs/java/org/tensorflow/ndarray/buffer/DataBufferWindow#buffer()) at index `x` will return the value at\n`index + x` in the original buffer.\n\n\u003cbr /\u003e\n\n##### Parameters\n\n| index | new offset for this window |\n|-------|----------------------------|\n\n##### Returns\n\n- this instance \n\n##### Throws\n\n| IndexOutOfBoundsException | if the window cannot be slid because it goes beyond the original buffer limits |\n|---------------------------|--------------------------------------------------------------------------------|"]]