Class: Fairy::PGroupBy::DirectMergeSortBuffer::CachedBuffer
- Inherits:
-
Object
- Object
- Fairy::PGroupBy::DirectMergeSortBuffer::CachedBuffer
show all
- Extended by:
- Forwardable
- Defined in:
- lib/fairy/node/p-group-by.rb
Instance Method Summary
collapse
Constructor Details
Returns a new instance of CachedBuffer.
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
|
# File 'lib/fairy/node/p-group-by.rb', line 1050
def initialize(njob, io)
@njob = njob
@io = io
io.open
@cache = []
@cache_pv = 0
@eof = false
read_buffer
@key = @njob.hash_key(@cache.first)
end
|
Instance Method Details
#each_by_same_key(&block) ⇒ Object
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
|
# File 'lib/fairy/node/p-group-by.rb', line 1081
def each_by_same_key(&block)
if @cache.size <= @cache_pv
read_buffer
return if @cache.empty?
end
while @njob.hash_key(@cache[@cache_pv]) == @key
block.call @cache[@cache_pv]
@cache_pv += 1
if @cache.size <= @cache_pv
read_buffer
return if @cache.empty?
end
end
@key = @njob.hash_key(@cache[@cache_pv])
end
|
#eof? ⇒ Boolean
1073
1074
1075
|
# File 'lib/fairy/node/p-group-by.rb', line 1073
def eof?
@eof
end
|
#key ⇒ Object
1077
1078
1079
|
# File 'lib/fairy/node/p-group-by.rb', line 1077
def key
@key
end
|
#read_buffer ⇒ Object
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
|
# File 'lib/fairy/node/p-group-by.rb', line 1116
def read_buffer
io = @io.io
begin
@cache = Marshal.load(io)
rescue EOFError
@eof = true
@cache = []
rescue ArgumentError
Log::debug(self, "MARSHAL ERROR OCCURED!!")
io.seek(-1024, IO::SEEK_CUR)
buf = io.read(2048)
Log::debugf(self, "File Contents: %s", buf)
raise
end
@cache_pv = 0
end
|
#shift_values ⇒ Object
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
|
# File 'lib/fairy/node/p-group-by.rb', line 1099
def shift_values
if @cache.empty?
read_buffer
return nil if @cache.empty?
end
idx = @cache.index{|v| @njob.hash_key(v) != @key}
if idx
vv = @cache.slice!(0, idx)
@key = @njob.hash_key(@cache.first)
else
vv = @cache
@cache = []
end
vv
end
|