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