<commit_before>// Ogo

package ogo

import (
	"fmt"
	"sync"
	"time"
)

type OnlineMap struct {
	lock *sync.RWMutex
	olm  map[string]*Online
}

type Online struct {
	Key  string
	Ex   time.Time
	Perm interface{}
}

var (
	OnlineCache *OnlineMap
)

func init() {
	OnlineCache = &OnlineMap{
		lock: new(sync.RWMutex),
		olm:  make(map[string]*Online),
	}
}

/* {{{ func GetOnlineKey(id string) (*Online,error)
 * 获取在线的key
 */
func GetOnlineKey(id string) (ol *Online, err error) {
	if ol = OnlineCache.Get(id); ol == nil {
		err = fmt.Errorf("not found")
	}
	return
}

/* }}} */

/* {{{ func SetOnlineKey(id string, ol *Online,p interface{}) bool
 *
 */
func SetOnlineKey(id, key string, p interface{}) bool {
	ol := &Online{
		Key:  key,
		Ex:   time.Now().Add(300 * time.Second), //缓存5分钟
		Perm: p,
	}
	return OnlineCache.Set(id, ol)
}

/* }}} */

// Maps the given key and value. Returns false
// if the key is already in the map and changes nothing.
func (m *OnlineMap) Set(k string, v *Online) bool {
	m.lock.Lock()
	defer m.lock.Unlock()
	if val, ok := m.olm[k]; !ok {
		m.olm[k] = v
	} else if val != v {
		m.olm[k] = v
	} else {
		return false
	}
	return true
}

// Get from maps return the k's value
func (m *OnlineMap) Get(k string) (ol *Online) {
	m.lock.RLock()
	defer m.lock.RUnlock()
	if val, ok := m.olm[k]; ok {
		if time.Now().Before(val.Ex) { //还没过期
			return val
		} else { //过期,删除
			m.Delete(k)
		}
	}
	return nil
}

// Delete the given key and value.
func (m *OnlineMap) Delete(k string) {<commit_msg>bugfix<commit_after>// Ogo

package ogo

import (
	"fmt"
	"sync"
	"time"
)

type OnlineMap struct {
	lock *sync.RWMutex
	olm  map[string]*Online
}

type Online struct {
	Key  string
	Ex   time.Time
	Perm interface{}
}

var (
	OnlineCache *OnlineMap
)

func init() {
	OnlineCache = &OnlineMap{
		lock: new(sync.RWMutex),
		olm:  make(map[string]*Online),
	}
}

/* {{{ func GetOnlineKey(id string) (*Online,error)
 * 获取在线的key
 */
func GetOnlineKey(id string) (ol *Online, err error) {
	if ol = OnlineCache.Get(id); ol == nil {
		err = fmt.Errorf("not found")
	}
	return
}

/* }}} */

/* {{{ func SetOnlineKey(id string, ol *Online,p interface{}) bool
 *
 */
func SetOnlineKey(id, key string, p interface{}) bool {
	ol := &Online{
		Key:  key,
		Ex:   time.Now().Add(300 * time.Second), //缓存5分钟
		Perm: p,
	}
	return OnlineCache.Set(id, ol)
}

/* }}} */

// Maps the given key and value. Returns false
// if the key is already in the map and changes nothing.
func (m *OnlineMap) Set(k string, v *Online) bool {
	m.lock.Lock()
	defer m.lock.Unlock()
	if val, ok := m.olm[k]; !ok {
		m.olm[k] = v
	} else if val != v {
		m.olm[k] = v
	} else {
		return false
	}
	return true
}

// Get from maps return the k's value
func (m *OnlineMap) Get(k string) (ol *Online) {
	m.lock.RLock()
	//defer m.lock.RUnlock()
	if val, ok := m.olm[k]; ok {
		if time.Now().Before(val.Ex) { //还没过期
			m.lock.RUnlock()
			return val
		} else { //过期,删除
			m.lock.RUnlock()
			m.Delete(k)
			return nil
		}
	}
	m.lock.RUnlock()
	return nil
}

// Delete the given key and value.
func (m *OnlineMap) Delete(k string) {
{'fraction_non_alphanumeric': 0.1667203089797232, 'fraction_numerical': 0.002574831026713872, 'mean_word_length': 3.036363636363636, 'pattern_counts': {'":': 0, '<': 3, '<?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': '2031560', 'n_tokens_mistral': 1342, 'n_tokens_neox': 1281, 'n_words': 353}