Skip to content

Commit

Permalink
CamelCase various functions
Browse files Browse the repository at this point in the history
  • Loading branch information
e-gun committed Dec 27, 2022
1 parent f569634 commit 361a09f
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 111 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# HipparchiaGoServer

### STATUS (`v1.0.9`):
### STATUS (`v1.0.10`):

* 25%-700% faster than HipparchiaServer depending on the function. Uses c. 60% as much RAM.
* monolithic binary: no need for extra files/folders beyond setting a password in `hgs-conf.json`
Expand Down
2 changes: 1 addition & 1 deletion dbworklines.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func (dbw *DbWorkline) Citation() string {
func (dbw *DbWorkline) Lvls() int {
//alternate is: "return dbw.MyWk().CountLevels()"
vv := []string{dbw.Lvl0Value, dbw.Lvl1Value, dbw.Lvl2Value, dbw.Lvl3Value, dbw.Lvl4Value, dbw.Lvl5Value}
empty := containsN(vv, "-1")
empty := ContainsN(vv, "-1")
return 6 - empty
}

Expand Down
61 changes: 31 additions & 30 deletions generichelpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,11 @@ const (
GREY2 = "\033[38;5;247m" // Grey62
GREY3 = "\033[38;5;242m" // Grey42
WHITE = "\033[38;5;255m" // Grey93
PANIC = "[%s%s v.%s%s] %sUNRECOVERABLE ERROR: PLEASE TAKE NOTE OF THE FOLLOWING PANIC MESSAGE%s\n"
)

// chke - send a generic message and panic on error
func chke(err error) {
const (
PANIC = "[%s%s v.%s%s] %sUNRECOVERABLE ERROR: PLEASE TAKE NOTE OF THE FOLLOWING PANIC MESSAGE%s\n"
)

if err != nil {
fmt.Printf(PANIC, YELLOW2, MYNAME, VERSION, RESET, RED2, RESET)
panic(err)
Expand Down Expand Up @@ -91,15 +88,15 @@ func msg(message string, threshold int) {

}

// timetracker - report time elapsed since last checkpoint
func timetracker(letter string, m string, start time.Time, previous time.Time) {
// TimeTracker - report time elapsed since last checkpoint
func TimeTracker(letter string, m string, start time.Time, previous time.Time) {
d := fmt.Sprintf("[Δ: %.3fs] ", time.Now().Sub(previous).Seconds())
m = fmt.Sprintf("[%s: %.3fs]", letter, time.Now().Sub(start).Seconds()) + d + m
msg(m, TIMETRACKERMSGTHRESH)
}

// gcstats - force garbage collection and report on the results
func gcstats(fn string) {
// GCStats - force garbage collection and report on the results
func GCStats(fn string) {
// NB: this could potentially backfire
// "GC runs a garbage collection and blocks the caller until the garbage collection is complete.
// It may also block the entire program." (https://pkg.go.dev/runtime#GC)
Expand Down Expand Up @@ -206,14 +203,17 @@ func SetSubtraction[T comparable](aa []T, bb []T) []T {
}

result := make([]T, 0, len(remain))
count := 0
for r := range remain {
result = append(result, r)
result[count] = r
count += 1
}

return result
}

// isinslice - is item X an element of slice A?
func isinslice[T comparable](sl []T, seek T) bool {
// IsInSlice - is item X an element of slice A?
func IsInSlice[T comparable](sl []T, seek T) bool {
for _, v := range sl {
if v == seek {
return true
Expand All @@ -222,8 +222,8 @@ func isinslice[T comparable](sl []T, seek T) bool {
return false
}

// containsN - how many Xs in slice A?
func containsN[T comparable](sl []T, seek T) int {
// ContainsN - how many Xs in slice A?
func ContainsN[T comparable](sl []T, seek T) int {
count := 0
for _, v := range sl {
if v == seek {
Expand All @@ -233,8 +233,8 @@ func containsN[T comparable](sl []T, seek T) int {
return count
}

// flatten - turn a slice of slices into a slice: [][]T --> []T
func flatten[T any](lists [][]T) []T {
// FlattenSlices - turn a slice of slices into a slice: [][]T --> []T
func FlattenSlices[T any](lists [][]T) []T {
// https://stackoverflow.com/questions/59579121/how-to-flatten-a-2d-slice-into-1d-slice
var res []T
for _, list := range lists {
Expand All @@ -243,8 +243,8 @@ func flatten[T any](lists [][]T) []T {
return res
}

// stringmapintoslice - convert map[string]T to []T
func stringmapintoslice[T any](mp map[string]T) []T {
// StringMapIntoSlice - convert map[string]T to []T
func StringMapIntoSlice[T any](mp map[string]T) []T {
sl := make([]T, len(mp))
i := 0
for _, v := range mp {
Expand All @@ -254,8 +254,8 @@ func stringmapintoslice[T any](mp map[string]T) []T {
return sl
}

// stringmapkeysintoslice - convert map[string]T to []string
func stringmapkeysintoslice[T any](mp map[string]T) []string {
// StringMapKeysIntoSlice - convert map[string]T to []string
func StringMapKeysIntoSlice[T any](mp map[string]T) []string {
sl := make([]string, len(mp))
i := 0
for k := range mp {
Expand All @@ -271,37 +271,37 @@ func stringmapkeysintoslice[T any](mp map[string]T) []string {

type lessFunc func(p1, p2 *DbWorkline) bool

// multiSorter implements the Sort interface, sorting the changes within.
type multiSorter struct {
// MultiSorter implements the Sort interface, sorting the changes within.
type MultiSorter struct {
changes []DbWorkline
less []lessFunc
}

// Sort sorts the argument slice according to the less functions passed to OrderedBy.
func (ms *multiSorter) Sort(changes []DbWorkline) {
func (ms *MultiSorter) Sort(changes []DbWorkline) {
ms.changes = changes
sort.Sort(ms)
}

// OrderedBy returns a Sorter that sorts using the less functions, in order.
// Call its Sort method to sort the data.
func OrderedBy(less ...lessFunc) *multiSorter {
return &multiSorter{
func OrderedBy(less ...lessFunc) *MultiSorter {
return &MultiSorter{
less: less,
}
}

// Len is part of sort.Interface.
func (ms *multiSorter) Len() int {
func (ms *MultiSorter) Len() int {
return len(ms.changes)
}

// Swap is part of sort.Interface.
func (ms *multiSorter) Swap(i, j int) {
func (ms *MultiSorter) Swap(i, j int) {
ms.changes[i], ms.changes[j] = ms.changes[j], ms.changes[i]
}

func (ms *multiSorter) Less(i, j int) bool {
func (ms *MultiSorter) Less(i, j int) bool {
p, q := &ms.changes[i], &ms.changes[j]
// Try all but the last comparison.
var k int
Expand All @@ -326,10 +326,11 @@ func (ms *multiSorter) Less(i, j int) bool {
// STRINGS and []RUNE
//

// Purgechars - drop any of the chars in the []byte from the string
// Purgechars - drop any of the chars in the bad-string from the check-string
func Purgechars(bad string, checking string) string {
reducer := make(map[rune]bool)
for _, r := range []rune(bad) {
rb := []rune(bad)
reducer := make(map[rune]bool, len(rb))
for _, r := range rb {
reducer[r] = true
}

Expand Down
32 changes: 16 additions & 16 deletions greekandlatin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ var (
UvRed = uvσςϲreducer()
)

// stripaccentsSTR - ὀκνεῖϲ --> οκνειϲ, etc.
func stripaccentsSTR(u string) string {
// StripaccentsSTR - ὀκνεῖϲ --> οκνειϲ, etc.
func StripaccentsSTR(u string) string {
// reducer := getrunereducer()
ru := []rune(u)
stripped := make([]rune, len(ru))
Expand All @@ -32,8 +32,8 @@ func stripaccentsSTR(u string) string {
return s
}

// stripaccentsRUNE - ὀκνεῖϲ --> οκνειϲ, etc.
func stripaccentsRUNE(u []rune) []rune {
// StripaccentsRUNE - ὀκνεῖϲ --> οκνειϲ, etc.
func StripaccentsRUNE(u []rune) []rune {
// reducer := getrunereducer()
stripped := make([]rune, len(u))
for i, x := range u {
Expand Down Expand Up @@ -192,24 +192,24 @@ func findacuteorgrave(s string) string {
return string(mod)
}

func swapacuteforgrave(thetext string) string {
func SwapAcuteForGrave(thetext string) string {
swap := strings.NewReplacer("ὰ", "ά", "ὲ", "έ", "ὶ", "ί", "ὸ", "ό", "ὺ", "ύ", "ὴ", "ή", "ὼ", "ώ",
"ἂ", "ἄ", "ἃ", "ἅ", "ᾲ", "ᾴ", "ᾂ", "ᾄ", "ᾃ", "ᾅ", "ἒ", "ἔ", "ἲ", "ἴ", "ὂ", "ὄ", "ὃ", "ὅ", "ὒ", "ὔ", "ὓ", "ὕ",
"ἢ", "ἤ", "ἣ", "ἥ", "ᾓ", "ᾕ", "ᾒ", "ᾔ", "ὢ", "ὤ", "ὣ", "ὥ", "ᾣ", "ᾥ", "ᾢ", "ᾤ", "á", "a", "é", "e",
"í", "i", "ó", "o", "ú", "u")
return swap.Replace(thetext)
}

func swapgraveforacute(thetext string) string {
func SwapGraveForAcute(thetext string) string {
swap := strings.NewReplacer("ά", "ὰ", "έ", "ὲ", "ί", "ὶ", "ό", "ὸ", "ύ", "ὺ", "ή", "ὴ", "ώ", "ὼ",
"ἄ", "ἂ", "ἅ", "ἃ", "ᾴ", "ᾲ", "ᾄ", "ᾂ", "ᾅ", "ᾃ", "ἔ", "ἒ", "ἴ", "ἲ", "ὄ", "ὂ", "ὅ", "ὃ", "ὔ", "ὒ", "ὕ", "ὓ",
"ἤ", "ἢ", "ἥ", "ἣ", "ᾕ", "ᾓ", "ᾔ", "ᾒ", "ὤ", "ὢ", "ὥ", "ὣ", "ᾥ", "ᾣ", "ᾤ", "ᾢ", "a", "á", "e", "é",
"i", "í", "o", "ó", "u", "ú")
return swap.Replace(thetext)
}

// capsvariants - build regex compilation template for a word and its capitalized variant: [aA][bB][cC]
func capsvariants(word string) string {
// CapsVariants - build regex compilation template for a word and its capitalized variant: [aA][bB][cC]
func CapsVariants(word string) string {
cv := ""
rr := []rune(word)
for _, r := range rr {
Expand All @@ -220,8 +220,8 @@ func capsvariants(word string) string {
return cv
}

// uvσςϲ - v to u, etc
func uvσςϲ(u string) string {
// UVσςϲ - v to u, etc
func UVσςϲ(u string) string {
ru := []rune(u)
stripped := make([]rune, len(ru))
for i, x := range ru {
Expand All @@ -236,7 +236,7 @@ func uvσςϲ(u string) string {

}

// uvσςϲreducer - provide map to uvσςϲ
// uvσςϲreducer - provide map to UVσςϲ
func uvσςϲreducer() map[rune]rune {
// map[73:105 74:105 85:117 86:117 105:105 106:105 ...]
feeder := make(map[rune][]rune)
Expand All @@ -254,8 +254,8 @@ func uvσςϲreducer() map[rune]rune {
return reducer
}

// delunate - Τὴν οὖν τῶν ϲωμάτων ϲύνταξιν ϲκεψαμένουϲ πρὸϲ --> Τὴν οὖν τῶν σωμάτων σύνταξιν σκεψαμένους πρὸς
func delunate(txt string) string {
// DeLunate - Τὴν οὖν τῶν ϲωμάτων ϲύνταξιν ϲκεψαμένουϲ πρὸϲ --> Τὴν οὖν τῶν σωμάτων σύνταξιν σκεψαμένους πρὸς
func DeLunate(txt string) string {
// be careful not to loop regexp.MustCompile; this function should be called on text blocks not single lines
swap := regexp.MustCompile("σ" + TERMINATIONS)
txt = strings.Replace(txt, "ϲ", "σ", -1)
Expand All @@ -264,8 +264,8 @@ func delunate(txt string) string {
return txt
}

// formatbcedate - turn "-300" into "300 B.C.E."
func formatbcedate(d string) string {
// FormatBCEDate - turn "-300" into "300 B.C.E."
func FormatBCEDate(d string) string {
s, e := strconv.Atoi(d)
if e != nil {
s = 9999
Expand All @@ -280,5 +280,5 @@ func formatbcedate(d string) string {

// IntToBCE - turn an int into something like "300 B.C.E."
func IntToBCE(i int) string {
return formatbcedate(fmt.Sprintf("%d", i))
return FormatBCEDate(fmt.Sprintf("%d", i))
}
2 changes: 1 addition & 1 deletion initializeglobals.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func nestedlemmamapper(unnested map[string]DbLemma) map[string]map[string]DbLemm
swap := strings.NewReplacer("j", "i", "v", "u")
for k, v := range unnested {
rbag := []rune(v.Entry)[0:2]
rbag = stripaccentsRUNE(rbag)
rbag = StripaccentsRUNE(rbag)
bag := strings.ToLower(string(rbag))
bag = swap.Replace(bag)
if _, y := nested[bag]; !y {
Expand Down
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ func main() {
previous := time.Now()

AllWorks = workmapper()
timetracker("A1", fmt.Sprintf(MSG1, len(AllWorks)), start, previous)
TimeTracker("A1", fmt.Sprintf(MSG1, len(AllWorks)), start, previous)

previous = time.Now()
AllAuthors = authormapper(AllWorks)
timetracker("A2", fmt.Sprintf(MSG2, len(AllAuthors)), start, previous)
TimeTracker("A2", fmt.Sprintf(MSG2, len(AllAuthors)), start, previous)

previous = time.Now()
WkCorpusMap = buildwkcorpusmap()
Expand All @@ -68,7 +68,7 @@ func main() {
WkGenres = buildwkgenresmap()
AuLocs = buildaulocationmap()
WkLocs = buildwklocationmap()
timetracker("A3", MSG3, start, previous)
TimeTracker("A3", MSG3, start, previous)
}(&awaiting)

awaiting.Add(1)
Expand All @@ -79,16 +79,16 @@ func main() {
previous := time.Now()

AllLemm = lemmamapper()
timetracker("B1", fmt.Sprintf(MSG4, len(AllLemm)), start, previous)
TimeTracker("B1", fmt.Sprintf(MSG4, len(AllLemm)), start, previous)

previous = time.Now()
NestedLemm = nestedlemmamapper(AllLemm)
timetracker("B2", MSG5, start, previous)
TimeTracker("B2", MSG5, start, previous)
}(&awaiting)

awaiting.Wait()

gcstats("main() post-initialization")
GCStats("main() post-initialization")
msg(fmt.Sprintf(SUMM, time.Now().Sub(launch).Seconds()), MSGWARN)
StartEchoServer()
}
Expand All @@ -105,7 +105,7 @@ type CurrentConfiguration struct {
HostIP string
HostPort int
LogLevel int
ManualGC bool // see gcstats()
ManualGC bool // see GCStats()
MaxText int
PGLogin PostgresLogin
QuietStart bool
Expand Down
10 changes: 6 additions & 4 deletions rt-browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func generatebrowsedpassage(au string, wk string, fc int, ctx int) BrowsedPassag
}

if w.UID == "null" {
// some problem cases (that arise via rt-lexica.go and the bad clicks embedded in teh lexical data):
// gr0161w001
msg(fmt.Sprintf(FAIL1, k), MSGFYI)
return BrowsedPassage{}
}
Expand Down Expand Up @@ -385,14 +387,14 @@ func buildbrowsertable(focus int, lines []DbWorkline) string {
wm[w] = true
}
}
return stringmapkeysintoslice(wm)
return StringMapKeysIntoSlice(wm)
}()

almostallregex := func() map[string]*regexp.Regexp {
// you will have "ἱματίῳ", but the marked up line has "ἱμα- | τίῳ"
ar := make(map[string]*regexp.Regexp)
for _, w := range allwords {
r := fmt.Sprintf(OBSREGTEMPL, capsvariants(w))
r := fmt.Sprintf(OBSREGTEMPL, CapsVariants(w))
pattern, e := regexp.Compile(r)
if e != nil {
// you will barf if w = *
Expand Down Expand Up @@ -424,7 +426,7 @@ func buildbrowsertable(focus int, lines []DbWorkline) string {
if j == len(wds)-1 && terminalhyph.MatchString(lmw) {
// wds[lastwordindex] is the unhyphenated word
// almostallregex does not contain this pattern: "ἱμα-", e.g.
np, e := regexp.Compile(fmt.Sprintf(OBSREGTEMPL, capsvariants(lmw)))
np, e := regexp.Compile(fmt.Sprintf(OBSREGTEMPL, CapsVariants(lmw)))
if e != nil {
msg(fmt.Sprintf(FAIL, lmw), MSGPEEK)
np = regexp.MustCompile("FIND_NOTHING")
Expand Down Expand Up @@ -473,7 +475,7 @@ func buildbrowsertable(focus int, lines []DbWorkline) string {
tab = top + tab + `</tbody></table>`

if Config.ZapLunates {
tab = delunate(tab)
tab = DeLunate(tab)
}

return tab
Expand Down
2 changes: 1 addition & 1 deletion rt-frontpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func readUUIDCookie(c echo.Context) string {

SessionLocker.Lock()
if _, t := SessionMap[id]; !t {
SessionMap[id] = makedefaultsession(id)
SessionMap[id] = MakeDefaultSession(id)
}
SessionLocker.Unlock()

Expand Down
Loading

0 comments on commit 361a09f

Please sign in to comment.