~ubuntu-branches/ubuntu/utopic/mtbl/utopic-proposed

« back to all changes in this revision

Viewing changes to mtbl/merger.c

  • Committer: Package Import Robot
  • Author(s): Robert S. Edmonds
  • Date: 2014-01-21 16:30:22 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20140121163022-g1077ma2csn1gne8
Tags: 0.4-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (c) 2012 by Internet Systems Consortium, Inc. ("ISC")
3
 
 *
4
 
 * Permission to use, copy, modify, and/or distribute this software for any
5
 
 * purpose with or without fee is hereby granted, provided that the above
6
 
 * copyright notice and this permission notice appear in all copies.
7
 
 *
8
 
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
9
 
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
 
 * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
11
 
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
 
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
 
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
14
 
 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
2
 * Copyright (c) 2012, 2014 by Farsight Security, Inc.
 
3
 *
 
4
 * Licensed under the Apache License, Version 2.0 (the "License");
 
5
 * you may not use this file except in compliance with the License.
 
6
 * You may obtain a copy of the License at
 
7
 *
 
8
 *    http://www.apache.org/licenses/LICENSE-2.0
 
9
 *
 
10
 * Unless required by applicable law or agreed to in writing, software
 
11
 * distributed under the License is distributed on an "AS IS" BASIS,
 
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
13
 * See the License for the specific language governing permissions and
 
14
 * limitations under the License.
15
15
 */
16
16
 
17
17
#include "mtbl-private.h"
18
18
 
19
 
#include "librsf/heap.h"
20
 
#include "librsf/ubuf.h"
21
 
#include "librsf/vector.h"
 
19
#include "libmy/heap.h"
 
20
#include "libmy/ubuf.h"
22
21
 
23
22
struct entry {
24
23
        struct mtbl_iter                *it;
37
36
        ubuf                            *cur_key;
38
37
        ubuf                            *cur_val;
39
38
        bool                            finished;
 
39
        bool                            pending;
40
40
};
41
41
 
42
42
struct mtbl_merger_options {
146
146
static mtbl_res
147
147
entry_fill(struct entry *ent)
148
148
{
149
 
        assert(ent->it != NULL);
150
 
 
151
149
        const uint8_t *key, *val;
152
150
        size_t len_key, len_val;
153
151
        mtbl_res res;
197
195
 
198
196
                if (ubuf_size(it->cur_key) == 0) {
199
197
                        ubuf_clip(it->cur_val, 0);
200
 
                        ubuf_append(it->cur_key, ubuf_data(e->key), ubuf_size(e->key));
201
 
                        ubuf_append(it->cur_val, ubuf_data(e->val), ubuf_size(e->val));
 
198
                        ubuf_extend(it->cur_key, e->key);
 
199
                        ubuf_extend(it->cur_val, e->val);
 
200
                        it->pending = true;
202
201
                        res = entry_fill(e);
203
202
                        if (res == mtbl_res_success)
204
203
                                heap_replace(it->h, e);
228
227
                }
229
228
        }
230
229
 
231
 
        *out_key = ubuf_data(it->cur_key);
232
 
        *out_val = ubuf_data(it->cur_val);
233
 
        *out_len_key = ubuf_size(it->cur_key);
234
 
        *out_len_val = ubuf_size(it->cur_val);
235
 
 
236
 
        return (mtbl_res_success);
 
230
        if (it->pending) {
 
231
                it->pending = false;
 
232
                *out_key = ubuf_data(it->cur_key);
 
233
                *out_val = ubuf_data(it->cur_val);
 
234
                *out_len_key = ubuf_size(it->cur_key);
 
235
                *out_len_val = ubuf_size(it->cur_val);
 
236
                return (mtbl_res_success);
 
237
        } else {
 
238
                return (mtbl_res_failure);
 
239
        }
237
240
}
238
241
 
239
242
static void