~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_groupcompress_pyx.pyx

Do a lot of renaming.

Change the config from 'max_entries_per_source' to 'max_bytes_to_index'.
I'm not 100% happy, because it is max_bytes_to_delta_index_per_source, but
that is just getting rediculously long.
Internally, change the code to take a 'settings' function, which currently
returns a tuple. I'm thinking to change it to a dict.

Show diffs side-by-side

added added

removed removed

Lines of Context:
74
74
    int get_hash_offset(delta_index *index, int pos, unsigned int *hash_offset)
75
75
    int get_entry_summary(delta_index *index, int pos,
76
76
                          unsigned int *global_offset, unsigned int *hash_val)
77
 
    unsigned int c_rabin_hash "rabin_hash" (char *data)
 
77
    unsigned int rabin_hash (char *data)
78
78
 
79
79
 
80
80
cdef void *safe_malloc(size_t count) except NULL:
118
118
    return AssertionError("Unrecognised delta result code: %d" % result)
119
119
 
120
120
 
121
 
def rabin_hash(content):
 
121
def _rabin_hash(content):
122
122
    if not PyString_CheckExact(content):
123
123
        raise ValueError('content must be a string')
124
124
    if len(content) < 16:
125
125
        raise ValueError('content must be at least 16 bytes long')
126
126
    # Try to cast it to an int, if it can fit
127
 
    return int(c_rabin_hash(PyString_AS_STRING(content)))
 
127
    return int(rabin_hash(PyString_AS_STRING(content)))
128
128
 
129
129
 
130
130
cdef class DeltaIndex:
137
137
    cdef delta_index *_index
138
138
    cdef public unsigned long _source_offset
139
139
    cdef readonly unsigned int _max_num_sources
140
 
    cdef public int _max_entries_per_source
 
140
    cdef public int _max_bytes_to_index
141
141
 
142
 
    def __init__(self, source=None, max_entries_per_source=None):
 
142
    def __init__(self, source=None, max_bytes_to_index=None):
143
143
        self._sources = []
144
144
        self._index = NULL
145
145
        self._max_num_sources = 65000
146
146
        self._source_infos = <source_info *>safe_malloc(sizeof(source_info)
147
147
                                                        * self._max_num_sources)
148
148
        self._source_offset = 0
149
 
        self._max_entries_per_source = 0
150
 
        if max_entries_per_source is not None:
151
 
            self._max_entries_per_source = max_entries_per_source
 
149
        self._max_bytes_to_index = 0
 
150
        if max_bytes_to_index is not None:
 
151
            self._max_bytes_to_index = max_bytes_to_index
152
152
 
153
153
        if source is not None:
154
154
            self.add_source(source, 0)
299
299
        if source_location != 0:
300
300
            with nogil:
301
301
                res = create_delta_index(src, self._index, &index,
302
 
                                         self._max_entries_per_source)
 
302
                                         self._max_bytes_to_index)
303
303
            if res != DELTA_OK:
304
304
                raise _translate_delta_failure(res)
305
305
            if index != self._index:
317
317
        # will always create a new index unless there's a malloc failure
318
318
        with nogil:
319
319
            res = create_delta_index(&self._source_infos[0], NULL, &index,
320
 
                                     self._max_entries_per_source)
 
320
                                     self._max_bytes_to_index)
321
321
        if res != DELTA_OK:
322
322
            raise _translate_delta_failure(res)
323
323
        self._index = index