1
/* -*- tab-width: 4 -*-
3
* Electric(tm) VLSI Design System
7
* Copyright (c) 2009 Sun Microsystems and Static Free Software
9
* Electric(tm) is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU Lesser General Public License as published by
11
* the Free Software Foundation; either version 3 of the License, or
12
* (at your option) any later version.
14
* Electric(tm) is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU Lesser General Public License for more details.
19
* You should have received a copy of the GNU Lesser General Public License
20
* along with Electric(tm); see the file COPYING. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
* Boston, Mass 02111-1307, USA.
24
package com.sun.electric.database.geometry.btree.unboxed;
28
/** A 32-bit <tt>int</tt> in unboxed form */
29
public class UnboxedInt implements UnboxedComparable<Integer> {
30
public static final UnboxedInt instance = new UnboxedInt();
31
public int getSize() { return 4; }
32
public Integer deserialize(byte[] buf, int ofs) { return new Integer(deserializeInt(buf, ofs)); }
33
public void serialize(Integer k, byte[] buf, int ofs) { serializeInt(k.intValue(), buf, ofs); }
34
public int deserializeInt(byte[] buf, int ofs) {
36
((buf[ofs+0] & 0xff) << 0) |
37
((buf[ofs+1] & 0xff) << 8) |
38
((buf[ofs+2] & 0xff) << 16) |
39
((buf[ofs+3] & 0xff) << 24);
41
public void serializeInt(int i, byte[] buf, int ofs) {
42
buf[ofs+0] = (byte)((i >> 0) & 0xff);
43
buf[ofs+1] = (byte)((i >> 8) & 0xff);
44
buf[ofs+2] = (byte)((i >> 16) & 0xff);
45
buf[ofs+3] = (byte)((i >> 24) & 0xff);
47
public int compare(byte[] buf1, int ofs1, byte[] buf2, int ofs2) {
48
int buf1msb = buf1[ofs1+3] & 0xff;
49
int buf2msb = buf2[ofs2+3] & 0xff;
50
boolean buf1negative = (buf1msb >> 7) != 0;
51
boolean buf2negative = (buf2msb >> 7) != 0;
52
if ( buf1negative && !buf2negative) return -1;
53
if (!buf1negative && buf2negative) return 1;
57
i = (buf1msb ) - (buf2msb ); if (i!=0) return i;
58
i = (buf1[ofs1+2] & 0xff) - (buf2[ofs2+2] & 0xff); if (i!=0) return i;
59
i = (buf1[ofs1+1] & 0xff) - (buf2[ofs2+1] & 0xff); if (i!=0) return i;
60
i = (buf1[ofs1+0] & 0xff) - (buf2[ofs2+0] & 0xff); if (i!=0) return i;