-
-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
77 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package runtime | ||
|
||
import ( | ||
"github.com/MontFerret/ferret/pkg/runtime/core" | ||
"github.com/MontFerret/ferret/pkg/runtime/values" | ||
) | ||
|
||
type DataSet struct { | ||
hashmap map[uint64]bool | ||
values *values.Array | ||
} | ||
|
||
func NewDataSet(distinct bool) *DataSet { | ||
var hasmap map[uint64]bool | ||
|
||
if distinct { | ||
hasmap = make(map[uint64]bool) | ||
} | ||
|
||
return &DataSet{ | ||
hashmap: hasmap, | ||
values: values.NewArray(16), | ||
} | ||
} | ||
|
||
func (ds *DataSet) Push(item core.Value) { | ||
if ds.hashmap != nil { | ||
hash := item.Hash() | ||
|
||
_, exists := ds.hashmap[hash] | ||
|
||
if exists { | ||
return | ||
} | ||
|
||
ds.hashmap[hash] = true | ||
} | ||
|
||
ds.values.Push(item) | ||
} | ||
|
||
func (ds *DataSet) MarshalJSON() ([]byte, error) { | ||
return ds.values.MarshalJSON() | ||
} | ||
|
||
func (ds *DataSet) ToArray() *values.Array { | ||
return ds.values | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters