Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67592 > unrolled thread
| Started by | Cameron Simpson <cs@zip.com.au> |
|---|---|
| First post | 2014-03-04 09:02 +1100 |
| Last post | 2014-03-04 09:02 +1100 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: how to get bytes from bytearray without copying Cameron Simpson <cs@zip.com.au> - 2014-03-04 09:02 +1100
| From | Cameron Simpson <cs@zip.com.au> |
|---|---|
| Date | 2014-03-04 09:02 +1100 |
| Subject | Re: how to get bytes from bytearray without copying |
| Message-ID | <mailman.7665.1393884137.18130.python-list@python.org> |
On 03Mar2014 09:15, Juraj Ivančić <juraj.ivancic@gmail.com> wrote:
> On 3.3.2014. 1:44, Cameron Simpson wrote:
> >>ValueError: cannot hash writable memoryview object
> >
> >Have you considered subclassing memoryview and giving the subclass
> >a __hash__ method?
>
> I have, and then, when I failed to subclass it, I considered doing
> aggregation, and make it behave byte-like. But how to implement the
> overridden __hash__ method? It will still require at least *some*
> redundant copying. And there is the slicing thing... the whole idea
> started to feel like I was performing tonsillectomy through the anal
> cavity.
Write a wrapper class instead and use:
def __hash__(self):
return id(self)
Simple and fast. Unless you need slices with the same content to
hash the same (eg storing them as dict keys, or in sets).
And alternative would be a simple hash of the first few bytes in
whatever slice you had.
Cheers,
--
Cameron Simpson <cs@zip.com.au>
Why is it so hard for people to simply leave people alone? But, the answer
comes to me: they are idiots and in a perfect world, I would be permitted to
kill them all. - Julie Rhodes <jk.rhodes@asacomp.com>
Back to top | Article view | comp.lang.python
csiph-web