Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.servlets.iphone;

public final class AmazonInterviewCode_BitVector
{
    private int[] mValues;

    public AmazonInterviewCode_BitVector( int[] pValues )
    {
        mValues = pValues;
    }

    /**
     * @param pPos >= 0
     */
    public boolean get( int pPos )
    {
        int zBit = pPos & 31;
        int zNdx = pPos >> 5;
        if ( (pPos < 0) || (zNdx >= mValues.length) )
        {
            throw new IndexOutOfBoundsException();
        }
        return LLget( zNdx, zBit );
    }

    private boolean LLget( int pPos )
    {
        int zBit = pPos & 31;
        int zNdx = pPos >> 5;
        return LLget( zNdx, zBit );
    }

    private boolean LLget( int pNdx, int pBit )
    {
        return 0 != (mValues[pNdx] & pBit);
    }

    private void LLsetOne( int pNdx, int pBit )
    {
        mValues[pNdx] |= pBit;
    }

    /**
     * @param pPos >= 0
     * @param pLen >= 0
     */
    public AmazonInterviewCode_BitVector extract( int pPos, int pLen )
    {
        if ( pLen < 0 )
        {
            throw new IllegalArgumentException();
        }
        int zBitFrom = pPos & 31;
        int zNdxFrom = pPos >> 5;
        if ( (pPos < 0) || (zNdxFrom >= mValues.length) )
        {
            throw new IndexOutOfBoundsException();
        }
        int pTo = pPos + pLen;
        int zBitTo = pTo & 31;
        int zNdxTo = pTo >> 5;
        if ( (pTo < 0) || (zNdxTo >= mValues.length) )
        {
            throw new IndexOutOfBoundsException();
        }
        return null; // Not Done
    }

    public interface Node
    {
        Node getNext();
    }

    public Node getNthNodefromEnd( Node pHead, int pNth )
    {
        if ( pHead == null || pNth < 0 )
        {
            return null;
        }
        NodePlus zPlus = LLgetNthNodefromEnd( pHead, pNth );
        return (zPlus.mOffset == pNth) ? zPlus.mNode : null;
    }

    public NodePlus LLgetNthNodefromEnd( Node pCur, int pNth )
    {
        Node zNext = pCur.getNext();
        if ( zNext == null )
        {
            return new NodePlus( pCur, 0 );
        }
        NodePlus zPlus = LLgetNthNodefromEnd( zNext, pNth );
        return (zPlus.mOffset == pNth) ? zPlus : new NodePlus( pCur, zPlus.mOffset + 1 );
    }

    private class NodePlus
    {
        Node mNode;
        int mOffset;

        private NodePlus( Node pNode, int pOffset )
        {
            mNode = pNode;
            mOffset = pOffset;
        }
    }
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/servlets/iphone/AmazonInterviewCode_BitVector.java

Diff revisions: vs.
Revision Author Commited Message
947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000