summaryrefslogtreecommitdiff
path: root/tools/cvs2fossil/lib/id.tcl
diff options
context:
space:
mode:
authorcashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
committercashmere <cashmere@autistici.org>2026-09-04 09:05:24 +0200
commit4f49b16079b27d7ce633619e4cddfdf2bffbc952 (patch)
treec296c1e7f3c3e2f6859c6d3a1b1b208779b89679 /tools/cvs2fossil/lib/id.tcl
downloadrelic-master.tar.gz
initial commitHEADmaster
Diffstat (limited to 'tools/cvs2fossil/lib/id.tcl')
-rw-r--r--tools/cvs2fossil/lib/id.tcl64
1 files changed, 64 insertions, 0 deletions
diff --git a/tools/cvs2fossil/lib/id.tcl b/tools/cvs2fossil/lib/id.tcl
new file mode 100644
index 0000000..331f9a6
--- /dev/null
+++ b/tools/cvs2fossil/lib/id.tcl
@@ -0,0 +1,64 @@
+# # ## ### ##### ######## #############
+
+## A simple class for handling an in-memory index mapping from
+## arbitrary strings to a small numeric id. Can be queried in reverse
+## too, returning the string for the id.
+
+## Id's are starting from 1.
+
+# # ## ### ##### ######## #############
+## Requirements.
+
+package require Tcl ; # Runtime.
+package require snit ; # OO runtime.
+
+# # ## ### ##### ######## #############
+## Implementation.
+
+snit::type ::vc::tools::id {
+ # # ## ### ##### ######## #############
+
+ constructor {} {}
+
+ # # ## ### ##### ######## #############
+ ## Public API.
+ ## - Put data into the index, incl. query for id of key.
+ ## - Lookup data for id.
+
+ method put {key} {
+ if {[info exists mydata($key)]} { return $mydata($key) }
+ incr mycounter
+
+ set mydata($key) $mycounter
+ set myinvert($mycounter) $key
+
+ return $mycounter
+ }
+
+ # Explicitly load the database with a mapping.
+ method map {id key} {
+ set mydata($key) $id
+ set myinvert($id) $key
+ }
+
+ method keyof {id} { return $myinvert($id) }
+ method get {} { return [array get mydata] }
+
+ # # ## ### ##### ######## #############
+ ## Internal. State.
+
+ variable mydata -array {} ; # Map data -> id
+ variable myinvert -array {} ; # Map id -> data
+ variable mycounter 0 ; # Counter for id generation.
+
+ # # ## ### ##### ######## #############
+}
+
+namespace eval ::vc::tools {
+ namespace export id
+}
+
+# # ## ### ##### ######## #############
+## Ready.
+
+package provide vc::tools::id 1.0