24 lines
345 B
V
24 lines
345 B
V
module intern
|
|
|
|
@[heap]
|
|
pub struct InternPool {
|
|
pub mut:
|
|
strings map[string]string
|
|
}
|
|
|
|
pub fn (mut ip InternPool) intern(s string) string {
|
|
if s in ip.strings {
|
|
return ip.strings[s]
|
|
}
|
|
ip.strings[s] = s
|
|
return s
|
|
}
|
|
|
|
pub fn (mut ip InternPool) count() int {
|
|
return ip.strings.len
|
|
}
|
|
|
|
pub fn (mut ip InternPool) clear() {
|
|
ip.strings.clear()
|
|
}
|