fork of https://github.com/oxigraph/rocksdb and https://github.com/facebook/rocksdb for nextgraph and oxigraph
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.4 KiB
69 lines
1.4 KiB
11 years ago
|
// Copyright (c) 2012 The LevelDB Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style license that can be
|
||
|
// found in the LICENSE file. See the AUTHORS file for names of contributors.
|
||
|
|
||
|
#include "leveldb/slice_transform.h"
|
||
|
#include "leveldb/slice.h"
|
||
|
|
||
|
namespace leveldb {
|
||
|
|
||
|
namespace {
|
||
|
|
||
|
class FixedPrefixTransform : public SliceTransform {
|
||
|
private:
|
||
|
size_t prefix_len_;
|
||
|
|
||
|
public:
|
||
|
explicit FixedPrefixTransform(size_t prefix_len) : prefix_len_(prefix_len) { }
|
||
|
|
||
|
virtual const char* Name() const {
|
||
|
return "rocksdb.FixedPrefix";
|
||
|
}
|
||
|
|
||
|
virtual Slice Transform(const Slice& src) const {
|
||
|
assert(InDomain(src));
|
||
|
return Slice(src.data(), prefix_len_);
|
||
|
}
|
||
|
|
||
|
virtual bool InDomain(const Slice& src) const {
|
||
|
return (src.size() >= prefix_len_);
|
||
|
}
|
||
|
|
||
|
virtual bool InRange(const Slice& dst) const {
|
||
|
return (dst.size() == prefix_len_);
|
||
|
}
|
||
|
};
|
||
11 years ago
|
|
||
|
class NoopTransform : public SliceTransform {
|
||
|
public:
|
||
|
explicit NoopTransform() { }
|
||
|
|
||
|
virtual const char* Name() const {
|
||
|
return "rocksdb.Noop";
|
||
|
}
|
||
|
|
||
|
virtual Slice Transform(const Slice& src) const {
|
||
|
return src;
|
||
|
}
|
||
|
|
||
|
virtual bool InDomain(const Slice& src) const {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
virtual bool InRange(const Slice& dst) const {
|
||
|
return true;
|
||
|
}
|
||
|
};
|
||
|
|
||
11 years ago
|
}
|
||
|
|
||
|
const SliceTransform* NewFixedPrefixTransform(size_t prefix_len) {
|
||
|
return new FixedPrefixTransform(prefix_len);
|
||
|
}
|
||
|
|
||
11 years ago
|
const SliceTransform* NewNoopTransform() {
|
||
|
return new NoopTransform;
|
||
|
}
|
||
|
|
||
11 years ago
|
} // namespace leveldb
|