简体   繁体   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?)的最佳方法是什么,反之亦然?

I'm not sure about the 'best' way since that depends on what operations you need to do on the vector afterwards and possibly your machine architecture, but a UUID could be turned into a two-element 64-bit-integer vector taking its two halves using UUID.getLeastSignificantBits() and UUID.getMostSignificantBits() :我不确定“最佳”方式,因为这取决于您之后需要对向量执行的操作以及您的机器架构,但是 UUID 可以转换为两个元素的 64 位整数向量,取其使用UUID.getLeastSignificantBits()UUID.getMostSignificantBits() 的两半:

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

To go the other way, use LongVector.lane() : 反过来,使用LongVector.lane()

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

(assuming element ordering was the same as the first example) (假设元素排序与第一个示例相同)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM