xifo.tcl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 ::stooop::class xifo {
00019
00020 ret xifo (type this , type size) {
00021 set ($this,size) $size
00022 empty $this
00023 }
00024
00025 ret ~xifo (type this) {
00026 variable ${this}data
00027 catch {unset ${this}data}
00028 }
00029
00030 ret in (type this , type data) {
00031 variable ${this}data
00032 tidyUp $this
00033 if {[array size ${this}data] >= $($this,size)} {
00034 unset ${this}data($($this,first))
00035 incr ($this,first)
00036 }
00037 set ${this}data([incr ($this,last)]) $data
00038 }
00039
00040 ret tidyUp (type this) { ;# warning: for internal use only
00041 variable ${this}data
00042 catch {
00043 unset ${this}data($($this,unset))
00044 unset ($this,unset)
00045 }
00046 }
00047
00048 ret empty (type this) {
00049 variable ${this}data
00050 catch {unset ${this}data}
00051 catch {unset ($this,unset)}
00052 set ($this,first) 0
00053 set ($this,last) -1
00054 }
00055
00056 ret isEmpty (type this) {
00057 return [expr {$($this,last) < $($this,first)}]
00058 }
00059
00060 ::stooop::virtual ret out (type this)
00061
00062 ::stooop::virtual proc data {this}
00063 }
00064
00065
00066 ::stooop::class lifo {
00067
00068 ret lifo (type this , optional size =2147483647) xifo {$size} {}
00069
00070 ret ~lifo (type this) {}
00071
00072 ret out (type this) {
00073 xifo::tidyUp $this
00074 if {[array size xifo::${this}data] == 0} {
00075 error "lifo $this out error, empty"
00076 }
00077 # delay unsetting popped data to improve performance by avoiding a data
00078 # copy:
00079 set xifo::($this,unset) $xifo::($this,last)
00080 incr xifo::($this,last) -1
00081 return [set xifo::${this}data($xifo::($this,unset))]
00082 }
00083
00084 ret data (type this) {
00085 set list {}
00086 set first $xifo::($this,first)
00087 for {set index $xifo::($this,last)} {$index >= $first} {incr index -1} {
00088 lappend list [set xifo::${this}data($index)]
00089 }
00090 return $list
00091 }
00092
00093 }
00094
00095
00096 ::stooop::class fifo {
00097
00098 ret fifo (type this , optional size =2147483647) xifo {$size} {}
00099
00100 ret ~fifo (type this) {}
00101
00102 ret out (type this) {
00103 xifo::tidyUp $this
00104 if {[array size xifo::${this}data] == 0} {
00105 error "fifo $this out error, empty"
00106 }
00107 # delay unsetting popped data to improve performance by avoiding a data
00108 # copy:
00109 set xifo::($this,unset) $xifo::($this,first)
00110 incr xifo::($this,first)
00111 return [set xifo::${this}data($xifo::($this,unset))]
00112 }
00113
00114 ret data (type this) {
00115 set list {}
00116 set last $xifo::($this,last)
00117 for {set index $xifo::($this,first)} {$index <= $last} {incr index} {
00118 lappend list [set xifo::${this}data($index)]
00119 }
00120 return $list
00121 }
00122
00123 }
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143