[591ef1]: inst / @dataframe / private / df_cow.m Maximize Restore History

Download this file

df_cow.m    79 lines (68 with data), 2.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function [df, S] = df_cow(df, S, col)
%# function [resu, S] = df_cow(df, S, col)
%# Implements Copy-On-Write on dataframe. If one or more columns
%# specified in inds is aliased to another one, duplicate it and
%# adjust the repetition index to remove the aliasing
%% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
%%
%% This file is part of Octave.
%%
%% Octave is free software; you can redistribute it and/or
%% modify it under the terms of the GNU General Public
%% License as published by the Free Software Foundation;
%% either version 2, or (at your option) any later version.
%%
%% Octave is distributed in the hope that it will be useful,
%% but WITHOUT ANY WARRANTY; without even the implied
%% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
%% PURPOSE. See the GNU General Public License for more
%% details.
%%
%% You should have received a copy of the GNU General Public
%% License along with Octave; see the file COPYING. If not,
%% write to the Free Software Foundation, 51 Franklin Street -
%% Fifth Floor, Boston, MA 02110-1301, USA.
%#
%# $Id$
%#
if (length (col) > 1)
error ("df_cow must work on a column-by-column basis");
endif
if (1 == length (S.subs)),
inds = 1;
else
inds = S.subs{2};
endif
if (~isnumeric(inds))
if (~strcmp (inds, ':'))
error ("Unknown sheet selector %s", inds);
endif
inds = 1:length (df._rep(col));
endif
for indi = (inds(:).')
dummy = df._rep{col}; dummy(indi) = 0;
[t1, t2] = ismember (df._rep{col}(indi)(:), dummy);
for indj = (t2(find (t2))) %# Copy-On-Write
%# determines the index for the next column
t1 = 1 + max (df._rep{col});
%# duplicate the touched column
df._data{col} = horzcat (df._data{col}, ...
df._data{col}(:, df._rep{col}(indj)));
if (indi > 1)
%# a new column has been created
df._rep{col}(indi) = t1;
else
%# update repetition index aliasing this one
df._rep{col}(find (dummy == indi)) = t1;
endif
endfor
endfor
%# reorder S
if (length (S.subs) > 1)
if (S.subs{2} ~= 1 || length (S.subs{2}) > 1),
%# adapt sheet index according to df_rep
S.subs{2} = df._rep{col}(S.subs{2});
endif
endif
df = df_thirddim (df);
endfunction