Skip to content

Commit

Permalink
index_idmap.go: go binding added
Browse files Browse the repository at this point in the history
IndexIDMap was missing from the go bindings, even though is is important
to wrap a flat index in if addWithID functionality is required.
  • Loading branch information
orihabAnyvision committed Jul 28, 2021
1 parent 3e856bb commit 53ce01f
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions index_idmap.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package faiss

/*
#include <faiss/c_api/MetaIndexes_c.h>
*/
import "C"
import (
"errors"
)

type IndexIDMapWrapper struct {
Index
cpointer **C.FaissIndex
}

func NewIndexIDMap(index *IndexFlat) (*IndexIDMapWrapper, error) {
var indexMapPointer *C.FaissIndexIDMap
var pointerToIndexMapPointer **C.FaissIndexIDMap
pointerToIndexMapPointer = &indexMapPointer
wrapper := IndexIDMapWrapper{cpointer: &indexMapPointer}
if C.faiss_IndexIDMap_new(pointerToIndexMapPointer, index.cPtr()) != 0 {
return nil, errors.New("Error occurred while initializing IndexIDMapWrapper")
}
wrapper.Index = &faissIndex{idx: *wrapper.cpointer}
return &wrapper, nil
}

0 comments on commit 53ce01f

Please sign in to comment.