Commit c5aeedc
Changed files (1)
structures.go
@@ -1,7 +1,6 @@
package main
import (
- "strings"
"sync"
)
@@ -13,13 +12,9 @@ var mapLock *sync.Mutex
const CATEGORY_SEPARATOR = ":"
-// categoryPaths stores the path of a category from the
-// categories array. These indices must match exactly.
-// Implmentation based on closure table from
-// http://www.slideshare.net/billkarwin/models-for-hierarchical-data
-// The path is stored using CATEGORY_SEPARATOR as the delimiter
-// in the string.
-var categories []Category
+// contains the list of categories
+// as pulled from the server
+var categories []string
// define colors for printing to terminals
const (
@@ -73,77 +68,6 @@ type CountingSemaphore struct {
locksTaken int
}
-// Category stores information related to categories
-// Storing pointers to the category array simplifies
-// sending the structures over the wire.
-type Category struct {
- Children []int
- // stores the indices of the array in
- // 'categories' of the children. Similar to a pointer,
- // but can be sent across the network.
-
- Parent int // the index in the array of 'categories'
- // a negative value indicates no parent
- fullCategoryPath,
- Value string // leaf portion of path
- // RecordArray contains all records grouped into
- // categorical buckets.
- RecordArray,
- // usedRecordArray contains the questions that have
- // already been used.
- UsedRecordArray []Record
-}
-
-// returns the fully qualified path of this
-// category, or the empty string if the PathIndex
-// variable is too large
-func (cat Category) String() string {
- return cat.FullCategoryPath()
-}
-
-// uses lazy evaluation and short circuting
-// to generate a fully qualified tag path for this category
-func (cat Category) FullCategoryPath() string {
- if cat.fullCategoryPath != "" {
- return cat.fullCategoryPath
- }
- if cat.Parent < 0 {
- return cat.Value
- }
- return categories[cat.Parent].FullCategoryPath() + CATEGORY_SEPARATOR + cat.Value
-}
-
-// IsDescendentOfPath returns true if the category is a descendant
-// of the given path
-func (cat Category) IsAncestorOfPath(path []string) bool {
- pathToCheck := strings.Join(path, ":")
- answer := (len(pathToCheck) > len(cat.FullCategoryPath())) && strings.HasPrefix(pathToCheck, cat.FullCategoryPath())
- return answer
-}
-
-// getParentCategory returns the index of the parent tag for the
-// lowest descendant if the path exists. The entire path MUST
-// match exactly for the function to return true.
-// a negative value is returned if it does not exist
-func getNearestParentCategory(tags []string) int {
- if len(tags) <= 0 {
- return -1
- }
- tagFoundIndex := -1
- for i, cat := range categories {
- if cat.IsAncestorOfPath(tags) {
- if tagFoundIndex < 0 {
- tagFoundIndex = i
- } else { // pick longest path
- if len(cat.FullCategoryPath()) > len(categories[tagFoundIndex].FullCategoryPath()) {
- tagFoundIndex = i
- }
- }
- }
- }
- return tagFoundIndex
-}
-
// P incrememnts the counter here
// note: race conditions can totally happen
func (cSem *CountingSemaphore) P() {
@@ -180,6 +104,6 @@ func (cSem *CountingSemaphore) SetCapacity(cap int) {
}
func init() {
- categories = []Category{}
+ categories = []string{}
mapLock = &sync.Mutex{}
}