Prototype: Tokenize(text string) []string lowercases Unicode text then returns ordered ASCII [a-z0-9]+ runs, duplicates retained. No broader letter matching.

Final: NewSearchEngine() *SearchEngine; Add(id,text) (bool,error), Get(id) (*string,error), Update(id,text) (bool,error), Delete(id) (bool,error) require nonempty IDs. Duplicate Add preserves original; missing Update/Delete false; deleted IDs reusable. Search(term string,limit int) ([]Hit,error) requires exactly one query token even at zero limit, scores occurrences. SearchPhrase(phrase,limit) ([]Hit,error) counts consecutive-token starts including overlaps; empty token sequence yields empty. Negative limit errors; zero returns empty after query validation. Sort score descending then ID ascending, truncate limit. Stats() SearchStats reports current document and token counts. Every update/delete must remove stale terms/positions/counts. Final design should retain a positional inverted index. Limits are explicit arguments; pass 10 for the customary default.

All identifiers and strings compare exactly and case-sensitively. Numeric inputs are typed int; booleans cannot be passed as amounts. Arithmetic and logical timestamps fit int. All supplied collection inputs that are retained must be copied. Every collection or pointer snapshot must be detached; separate service instances own independent state. A nil pointer or nil optional slice denotes absence, while an ordinary empty result collection is nonnil. Invalid calls leave state unchanged unless the contract explicitly accepts time and expires state on a valid unsuccessful call. The exported signatures in exercise.go are the API specification.

Edit exercise.go; retain the public types and signatures. prototype and final are separate stages. The executable tests recover panics as failures, report named checks, and exit nonzero on any failure. A successful run must execute at least one check. Tests use logical time or explicit synchronization where relevant.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.