2014-09-12 23:21:35 +02:00
|
|
|
// Copyright (c) 2014 Couchbase, Inc.
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
|
|
// and limitations under the License.
|
|
|
|
|
|
|
|
package upside_down
|
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
type dictionaryTermIncr struct{}
|
2014-09-12 23:21:35 +02:00
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
func newDictionaryTermIncr() *dictionaryTermIncr {
|
|
|
|
return &dictionaryTermIncr{}
|
2014-09-12 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
func (t *dictionaryTermIncr) Merge(key, existing []byte) ([]byte, error) {
|
2014-09-12 23:21:35 +02:00
|
|
|
if len(existing) > 0 {
|
2015-03-10 21:22:19 +01:00
|
|
|
dr, err := NewDictionaryRowKV(key, existing)
|
2014-09-12 23:21:35 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-03-10 21:22:19 +01:00
|
|
|
dr.count++
|
|
|
|
return dr.Value(), nil
|
2014-09-12 23:21:35 +02:00
|
|
|
} else {
|
2015-03-10 21:22:19 +01:00
|
|
|
dr, err := NewDictionaryRowK(key)
|
2014-09-12 23:21:35 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-03-10 21:22:19 +01:00
|
|
|
dr.count = 1
|
|
|
|
return dr.Value(), nil
|
2014-09-12 23:21:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
type dictionaryTermDecr struct{}
|
2014-09-12 23:21:35 +02:00
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
func newDictionaryTermDecr() *dictionaryTermDecr {
|
|
|
|
return &dictionaryTermDecr{}
|
2014-09-12 23:21:35 +02:00
|
|
|
}
|
|
|
|
|
2015-03-10 21:22:19 +01:00
|
|
|
func (t *dictionaryTermDecr) Merge(key, existing []byte) ([]byte, error) {
|
2014-09-12 23:21:35 +02:00
|
|
|
if len(existing) > 0 {
|
2015-03-10 21:22:19 +01:00
|
|
|
dr, err := NewDictionaryRowKV(key, existing)
|
2014-09-12 23:21:35 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-03-10 21:22:19 +01:00
|
|
|
dr.count--
|
|
|
|
if dr.count > 0 {
|
|
|
|
return dr.Value(), nil
|
2014-09-12 23:21:35 +02:00
|
|
|
}
|
|
|
|
}
|
2014-11-20 20:31:51 +01:00
|
|
|
return nil, nil
|
2014-09-12 23:21:35 +02:00
|
|
|
}
|