github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/third_party/code.google.com/p/leveldb-go/leveldb/db/options.go (about)

     1  // Copyright 2011 The LevelDB-Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package db
     6  
     7  // Compression is the per-block compression algorithm to use.
     8  type Compression int
     9  
    10  const (
    11  	DefaultCompression Compression = iota
    12  	NoCompression
    13  	SnappyCompression
    14  	nCompression
    15  )
    16  
    17  // Options holds the optional parameters for leveldb's DB implementations.
    18  // These options apply to the DB at large; per-query options are defined by
    19  // the ReadOptions and WriteOptions types.
    20  //
    21  // Options are typically passed to a constructor function as a struct literal.
    22  // The GetXxx methods are used inside the DB implementations; they return the
    23  // default parameter value if the *Options receiver is nil or the field value
    24  // is zero.
    25  //
    26  // Read/Write options:
    27  //   - Comparer
    28  // Read options:
    29  //   - VerifyChecksums
    30  // Write options:
    31  //   - BlockRestartInterval
    32  //   - BlockSize
    33  //   - Compression
    34  type Options struct {
    35  	// BlockRestartInterval is the number of keys between restart points
    36  	// for delta encoding of keys.
    37  	//
    38  	// The default value is 16.
    39  	BlockRestartInterval int
    40  
    41  	// BlockSize is the minimum uncompressed size in bytes of each table block.
    42  	//
    43  	// The default value is 4096.
    44  	BlockSize int
    45  
    46  	// Comparer defines a total ordering over the space of []byte keys: a 'less
    47  	// than' relationship. The same comparison algorithm must be used for reads
    48  	// and writes over the lifetime of the DB.
    49  	//
    50  	// The default value uses the same ordering as bytes.Compare.
    51  	Comparer Comparer
    52  
    53  	// Compression defines the per-block compression to use.
    54  	//
    55  	// The default value (DefaultCompression) uses snappy compression.
    56  	Compression Compression
    57  
    58  	// VerifyChecksums is whether to verify the per-block checksums in a DB.
    59  	//
    60  	// The default value is false.
    61  	VerifyChecksums bool
    62  }
    63  
    64  func (o *Options) GetBlockRestartInterval() int {
    65  	if o == nil || o.BlockRestartInterval <= 0 {
    66  		return 16
    67  	}
    68  	return o.BlockRestartInterval
    69  }
    70  
    71  func (o *Options) GetBlockSize() int {
    72  	if o == nil || o.BlockSize <= 0 {
    73  		return 4096
    74  	}
    75  	return o.BlockSize
    76  }
    77  
    78  func (o *Options) GetComparer() Comparer {
    79  	if o == nil || o.Comparer == nil {
    80  		return DefaultComparer
    81  	}
    82  	return o.Comparer
    83  }
    84  
    85  func (o *Options) GetCompression() Compression {
    86  	if o == nil || o.Compression <= DefaultCompression || o.Compression >= nCompression {
    87  		// Default to SnappyCompression.
    88  		return SnappyCompression
    89  	}
    90  	return o.Compression
    91  }
    92  
    93  func (o *Options) GetVerifyChecksums() bool {
    94  	if o == nil {
    95  		return false
    96  	}
    97  	return o.VerifyChecksums
    98  }
    99  
   100  // ReadOptions hold the optional per-query parameters for Get and Find
   101  // operations.
   102  //
   103  // Like Options, a nil *ReadOptions is valid and means to use the default
   104  // values.
   105  type ReadOptions struct {
   106  	// No fields so far.
   107  }
   108  
   109  // WriteOptions hold the optional per-query parameters for Set and Delete
   110  // operations.
   111  //
   112  // Like Options, a nil *WriteOptions is valid and means to use the default
   113  // values.
   114  type WriteOptions struct {
   115  	// Sync is whether to sync underlying writes from the OS buffer cache
   116  	// through to actual disk, if applicable. Setting Sync can result in
   117  	// slower writes.
   118  	//
   119  	// If false, and the machine crashes, then some recent writes may be lost.
   120  	// Note that if it is just the process that crashes (and the machine does
   121  	// not) then no writes will be lost.
   122  	//
   123  	// In other words, Sync being false has the same semantics as a write
   124  	// system call. Sync being true means write followed by fsync.
   125  	//
   126  	// The default value is false.
   127  	Sync bool
   128  }
   129  
   130  func (o *WriteOptions) GetSync() bool {
   131  	return o != nil && o.Sync
   132  }