diff --git a/enumeration.go b/enumeration.go index 4233039f..e29b15f4 100644 --- a/enumeration.go +++ b/enumeration.go @@ -62,8 +62,18 @@ func enumerationTypeToTileDB[T EnumerationType]() Datatype { } } -// NewEnumeration creates an enumeration with name and ordered or not values. -func NewEnumeration[T EnumerationType](tdbCtx *Context, name string, ordered bool, values []T) (*Enumeration, error) { +// NewOrderedEnumeration creates an ordered enumeration with name and values. +func NewOrderedEnumeration[T EnumerationType](tdbCtx *Context, name string, values []T) (*Enumeration, error) { + return newEnumeration[T](tdbCtx, name, true, values) +} + +// NewOrderedEnumeration creates an unordered enumeration with name and values. +func NewUnorderedEnumeration[T EnumerationType](tdbCtx *Context, name string, values []T) (*Enumeration, error) { + return newEnumeration[T](tdbCtx, name, false, values) +} + +// newEnumeration creates an enumeration with name and ordered or not values. +func newEnumeration[T EnumerationType](tdbCtx *Context, name string, ordered bool, values []T) (*Enumeration, error) { cName := C.CString(name) defer C.free(unsafe.Pointer(cName)) diff --git a/enumeration_test.go b/enumeration_test.go index 37132cac..fe6bd85c 100644 --- a/enumeration_test.go +++ b/enumeration_test.go @@ -17,14 +17,14 @@ func TestEnumeration(t *testing.T) { tdbCtx, err := NewContext(config) require.NoError(t, err) - romanNumerals, err := NewEnumeration(tdbCtx, "romanNumerals", true, + romanNumerals, err := NewOrderedEnumeration(tdbCtx, "romanNumerals", []string{"i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", "xvi"}) require.NoError(t, err) - powersOfTwo, err := NewEnumeration(tdbCtx, "powersOfTwo", true, []uint32{1, 2, 4, 8, 16, 32, 64, 128, 256}) + powersOfTwo, err := NewOrderedEnumeration(tdbCtx, "powersOfTwo", []uint32{1, 2, 4, 8, 16, 32, 64, 128, 256}) require.NoError(t, err) - truth, err := NewEnumeration(tdbCtx, "truth", false, []bool{false, true}) + truth, err := NewUnorderedEnumeration(tdbCtx, "truth", []bool{false, true}) require.NoError(t, err) t.Run("Name", func(t *testing.T) { @@ -272,11 +272,11 @@ func arraySchemaWithEnumerations(t *testing.T) *ArraySchema { require.NoError(t, domain.AddDimensions(dimRows, dimCols)) require.NoError(t, schema.SetDomain(domain)) - greekNumerals, err := NewEnumeration(tdbCtx, "greekNumerals", true, + greekNumerals, err := NewOrderedEnumeration(tdbCtx, "greekNumerals", []string{"α", "β", "γ", "δ", "ε", "στ", "ζ", "η", "θ", "ι", "ια", "ιβ", "ιγ", "ιδ", "ιε", "ιστ"}) require.NoError(t, err) require.NoError(t, schema.AddEnumeration(greekNumerals)) - romanNumerals, err := NewEnumeration(tdbCtx, "romanNumerals", true, + romanNumerals, err := NewOrderedEnumeration(tdbCtx, "romanNumerals", []string{"i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix", "x", "xi", "xii", "xiii", "xiv", "xv", "xvi"}) require.NoError(t, err) require.NoError(t, schema.AddEnumeration(romanNumerals))