簡體   English   中英

如何在 Java 16 中將 UUID 轉換為 jdk.incubator.vector.Vector,反之亦然

[英]How to convert UUID into jdk.incubator.vector.Vector and vice versa in Java 16

從 UUID 轉換為 jdk.incubator.vector.Vector(不確定哪種基本類型,可能是 Float?)的最佳方法是什么,反之亦然?

我不確定“最佳”方式,因為這取決於您之后需要對向量執行的操作以及您的機器架構,但是 UUID 可以轉換為兩個元素的 64 位整數向量,取其使用UUID.getLeastSignificantBits()UUID.getMostSignificantBits() 的兩半:

UUID uuid = UUID.randomUUID();
LongVector vector = LongVector.fromArray(LongVector.SPECIES_128, new long[] {uuid.getLeastSignificantBits(), uuid.getMostSignificantBits()}, 0);

反過來,使用LongVector.lane()

UUID x = new UUID(vector.lane(1), vector.lane(0));

(假設元素排序與第一個示例相同)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM