DataBufferWindow
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
คอนเทนเนอร์ที่ไม่แน่นอนสำหรับการดูส่วนหนึ่งของ DataBuffer
หน้าต่างบัฟเฟอร์ข้อมูลมีขนาดคงที่และสามารถ "slide"
ไปตามบัฟเฟอร์เพื่อให้มีมุมมองที่แตกต่างกันของข้อมูลโดยไม่ต้องจัดสรรอินสแตนซ์บัฟเฟอร์ใหม่ เช่นเดียวกับ offset(long)
ซึ่งช่วยปรับปรุงประสิทธิภาพโดยรวมเมื่อมีการทำซ้ำบ่อยครั้ง ตัวอย่างเช่น:
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;
}
}
อินสแตนซ์ DataBufferWindow
มีสถานะและไม่ปลอดภัยสำหรับเธรด
วิธีการสาธารณะ
นามธรรมบี | บัฟเฟอร์ () ส่งกลับบัฟเฟอร์ที่สนับสนุนหน้าต่างนี้ |
ยาวเป็นนามธรรม | ชดเชย () ส่งกลับค่าชดเชยปัจจุบันของหน้าต่างนี้ในบัฟเฟอร์เดิม |
ยาวเป็นนามธรรม | ขนาด () ส่งกลับขนาดของหน้าต่างบัฟเฟอร์นี้ |
บทคัดย่อ DataBufferWindow <B> | สไลด์ (ก้าวยาว) ย้ายหน้าต่างขององค์ประกอบ step ในบัฟเฟอร์เดิม |
บทคัดย่อ DataBufferWindow <B> | slideTo (ดัชนียาว) ย้ายหน้าต่างไปยังตำแหน่งที่กำหนดในบัฟเฟอร์เดิม |
วิธีการสาธารณะ
บัฟเฟอร์ B บทคัดย่อสาธารณะ ()
ส่งกลับบัฟเฟอร์ที่สนับสนุนหน้าต่างนี้
แต่ละอินสแตนซ์ของหน้าต่างมีบัฟเฟอร์ของตัวเองเพื่อให้ดู DataBuffer
ดั้งเดิมได้ บัฟเฟอร์จะกลายพันธุ์เมื่อหน้าต่างเลื่อนไปที่ออฟเซ็ตที่แตกต่างกัน ตัวอย่างเช่น:
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());
ออฟเซ็ต ยาวนามธรรมสาธารณะ ()
ส่งกลับค่าชดเชยปัจจุบันของหน้าต่างนี้ในบัฟเฟอร์เดิม
ขนาด ยาวนามธรรมสาธารณะ ()
ส่งกลับขนาดของหน้าต่างบัฟเฟอร์นี้
สไลด์ DataBufferWindow นามธรรมสาธารณะ <B> (ขั้นตอนยาว)
ย้ายหน้าต่างขององค์ประกอบ step
ในบัฟเฟอร์เดิม
ขนาดของหน้าต่างยังคงเท่าเดิมและออฟเซ็ตของมันถูกตั้งค่าเป็น offset() + step
หาก step
เป็นบวก หน้าต่างจะเลื่อนไปข้างหน้า หากเป็นลบก็จะเลื่อนถอยหลัง
พารามิเตอร์
ขั้นตอน | ค่าที่จะเพิ่มให้กับออฟเซ็ตปัจจุบันของหน้าต่างนี้ |
---|
ขว้าง
IndexOutOfBoundsException | หากไม่สามารถเลื่อนหน้าต่างได้เนื่องจากเกินขีดจำกัดบัฟเฟอร์เดิม |
---|
สาธารณะบทคัดย่อ DataBufferWindow <B> slideTo (ดัชนียาว)
ย้ายหน้าต่างไปยังตำแหน่งที่กำหนดในบัฟเฟอร์เดิม
ขนาดของหน้าต่างยังคงเท่าเดิมและออฟเซ็ตถูกตั้งค่าเป็น index
ดังนั้นการเข้าถึงค่าของ buffer()
ที่ดัชนี x
จะส่งกลับค่าที่ index + x
ในบัฟเฟอร์ดั้งเดิม
พารามิเตอร์
ดัชนี | ออฟเซ็ตใหม่สำหรับหน้าต่างนี้ |
---|
ขว้าง
IndexOutOfBoundsException | หากไม่สามารถเลื่อนหน้าต่างได้เนื่องจากเกินขีดจำกัดบัฟเฟอร์เดิม |
---|
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 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|---------------------------|--------------------------------------------------------------------------------|"]]