1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-01-21 15:56:50 +00:00

Make some functions unexported

This commit is contained in:
Timur Ismagilov 2021-12-20 23:59:23 +03:00
parent cd18a99bc0
commit fbcbd0e445
4 changed files with 38 additions and 36 deletions

View File

@ -33,20 +33,20 @@ func fetchText(h *Hypha) string {
return "" return ""
} }
// BacklinkIndexOperation is an operation for the backlink index. This operation is executed async-safe. // backlinkIndexOperation is an operation for the backlink index. This operation is executed async-safe.
type BacklinkIndexOperation interface { type backlinkIndexOperation interface {
Apply() apply()
} }
// BacklinkIndexEdit contains data for backlink index update after a hypha edit // backlinkIndexEdit contains data for backlink index update after a hypha edit
type BacklinkIndexEdit struct { type backlinkIndexEdit struct {
Name string Name string
OldLinks []string OldLinks []string
NewLinks []string NewLinks []string
} }
// Apply changes backlink index respective to the operation data // Apply changes backlink index respective to the operation data
func (op BacklinkIndexEdit) Apply() { func (op backlinkIndexEdit) apply() {
oldLinks := toLinkSet(op.OldLinks) oldLinks := toLinkSet(op.OldLinks)
newLinks := toLinkSet(op.NewLinks) newLinks := toLinkSet(op.NewLinks)
for link := range oldLinks { for link := range oldLinks {
@ -64,14 +64,14 @@ func (op BacklinkIndexEdit) Apply() {
} }
} }
// BacklinkIndexDeletion contains data for backlink index update after a hypha deletion // backlinkIndexDeletion contains data for backlink index update after a hypha deletion
type BacklinkIndexDeletion struct { type backlinkIndexDeletion struct {
Name string Name string
Links []string Links []string
} }
// Apply changes backlink index respective to the operation data // Apply changes backlink index respective to the operation data
func (op BacklinkIndexDeletion) Apply() { func (op backlinkIndexDeletion) apply() {
for _, link := range op.Links { for _, link := range op.Links {
if lSet, exists := backlinkIndex[link]; exists { if lSet, exists := backlinkIndex[link]; exists {
delete(lSet, op.Name) delete(lSet, op.Name)
@ -79,15 +79,15 @@ func (op BacklinkIndexDeletion) Apply() {
} }
} }
// BacklinkIndexRenaming contains data for backlink index update after a hypha renaming // backlinkIndexRenaming contains data for backlink index update after a hypha renaming
type BacklinkIndexRenaming struct { type backlinkIndexRenaming struct {
OldName string OldName string
NewName string NewName string
Links []string Links []string
} }
// Apply changes backlink index respective to the operation data // Apply changes backlink index respective to the operation data
func (op BacklinkIndexRenaming) Apply() { func (op backlinkIndexRenaming) apply() {
for _, link := range op.Links { for _, link := range op.Links {
if lSet, exists := backlinkIndex[link]; exists { if lSet, exists := backlinkIndex[link]; exists {
delete(lSet, op.OldName) delete(lSet, op.OldName)
@ -97,7 +97,7 @@ func (op BacklinkIndexRenaming) Apply() {
} }
var backlinkIndex = make(map[string]linkSet) var backlinkIndex = make(map[string]linkSet)
var backlinkConveyor = make(chan BacklinkIndexOperation, 64) var backlinkConveyor = make(chan backlinkIndexOperation, 64)
// I hope, the buffer size is enough -- chekoopa // I hope, the buffer size is enough -- chekoopa
// Do we really need the buffer though? Dunno -- bouncepaw // Do we really need the buffer though? Dunno -- bouncepaw
@ -122,7 +122,7 @@ func RunBacklinksConveyor() {
// It is supposed to run as a goroutine for all the time. So, don't blame the infinite loop. // It is supposed to run as a goroutine for all the time. So, don't blame the infinite loop.
defer close(backlinkConveyor) defer close(backlinkConveyor)
for { for {
(<-backlinkConveyor).Apply() (<-backlinkConveyor).apply()
} }
} }
@ -138,19 +138,19 @@ func BacklinksCount(h *Hypha) int {
func BacklinksOnEdit(h *Hypha, oldText string) { func BacklinksOnEdit(h *Hypha, oldText string) {
oldLinks := extractHyphaLinksFromContent(h.Name, oldText) oldLinks := extractHyphaLinksFromContent(h.Name, oldText)
newLinks := extractHyphaLinks(h) newLinks := extractHyphaLinks(h)
backlinkConveyor <- BacklinkIndexEdit{h.Name, oldLinks, newLinks} backlinkConveyor <- backlinkIndexEdit{h.Name, oldLinks, newLinks}
} }
// BacklinksOnDelete is a deletion hook for backlinks index // BacklinksOnDelete is a deletion hook for backlinks index
func BacklinksOnDelete(h *Hypha, oldText string) { func BacklinksOnDelete(h *Hypha, oldText string) {
oldLinks := extractHyphaLinksFromContent(h.Name, oldText) oldLinks := extractHyphaLinksFromContent(h.Name, oldText)
backlinkConveyor <- BacklinkIndexDeletion{h.Name, oldLinks} backlinkConveyor <- backlinkIndexDeletion{h.Name, oldLinks}
} }
// BacklinksOnRename is a renaming hook for backlinks index // BacklinksOnRename is a renaming hook for backlinks index
func BacklinksOnRename(h *Hypha, oldName string) { func BacklinksOnRename(h *Hypha, oldName string) {
actualLinks := extractHyphaLinks(h) actualLinks := extractHyphaLinks(h)
backlinkConveyor <- BacklinkIndexRenaming{oldName, h.Name, actualLinks} backlinkConveyor <- backlinkIndexRenaming{oldName, h.Name, actualLinks}
} }
// YieldHyphaBacklinks gets backlinks for a desired hypha, sorts and iterates over them // YieldHyphaBacklinks gets backlinks for a desired hypha, sorts and iterates over them

View File

@ -17,21 +17,23 @@ func ResetCount() {
count.Unlock() count.Unlock()
} }
// IncrementCount increments the value of the hyphae counter. Use when creating new hyphae or loading hyphae from disk. // Count how many hyphae there are.
func IncrementCount() { func Count() int {
count.Lock()
defer count.Unlock()
return count.value
}
// incrementCount increments the value of the hyphae counter. Use when creating new hyphae or loading hyphae from disk.
func incrementCount() {
count.Lock() count.Lock()
count.value++ count.value++
count.Unlock() count.Unlock()
} }
// DecrementCount decrements the value of the hyphae counter. Use when deleting existing hyphae. // decrementCount decrements the value of the hyphae counter. Use when deleting existing hyphae.
func DecrementCount() { func decrementCount() {
count.Lock() count.Lock()
count.value-- count.value--
count.Unlock() count.Unlock()
} }
// Count how many hyphae there are.
func Count() int {
return count.value
}

View File

@ -21,9 +21,9 @@ func Index(path string) {
for h := range ch { for h := range ch {
// It's safe to ignore the mutex because there is a single worker right now. // It's safe to ignore the mutex because there is a single worker right now.
if oh := ByName(h.Name); oh.Exists { if oh := ByName(h.Name); oh.Exists {
oh.MergeIn(h) oh.mergeIn(h)
} else { } else {
h.Insert() h.insert()
} }
} }

View File

@ -82,14 +82,14 @@ func storeHypha(h *Hypha) {
h.Unlock() h.Unlock()
} }
// Insert inserts the hypha into the storage. A previous record is used if possible. Count incrementation is done if needed. // insert inserts the hypha into the storage. A previous record is used if possible. Count incrementation is done if needed.
func (h *Hypha) Insert() (justRecorded bool) { func (h *Hypha) insert() (justRecorded bool) {
hp, recorded := byNames[h.Name] hp, recorded := byNames[h.Name]
if recorded { if recorded {
hp.MergeIn(h) hp.mergeIn(h)
} else { } else {
storeHypha(h) storeHypha(h)
IncrementCount() incrementCount()
} }
return !recorded return !recorded
@ -98,7 +98,7 @@ func (h *Hypha) Insert() (justRecorded bool) {
// InsertIfNew checks whether hypha exists and returns `true` if it didn't and has been created. // InsertIfNew checks whether hypha exists and returns `true` if it didn't and has been created.
func (h *Hypha) InsertIfNew() (justRecorded bool) { func (h *Hypha) InsertIfNew() (justRecorded bool) {
if !h.Exists { if !h.Exists {
return h.Insert() return h.insert()
} }
return false return false
} }
@ -108,7 +108,7 @@ func (h *Hypha) Delete() {
byNamesMutex.Lock() byNamesMutex.Lock()
h.Lock() h.Lock()
delete(byNames, h.Name) delete(byNames, h.Name)
DecrementCount() decrementCount()
byNamesMutex.Unlock() byNamesMutex.Unlock()
h.Unlock() h.Unlock()
} }
@ -124,8 +124,8 @@ func (h *Hypha) RenameTo(newName string) {
h.Unlock() h.Unlock()
} }
// MergeIn merges in content file paths from a different hypha object. Prints warnings sometimes. // mergeIn merges in content file paths from a different hypha object. Prints warnings sometimes.
func (h *Hypha) MergeIn(oh *Hypha) { func (h *Hypha) mergeIn(oh *Hypha) {
if h == oh { if h == oh {
return return
} }