All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.pinecone.utils.SparseIndicesConverter Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package io.pinecone.utils;

import io.pinecone.exceptions.PineconeValidationException;

import java.util.ArrayList;
import java.util.List;

public class SparseIndicesConverter {
    public static List convertUnsigned32IntToSigned32Int(List unsigned32IntValues) {
        List int32Values = new ArrayList<>();
        for (Long value : unsigned32IntValues) {
            if (value < 0 || value > 0xFFFFFFFFL) {
                throw new PineconeValidationException("Sparse indices are out of range for unsigned 32-bit integers.");
            }
            int32Values.add(value.intValue());
        }
        return int32Values;
    }

    public static List convertSigned32IntToUnsigned32Int(List signed32IntValues) {
        List uint32Values = new ArrayList<>();
        for (Integer value : signed32IntValues) {
            if (value < 0) {
                uint32Values.add((long) value + 4294967296L);
            } else {
                uint32Values.add((long) value);
            }
        }
        return uint32Values;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy