<commit_before>package abkleveldb

import (
  "fmt"

  "github.com/jmhodges/levigo"
)

func boohoo(errstring string, rise bool){
  fmt.Println(errstring)
  if rise == true{ panic(errstring) }
}

func CreateDB(dbname string) (*levigo.DB) {
  opts := levigo.NewOptions()
  opts.SetCache(levigo.NewLRUCache(1<<10))
  opts.SetCreateIfMissing(true)
  db, err := levigo.Open(dbname, opts)
  if err != nil { boohoo("DB " + dbname + " Creation failed.", true) }
  return db
}

/* Push KeyVal */
func PushKeyVal(key string, val string, db *levigo.DB) bool{
  writer := levigo.NewWriteOptions()
  defer writer.Close()

  keyname := []byte(key)
  value := []byte(val)
  err := db.Put(writer, keyname, value)
  if err != nil {
    boohoo("Key " + key + " insertion failed. It's value was " + val, false)
    return false
  }
  return true
}

/* Get Key */
func GetVal(key string, db *levigo.DB) string {
  reader := levigo.NewReadOptions()
  defer reader.Close()

  data, err := db.Get(reader, []byte(key))
  if err != nil { boohoo("Key " + key + " query failed.", false) }
  return string(data)
}

/* Del Key */
func DelKey(key string, db *levigo.DB) bool {
  writer := levigo.NewWriteOptions()
  defer writer.Close()

  err := db.Delete(writer, []byte(key))
  if err != nil { boohoo("Key " + key + " query failed.", false) }
  return true
}<commit_msg>abkleveldb updated with comments<commit_after>package abkleveldb

import (
  "fmt"

  "github.com/jmhodges/levigo"
)


/*
Prints provided error message and panics if rise value is True.
*/
func boohoo(errstring string, rise bool){
  fmt.Println(errstring)
  if rise == true{ panic(errstring) }
}


/*
Creates a db at provided pathname.
*/
func CreateDB(dbname string) (*levigo.DB) {
  opts := levigo.NewOptions()
  opts.SetCache(levigo.NewLRUCache(1<<10))
  opts.SetCreateIfMissing(true)
  db, err := levigo.Open(dbname, opts)
  if err != nil { boohoo("DB " + dbname + " Creation failed.", true) }
  return db
}

/*
Push KeyVal in provided DB handle.
*/
func PushKeyVal(key string, val string, db *levigo.DB) bool{
  writer := levigo.NewWriteOptions()
  defer writer.Close()

  keyname := []byte(key)
  value := []byte(val)
  err := db.Put(writer, keyname, value)
  if err != nil {
    boohoo("Key " + key + " insertion failed. It's value was " + val, false)
    return false
  }
  return true
}

/*
Get Value of Key from provided db handle.
*/
func GetVal(key string, db *levigo.DB) string {
  reader := levigo.NewReadOptions()
  defer reader.Close()

  data, err := db.Get(reader, []byte(key))
  if err != nil { boohoo("Key " + key + " query failed.", false) }
  return string(data)
}

/*
Del Key from provided DB handle.
*/
func DelKey(key string, db *levigo.DB) bool {
  writer := levigo.NewWriteOptions()
  defer writer.Close()

  err := db.Delete(writer, []byte(key))
  if err != nil { boohoo("Key " + key + " query failed.", false) }
  return true
}
{'fraction_non_alphanumeric': 0.152864044168392, 'fraction_numerical': 0.002070393374741201, 'mean_word_length': 3.6162420382165603, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '305951', 'n_tokens_mistral': 1056, 'n_tokens_neox': 1027, 'n_words': 286}