Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/coc1961/searcharray
SearchArray This framework allows to perform searches on arrays of data structures.
https://github.com/coc1961/searcharray
array easy-to-use fast golang search
Last synced: about 1 month ago
JSON representation
SearchArray This framework allows to perform searches on arrays of data structures.
- Host: GitHub
- URL: https://github.com/coc1961/searcharray
- Owner: coc1961
- Created: 2019-03-09T19:58:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-05-19T16:36:23.000Z (over 2 years ago)
- Last Synced: 2024-06-20T10:06:46.414Z (6 months ago)
- Topics: array, easy-to-use, fast, golang, search
- Language: Go
- Homepage:
- Size: 2.73 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SearchArray
This framework allows to perform searches on arrays of data structures.
Example:
```Go
type TestStruct type {
Field1 string
Field2 int
}func main(){
var myArray []*TestStruct
//Fill the array
myArray=....
//initialize the searcharray structure
sa := searcharray.NewSearchArray()//create indexes of the fields Field1 and Field2
idx := []string{"Field1", "Field1"}//This function allows access to the attributes of the instances of TestStruct
fnGetFieldValue := func(ind int, indexField string) mapindex.IndexValue {
obj := myArray[ind]
switch indexField {
case "Field1":
return mapindex.IndexValue(obj.Field1)
case "Field2":
return mapindex.IndexValue(obj.Field2)
}
return mapindex.IndexValue(nil)
}
//Initialize with the array and the indices to create
sa.Set(fnGetFieldValue, len(myArray), idx)//I look for the records according to the filter
res, _, err := sa.Find( func (i int) error { fmt.Print("Record found",data[i]); return nil }
sa.Q("Field1", "Hello"),
sa.Q("Field2", 20),
)}
```