diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5172429 Binary files /dev/null and b/.DS_Store differ diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..f6ee7ba --- /dev/null +++ b/.classpath @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.idea/artifacts/Vengeful_jar.xml b/.idea/artifacts/Vengeful_jar.xml new file mode 100644 index 0000000..e26f9ee --- /dev/null +++ b/.idea/artifacts/Vengeful_jar.xml @@ -0,0 +1,16 @@ + + + $PROJECT_DIR$/out/artifacts/Vengeful_jar + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..1d9a118 --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/PermissionsEx_1_23_4.xml b/.idea/libraries/PermissionsEx_1_23_4.xml new file mode 100644 index 0000000..73aaf06 --- /dev/null +++ b/.idea/libraries/PermissionsEx_1_23_4.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spigot.xml b/.idea/libraries/spigot.xml new file mode 100644 index 0000000..e83f80f --- /dev/null +++ b/.idea/libraries/spigot.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..e208459 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..879934c --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..d85e4fa --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,595 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1533082544506 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Vengeful:jar + + + + + + + + No facets are configured + + + + + + + + + + + + + + + 1.8 + + + + + + + + Vengeful + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/.project b/bin/.project new file mode 100644 index 0000000..38c4c23 --- /dev/null +++ b/bin/.project @@ -0,0 +1,17 @@ + + + Hcf core + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/bin/LICENSE b/bin/LICENSE new file mode 100644 index 0000000..f288702 --- /dev/null +++ b/bin/LICENSE @@ -0,0 +1,674 @@ + GNU GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU General Public License is a free, copyleft license for +software and other kinds of works. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +the GNU General Public License is intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. We, the Free Software Foundation, use the +GNU General Public License for most of our software; it applies also to +any other work released this way by its authors. You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + To protect your rights, we need to prevent others from denying you +these rights or asking you to surrender the rights. Therefore, you have +certain responsibilities if you distribute copies of the software, or if +you modify it: responsibilities to respect the freedom of others. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must pass on to the recipients the same +freedoms that you received. You must make sure that they, too, receive +or can get the source code. And you must show them these terms so they +know their rights. + + Developers that use the GNU GPL protect your rights with two steps: +(1) assert copyright on the software, and (2) offer you this License +giving you legal permission to copy, distribute and/or modify it. + + For the developers' and authors' protection, the GPL clearly explains +that there is no warranty for this free software. For both users' and +authors' sake, the GPL requires that modified versions be marked as +changed, so that their problems will not be attributed erroneously to +authors of previous versions. + + Some devices are designed to deny users access to install or run +modified versions of the software inside them, although the manufacturer +can do so. This is fundamentally incompatible with the aim of +protecting users' freedom to change the software. The systematic +pattern of such abuse occurs in the area of products for individuals to +use, which is precisely where it is most unacceptable. Therefore, we +have designed this version of the GPL to prohibit the practice for those +products. If such problems arise substantially in other domains, we +stand ready to extend this provision to those domains in future versions +of the GPL, as needed to protect the freedom of users. + + Finally, every program is threatened constantly by software patents. +States should not allow patents to restrict development and use of +software on general-purpose computers, but in those that do, we wish to +avoid the special danger that patents applied to a free program could +make it effectively proprietary. To prevent this, the GPL assures that +patents cannot be used to render the program non-free. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Use with the GNU Affero General Public License. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU Affero General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the special requirements of the GNU Affero General Public License, +section 13, concerning interaction through a network will apply to the +combination as such. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/bin/LorexMC/us/utils/BukkitUtils.class b/bin/LorexMC/us/utils/BukkitUtils.class new file mode 100644 index 0000000..3c7746c Binary files /dev/null and b/bin/LorexMC/us/utils/BukkitUtils.class differ diff --git a/bin/LorexMC/us/utils/Color.class b/bin/LorexMC/us/utils/Color.class new file mode 100644 index 0000000..a94274d Binary files /dev/null and b/bin/LorexMC/us/utils/Color.class differ diff --git a/bin/LorexMC/us/utils/ConcurrentValueOrderedMap$InternalEntry.class b/bin/LorexMC/us/utils/ConcurrentValueOrderedMap$InternalEntry.class new file mode 100644 index 0000000..98c5b37 Binary files /dev/null and b/bin/LorexMC/us/utils/ConcurrentValueOrderedMap$InternalEntry.class differ diff --git a/bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class b/bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class new file mode 100644 index 0000000..303e836 Binary files /dev/null and b/bin/LorexMC/us/utils/ConcurrentValueOrderedMap.class differ diff --git a/bin/LorexMC/us/utils/Config.class b/bin/LorexMC/us/utils/Config.class new file mode 100644 index 0000000..7741c8f Binary files /dev/null and b/bin/LorexMC/us/utils/Config.class differ diff --git a/bin/LorexMC/us/utils/DelayedMessageRunnable.class b/bin/LorexMC/us/utils/DelayedMessageRunnable.class new file mode 100644 index 0000000..8cfab80 Binary files /dev/null and b/bin/LorexMC/us/utils/DelayedMessageRunnable.class differ diff --git a/bin/LorexMC/us/utils/DurationFormatter.class b/bin/LorexMC/us/utils/DurationFormatter.class new file mode 100644 index 0000000..156377d Binary files /dev/null and b/bin/LorexMC/us/utils/DurationFormatter.class differ diff --git a/bin/LorexMC/us/utils/ExperienceManager.class b/bin/LorexMC/us/utils/ExperienceManager.class new file mode 100644 index 0000000..cab6da5 Binary files /dev/null and b/bin/LorexMC/us/utils/ExperienceManager.class differ diff --git a/bin/LorexMC/us/utils/GenericUtils.class b/bin/LorexMC/us/utils/GenericUtils.class new file mode 100644 index 0000000..d7cb5ef Binary files /dev/null and b/bin/LorexMC/us/utils/GenericUtils.class differ diff --git a/bin/LorexMC/us/utils/InventorySerialisation.class b/bin/LorexMC/us/utils/InventorySerialisation.class new file mode 100644 index 0000000..832d5b2 Binary files /dev/null and b/bin/LorexMC/us/utils/InventorySerialisation.class differ diff --git a/bin/LorexMC/us/utils/InventoryUtils.class b/bin/LorexMC/us/utils/InventoryUtils.class new file mode 100644 index 0000000..4704d8b Binary files /dev/null and b/bin/LorexMC/us/utils/InventoryUtils.class differ diff --git a/bin/LorexMC/us/utils/ItemBuilder.class b/bin/LorexMC/us/utils/ItemBuilder.class new file mode 100644 index 0000000..04c22d9 Binary files /dev/null and b/bin/LorexMC/us/utils/ItemBuilder.class differ diff --git a/bin/LorexMC/us/utils/JavaUtils.class b/bin/LorexMC/us/utils/JavaUtils.class new file mode 100644 index 0000000..f6686bd Binary files /dev/null and b/bin/LorexMC/us/utils/JavaUtils.class differ diff --git a/bin/LorexMC/us/utils/MapSorting$1.class b/bin/LorexMC/us/utils/MapSorting$1.class new file mode 100644 index 0000000..dadb3ee Binary files /dev/null and b/bin/LorexMC/us/utils/MapSorting$1.class differ diff --git a/bin/LorexMC/us/utils/MapSorting$2.class b/bin/LorexMC/us/utils/MapSorting$2.class new file mode 100644 index 0000000..67b1955 Binary files /dev/null and b/bin/LorexMC/us/utils/MapSorting$2.class differ diff --git a/bin/LorexMC/us/utils/MapSorting.class b/bin/LorexMC/us/utils/MapSorting.class new file mode 100644 index 0000000..61c1ab4 Binary files /dev/null and b/bin/LorexMC/us/utils/MapSorting.class differ diff --git a/bin/LorexMC/us/utils/NmsUtils.class b/bin/LorexMC/us/utils/NmsUtils.class new file mode 100644 index 0000000..7115d22 Binary files /dev/null and b/bin/LorexMC/us/utils/NmsUtils.class differ diff --git a/bin/LorexMC/us/utils/ParticleEffect.class b/bin/LorexMC/us/utils/ParticleEffect.class new file mode 100644 index 0000000..bf4f5b4 Binary files /dev/null and b/bin/LorexMC/us/utils/ParticleEffect.class differ diff --git a/bin/LorexMC/us/utils/PersistableLocation.class b/bin/LorexMC/us/utils/PersistableLocation.class new file mode 100644 index 0000000..62b53cf Binary files /dev/null and b/bin/LorexMC/us/utils/PersistableLocation.class differ diff --git a/bin/LorexMC/us/utils/SignHandler$1.class b/bin/LorexMC/us/utils/SignHandler$1.class new file mode 100644 index 0000000..9315a33 Binary files /dev/null and b/bin/LorexMC/us/utils/SignHandler$1.class differ diff --git a/bin/LorexMC/us/utils/SignHandler$SignChange.class b/bin/LorexMC/us/utils/SignHandler$SignChange.class new file mode 100644 index 0000000..ac7fc90 Binary files /dev/null and b/bin/LorexMC/us/utils/SignHandler$SignChange.class differ diff --git a/bin/LorexMC/us/utils/SignHandler.class b/bin/LorexMC/us/utils/SignHandler.class new file mode 100644 index 0000000..4b37c51 Binary files /dev/null and b/bin/LorexMC/us/utils/SignHandler.class differ diff --git a/bin/LorexMC/us/utils/SpigotUtils.class b/bin/LorexMC/us/utils/SpigotUtils.class new file mode 100644 index 0000000..6819b2b Binary files /dev/null and b/bin/LorexMC/us/utils/SpigotUtils.class differ diff --git a/bin/LorexMC/us/utils/UUIDFetcher.class b/bin/LorexMC/us/utils/UUIDFetcher.class new file mode 100644 index 0000000..dc75a06 Binary files /dev/null and b/bin/LorexMC/us/utils/UUIDFetcher.class differ diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class new file mode 100644 index 0000000..8ea2eac Binary files /dev/null and b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat$1.class differ diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class new file mode 100644 index 0000000..7af7121 Binary files /dev/null and b/bin/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.class differ diff --git a/bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class b/bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class new file mode 100644 index 0000000..0c0bcae Binary files /dev/null and b/bin/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.class differ diff --git a/bin/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.class b/bin/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.class new file mode 100644 index 0000000..fd3ec63 Binary files /dev/null and b/bin/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.class differ diff --git a/bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class b/bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class new file mode 100644 index 0000000..f434686 Binary files /dev/null and b/bin/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.class differ diff --git a/bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class b/bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class new file mode 100644 index 0000000..440e095 Binary files /dev/null and b/bin/LorexMC/us/utils/internal/com/bruce/base/Callback.class differ diff --git a/bin/LorexMC/us/utils/other/chat/ChatUtil.class b/bin/LorexMC/us/utils/other/chat/ChatUtil.class new file mode 100644 index 0000000..2ce938d Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/ChatUtil.class differ diff --git a/bin/LorexMC/us/utils/other/chat/ClickAction.class b/bin/LorexMC/us/utils/other/chat/ClickAction.class new file mode 100644 index 0000000..d2b84e1 Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/ClickAction.class differ diff --git a/bin/LorexMC/us/utils/other/chat/HoverAction.class b/bin/LorexMC/us/utils/other/chat/HoverAction.class new file mode 100644 index 0000000..135bf9a Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/HoverAction.class differ diff --git a/bin/LorexMC/us/utils/other/chat/Lang.class b/bin/LorexMC/us/utils/other/chat/Lang.class new file mode 100644 index 0000000..f855d84 Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/Lang.class differ diff --git a/bin/LorexMC/us/utils/other/chat/Text.class b/bin/LorexMC/us/utils/other/chat/Text.class new file mode 100644 index 0000000..3a50715 Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/Text.class differ diff --git a/bin/LorexMC/us/utils/other/chat/Trans.class b/bin/LorexMC/us/utils/other/chat/Trans.class new file mode 100644 index 0000000..cecb6df Binary files /dev/null and b/bin/LorexMC/us/utils/other/chat/Trans.class differ diff --git a/bin/LorexMC/us/utils/other/command/ArgumentExecutor.class b/bin/LorexMC/us/utils/other/command/ArgumentExecutor.class new file mode 100644 index 0000000..b4790ac Binary files /dev/null and b/bin/LorexMC/us/utils/other/command/ArgumentExecutor.class differ diff --git a/bin/LorexMC/us/utils/other/command/CommandArgument.class b/bin/LorexMC/us/utils/other/command/CommandArgument.class new file mode 100644 index 0000000..ea9195b Binary files /dev/null and b/bin/LorexMC/us/utils/other/command/CommandArgument.class differ diff --git a/bin/LorexMC/us/utils/other/command/CommandWrapper$ArgumentComparator.class b/bin/LorexMC/us/utils/other/command/CommandWrapper$ArgumentComparator.class new file mode 100644 index 0000000..6241881 Binary files /dev/null and b/bin/LorexMC/us/utils/other/command/CommandWrapper$ArgumentComparator.class differ diff --git a/bin/LorexMC/us/utils/other/command/CommandWrapper.class b/bin/LorexMC/us/utils/other/command/CommandWrapper.class new file mode 100644 index 0000000..65ce03f Binary files /dev/null and b/bin/LorexMC/us/utils/other/command/CommandWrapper.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class b/bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class new file mode 100644 index 0000000..b8e2ecd Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/CoordinatePair.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/Cuboid.class b/bin/LorexMC/us/utils/other/cuboid/Cuboid.class new file mode 100644 index 0000000..b13a68c Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/Cuboid.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.class b/bin/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.class new file mode 100644 index 0000000..b371c7e Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/CuboidDirection.class b/bin/LorexMC/us/utils/other/cuboid/CuboidDirection.class new file mode 100644 index 0000000..cba5a22 Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/CuboidDirection.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class b/bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class new file mode 100644 index 0000000..a688c5d Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.class differ diff --git a/bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class b/bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class new file mode 100644 index 0000000..8942328 Binary files /dev/null and b/bin/LorexMC/us/utils/other/cuboid/NamedCuboid.class differ diff --git a/bin/LorexMC/us/utils/other/imagemessage/ImageChar.class b/bin/LorexMC/us/utils/other/imagemessage/ImageChar.class new file mode 100644 index 0000000..1f9f4d9 Binary files /dev/null and b/bin/LorexMC/us/utils/other/imagemessage/ImageChar.class differ diff --git a/bin/LorexMC/us/utils/other/imagemessage/ImageMessage.class b/bin/LorexMC/us/utils/other/imagemessage/ImageMessage.class new file mode 100644 index 0000000..6ea93b9 Binary files /dev/null and b/bin/LorexMC/us/utils/other/imagemessage/ImageMessage.class differ diff --git a/bin/LorexMC/us/utils/other/itemdb/ItemData.class b/bin/LorexMC/us/utils/other/itemdb/ItemData.class new file mode 100644 index 0000000..bf580b9 Binary files /dev/null and b/bin/LorexMC/us/utils/other/itemdb/ItemData.class differ diff --git a/bin/LorexMC/us/utils/other/itemdb/ItemDb.class b/bin/LorexMC/us/utils/other/itemdb/ItemDb.class new file mode 100644 index 0000000..f909c97 Binary files /dev/null and b/bin/LorexMC/us/utils/other/itemdb/ItemDb.class differ diff --git a/bin/LorexMC/us/utils/other/itemdb/ManagedFile.class b/bin/LorexMC/us/utils/other/itemdb/ManagedFile.class new file mode 100644 index 0000000..1b6572a Binary files /dev/null and b/bin/LorexMC/us/utils/other/itemdb/ManagedFile.class differ diff --git a/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb$1.class b/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb$1.class new file mode 100644 index 0000000..bc050f3 Binary files /dev/null and b/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb$1.class differ diff --git a/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb.class b/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb.class new file mode 100644 index 0000000..d2ea33c Binary files /dev/null and b/bin/LorexMC/us/utils/other/itemdb/SimpleItemDb.class differ diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..257aa50 --- /dev/null +++ b/bin/README.md @@ -0,0 +1,2 @@ +# Vengefull +A bruceboy skid diff --git a/bin/Vengeful.iml b/bin/Vengeful.iml new file mode 100644 index 0000000..914d662 --- /dev/null +++ b/bin/Vengeful.iml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/bin/balances.yml b/bin/balances.yml new file mode 100644 index 0000000..18e0854 --- /dev/null +++ b/bin/balances.yml @@ -0,0 +1 @@ +balances: {} diff --git a/bin/config.yml b/bin/config.yml new file mode 100644 index 0000000..65a5faf --- /dev/null +++ b/bin/config.yml @@ -0,0 +1,87 @@ +death-signs: true +diamond-ore-notifications: true +death-lightning: true +map-number: 1 +kit-map: true +prevent-ally-damage: true +exp-multiplier: + global: 2.0 + fishing: 2.0 + smelting: 2.0 + looting-per-level: 1.5 + luck-per-level: 1.5 + fortune-per-level: 1.5 +roads: + allow-claims-besides: true +scoreboard: + sidebar: + title: "" + enabled: true + nametags: + enabled: true +combatlog: + enabled: true + despawn-delay-ticks: 600 +conquest: + point-loss-per-death: 20 + victory-points: 300 + allow-negative-points: true +warzone: + radius: 1000 +factions: + disallowed-faction-names: + - EOTW + min-name-characters: 3 + max-name-characters: 16 + max-members: 25 + max-allies: 1 +subclaims: + min-name-characters: 3 + max-name-characters: 16 +relation-colours: + wilderness: DARK_GREEN + warzone: LIGHT_PURPLE + teammate: GREEN + ally: GOLD + enemy: RED + road: GOLD +deaths-till-raidable: + maximum: 6 + millis-between-updates: 45000 + increment-between-updates: 0.1 +deathban: + base-duration-minutes: 120 + respawn-screen-seconds-before-kick: 15 +enchantment-limits: + PROTECTION_ENVIRONMENTAL: 3 + PROTECTION_FIRE: 3 + SILK_TOUCH: 1 + DURABILITY: 3 + PROTECTION_EXPLOSIONS: 3 + LOOT_BONUS_BLOCKS: 3 + PROTECTION_PROJECTILE: 3 + OXYGEN: 3 + WATER_WORKER: 1 + THORNS: 0 + DAMAGE_ALL: 3 + ARROW_KNOCKBACK: 1 + KNOCKBACK: 1 + FIRE_ASPECT: 1 + LOOT_BONUS_MOBS: 3 + LUCK: 3 + LURE: 3 +end: + open: true + exit: world,0.5,75,0.5,0,0 +eotw: + chat-symbol-prefix: "" + chat-symbol-suffix: "" + last-map-cappers: [] +potion-limits: + STRENGTH: 0 + INVISIBILITY: 0 + REGEN: 0 + WEAKNESS: 0 + INSTANT_DAMAGE: 0 + SLOWNESS: 1 + POISON: 1 diff --git a/bin/coords.txt b/bin/coords.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/enderdragon-art-old.png b/bin/enderdragon-art-old.png new file mode 100644 index 0000000..e33ffd6 Binary files /dev/null and b/bin/enderdragon-art-old.png differ diff --git a/bin/enderdragon-art.png b/bin/enderdragon-art.png new file mode 100644 index 0000000..31c18b3 Binary files /dev/null and b/bin/enderdragon-art.png differ diff --git a/bin/event-schedules.txt b/bin/event-schedules.txt new file mode 100644 index 0000000..3ee09a6 --- /dev/null +++ b/bin/event-schedules.txt @@ -0,0 +1,2 @@ +# year, month, day, hour, minute: eventName (24 hour clock) +# 2015,1,1,2,0:Example This would run event named 'Example' at 2AM on the 1st of January, 2015. diff --git a/bin/faction-users.yml b/bin/faction-users.yml new file mode 100644 index 0000000..bf82e98 --- /dev/null +++ b/bin/faction-users.yml @@ -0,0 +1 @@ +users: {} diff --git a/bin/factions.yml b/bin/factions.yml new file mode 100644 index 0000000..10bc293 --- /dev/null +++ b/bin/factions.yml @@ -0,0 +1 @@ +factions: {} diff --git a/bin/gopple-art.png b/bin/gopple-art.png new file mode 100644 index 0000000..08c061a Binary files /dev/null and b/bin/gopple-art.png differ diff --git a/bin/help.txt b/bin/help.txt new file mode 100644 index 0000000..e69de29 diff --git a/bin/items.csv b/bin/items.csv new file mode 100644 index 0000000..49dd25c --- /dev/null +++ b/bin/items.csv @@ -0,0 +1,7451 @@ +#This file belongs to Essentials. +#version: TeamCity +#If you change this file, it will not be automatically updated after the next release. +#item,id,metadata +stone,1,0 +sstone,1,0 +smoothstone,1,0 +rock,1,0 +grass,2,0 +greendirt,2,0 +greenearth,2,0 +greenland,2,0 +dirt,3,0 +earth,3,0 +land,3,0 +grasslessdirt,3,1 +grasslessearth,3,1 +grasslessland,3,1 +podzol,3,2 +cobblestone,4,0 +cstone,4,0 +cobble,4,0 +wood,5,0 +plank,5,0 +woodenplank,5,0 +woodplank,5,0 +wplank,5,0 +plankwooden,5,0 +plankwood,5,0 +plankw,5,0 +oakplank,5,0 +oakwoodenplank,5,0 +oakwoodplank,5,0 +oakwplank,5,0 +oakplankwooden,5,0 +oakplankwood,5,0 +oakplankw,5,0 +oplank,5,0 +owoodenplank,5,0 +owoodplank,5,0 +owplank,5,0 +oplankwooden,5,0 +oplankwood,5,0 +oplankw,5,0 +pineplank,5,1 +pinewoodenplank,5,1 +pinewoodplank,5,1 +pinewplank,5,1 +pineplankwooden,5,1 +pineplankwood,5,1 +pineplankw,5,1 +pplank,5,1 +pwoodenplank,5,1 +pwoodplank,5,1 +pwplank,5,1 +pplankwooden,5,1 +pplankwood,5,1 +pplankw,5,1 +darkplank,5,1 +darkwoodenplank,5,1 +darkwoodplank,5,1 +darkwplank,5,1 +darkplankwooden,5,1 +darkplankwood,5,1 +darkplankw,5,1 +dplank,5,1 +dwoodenplank,5,1 +dwoodplank,5,1 +dwplank,5,1 +dplankwooden,5,1 +dplankwood,5,1 +dplankw,5,1 +spruceplank,5,1 +sprucewoodenplank,5,1 +sprucewoodplank,5,1 +sprucewplank,5,1 +spruceplankwooden,5,1 +spruceplankwood,5,1 +spruceplankw,5,1 +splank,5,1 +swoodenplank,5,1 +swoodplank,5,1 +swplank,5,1 +splankwooden,5,1 +splankwood,5,1 +splankw,5,1 +birchplank,5,2 +birchwoodenplank,5,2 +birchwoodplank,5,2 +birchwplank,5,2 +birchplankwooden,5,2 +birchplankwood,5,2 +birchplankw,5,2 +bplank,5,2 +bwoodenplank,5,2 +bwoodplank,5,2 +bwplank,5,2 +bplankwooden,5,2 +bplankwood,5,2 +bplankw,5,2 +lightplank,5,2 +lightwoodenplank,5,2 +lightwoodplank,5,2 +lightwplank,5,2 +lightplankwooden,5,2 +lightplankwood,5,2 +lightplankw,5,2 +lplank,5,2 +lwoodenplank,5,2 +lwoodplank,5,2 +lwplank,5,2 +lplankwooden,5,2 +lplankwood,5,2 +lplankw,5,2 +whiteplank,5,2 +whitewoodenplank,5,2 +whitewoodplank,5,2 +whitewplank,5,2 +whiteplankwooden,5,2 +whiteplankwood,5,2 +whiteplankw,5,2 +wwoodenplank,5,2 +wwoodplank,5,2 +wwplank,5,2 +wplankwooden,5,2 +wplankwood,5,2 +wplankw,5,2 +jungleplank,5,3 +junglewoodenplank,5,3 +junglewoodplank,5,3 +junglewplank,5,3 +jungleplankwooden,5,3 +jungleplankwood,5,3 +jungleplankw,5,3 +jplank,5,3 +jwoodenplank,5,3 +jwoodplank,5,3 +jwplank,5,3 +jplankwooden,5,3 +jplankwood,5,3 +jplankw,5,3 +forestplank,5,3 +forestwoodenplank,5,3 +forestwoodplank,5,3 +forestwplank,5,3 +forestplankwooden,5,3 +forestplankwood,5,3 +forestplankw,5,3 +fplank,5,3 +fwoodenplank,5,3 +fwoodplank,5,3 +fwplank,5,3 +fplankwooden,5,3 +fplankwood,5,3 +fplankw,5,3 +acaciaplank,5,4 +acaciawoodenplank,5,4 +acaciawoodplank,5,4 +acaciawplank,5,4 +acaciaplankwooden,5,4 +acaciaplankwood,5,4 +acaciaplankw,5,4 +aplank,5,4 +awoodenplank,5,4 +awoodplank,5,4 +awplank,5,4 +aplankwooden,5,4 +aplankwood,5,4 +aplankw,5,4 +darkoakplank,5,5 +darkoakwoodenplank,5,5 +darkoakwoodplank,5,5 +darkoakwplank,5,5 +darkoakplankwooden,5,5 +darkoakplankwood,5,5 +darkoakplankw,5,5 +doakplank,5,5 +doakwoodenplank,5,5 +doakwoodplank,5,5 +doakwplank,5,5 +doakplankwooden,5,5 +doakplankwood,5,5 +doakplankw,5,5 +doplank,5,5 +dowoodenplank,5,5 +dowoodplank,5,5 +dowplank,5,5 +doplankwooden,5,5 +doplankwood,5,5 +doplankw,5,5 +sapling,6,0 +treesapling,6,0 +logsapling,6,0 +trunksapling,6,0 +woodsapling,6,0 +oaktreesapling,6,0 +oaklogsapling,6,0 +oaktrunksapling,6,0 +oakwoodsapling,6,0 +osapling,6,0 +otreesapling,6,0 +ologsapling,6,0 +otrunksapling,6,0 +owoodsapling,6,0 +darksapling,6,1 +darktreesapling,6,1 +darklogsapling,6,1 +darktrunksapling,6,1 +darkwoodsapling,6,1 +sprucesapling,6,1 +sprucetreesapling,6,1 +sprucelogsapling,6,1 +sprucetrunksapling,6,1 +sprucewoodsapling,6,1 +pinesapling,6,1 +pinetreesapling,6,1 +pinelogsapling,6,1 +pinetrunksapling,6,1 +pinewoodsapling,6,1 +dsapling,6,1 +dtreesapling,6,1 +dlogsapling,6,1 +dtrunksapling,6,1 +dwoodsapling,6,1 +ssapling,6,1 +streesapling,6,1 +slogsapling,6,1 +strunksapling,6,1 +swoodsapling,6,1 +psapling,6,1 +ptreesapling,6,1 +plogsapling,6,1 +ptrunksapling,6,1 +pwoodsapling,6,1 +birchsapling,6,2 +birchtreesapling,6,2 +birchlogsapling,6,2 +birchtrunksapling,6,2 +birchwoodsapling,6,2 +lightsapling,6,2 +lighttreesapling,6,2 +lightlogsapling,6,2 +lighttrunksapling,6,2 +lightwoodsapling,6,2 +whitesapling,6,2 +whitetreesapling,6,2 +whitelogsapling,6,2 +whitetrunksapling,6,2 +whitewoodsapling,6,2 +bsapling,6,2 +btreesapling,6,2 +blogsapling,6,2 +btrunksapling,6,2 +bwoodsapling,6,2 +lsapling,6,2 +ltreesapling,6,2 +llogsapling,6,2 +ltrunksapling,6,2 +lwoodsapling,6,2 +wsapling,6,2 +wtreesapling,6,2 +wlogsapling,6,2 +wtrunksapling,6,2 +wwoodsapling,6,2 +junglesapling,6,3 +jungletreesapling,6,3 +junglelogsapling,6,3 +jungletrunksapling,6,3 +junglewoodsapling,6,3 +forestsapling,6,3 +foresttreesapling,6,3 +forestlogsapling,6,3 +foresttrunksapling,6,3 +forestwoodsapling,6,3 +jsapling,6,3 +jtreesapling,6,3 +jlogsapling,6,3 +jtrunksapling,6,3 +jwoodsapling,6,3 +fsapling,6,3 +ftreesapling,6,3 +flogsapling,6,3 +ftrunksapling,6,3 +fwoodsapling,6,3 +acaciasapling,6,4 +acaciatreesapling,6,4 +acacialogsapling,6,4 +acaciatrunksapling,6,4 +acaciawoodsapling,6,4 +asapling,6,4 +atreesapling,6,4 +alogsapling,6,4 +atrunksapling,6,4 +awoodsapling,6,4 +darkoaksapling,6,5 +darkoaktreesapling,6,5 +darkoaklogsapling,6,5 +darkoaktrunksapling,6,5 +darkoakwoodsapling,6,5 +doaksapling,6,5 +doaktreesapling,6,5 +doaklogsapling,6,5 +doaktrunksapling,6,5 +dosapling,6,5 +dowoodsapling,6,5 +dotreesapling,6,5 +dologsapling,6,5 +dotrunksapling,6,5 +bedrock,7,0 +oprock,7,0 +opblock,7,0 +adminblock,7,0 +adminrock,7,0 +adminium,7,0 +water,8,0 +stationarywater,9,0 +stillwater,9,0 +swater,9,0 +lava,10,0 +stationarylava,11,0 +stilllava,11,0 +slava,11,0 +sand,12,0 +redsand,12,1 +rsand,12,1 +gravel,13,0 +goldore,14,0 +oregold,14,0 +gore,14,0 +oreg,14,0 +ogold,14,0 +goldo,14,0 +ironore,15,0 +oreiron,15,0 +irono,15,0 +oiron,15,0 +steelore,15,0 +oresteel,15,0 +steelo,15,0 +osteel,15,0 +iore,15,0 +orei,15,0 +sore,15,0 +ores,15,0 +coalore,16,0 +orecoal,16,0 +coalo,16,0 +ocoal,16,0 +core,16,0 +tree,17,0 +log,17,0 +trunk,17,0 +oak,17,0 +oaktree,17,0 +oaklog,17,0 +oaktrunk,17,0 +oakwood,17,0 +otree,17,0 +olog,17,0 +otrunk,17,0 +owood,17,0 +pine,17,1 +pinetree,17,1 +pinelog,17,1 +pinetrunk,17,1 +pinewood,17,1 +darktree,17,1 +darklog,17,1 +darktrunk,17,1 +darkwood,17,1 +spruce,17,1 +sprucetree,17,1 +sprucelog,17,1 +sprucetrunk,17,1 +sprucewood,17,1 +dtree,17,1 +dlog,17,1 +dtrunk,17,1 +dwood,17,1 +stree,17,1 +slog,17,1 +strunk,17,1 +swood,17,1 +ptree,17,1 +plog,17,1 +ptrunk,17,1 +pwood,17,1 +birch,17,2 +birchtree,17,2 +birchlog,17,2 +birchtrunk,17,2 +birchwood,17,2 +whitetree,17,2 +whitelog,17,2 +whitetrunk,17,2 +whitewood,17,2 +lighttree,17,2 +lightlog,17,2 +lighttrunk,17,2 +lightwood,17,2 +btree,17,2 +blog,17,2 +btrunk,17,2 +bwood,17,2 +wtree,17,2 +wlog,17,2 +wtrunk,17,2 +wwood,17,2 +ltree,17,2 +llog,17,2 +ltrunk,17,2 +lwood,17,2 +jungletree,17,3 +junglelog,17,3 +jungletrunk,17,3 +junglewood,17,3 +jungle,17,3 +forest,17,3 +foresttree,17,3 +forestlog,17,3 +foresttrunk,17,3 +forestwood,17,3 +jtree,17,3 +jlog,17,3 +jtrunk,17,3 +jwood,17,3 +ftree,17,3 +flog,17,3 +ftrunk,17,3 +fwood,17,3 +leaves,18,0 +leaf,18,0 +treeleaves,18,0 +logleaves,18,0 +trunkleaves,18,0 +woodleaves,18,0 +oakleaves,18,0 +oakleaf,18,0 +oleaves,18,0 +oleaf,18,0 +oaktreeleaves,18,0 +oaklogleaves,18,0 +oaktrunkleaves,18,0 +oakwoodleaves,18,0 +otreeleaves,18,0 +ologleaves,18,0 +otrunkleaves,18,0 +owoodleaves,18,0 +treeleaf,18,0 +logleaf,18,0 +trunkleaf,18,0 +woodleaf,18,0 +oaktreeleaf,18,0 +oaklogleaf,18,0 +oaktrunkleaf,18,0 +oakwoodleaf,18,0 +otreeleaf,18,0 +ologleaf,18,0 +otrunkleaf,18,0 +owoodleaf,18,0 +pineleaves,18,1 +pineleaf,18,1 +pleaves,18,1 +pleaf,18,1 +pinetreeleaves,18,1 +pinelogleaves,18,1 +pinetrunkleaves,18,1 +pinewoodleaves,18,1 +ptreeleaves,18,1 +plogleaves,18,1 +ptrunkleaves,18,1 +pwoodleaves,18,1 +spruceleaves,18,1 +spruceleaf,18,1 +sleaves,18,1 +sleaf,18,1 +sprucetreeleaves,18,1 +sprucelogleaves,18,1 +sprucetrunkleaves,18,1 +sprucewoodleaves,18,1 +streeleaves,18,1 +slogleaves,18,1 +strunkleaves,18,1 +swoodleaves,18,1 +darkleaves,18,1 +darkleaf,18,1 +dleaves,18,1 +dleaf,18,1 +darktreeleaves,18,1 +darklogleaves,18,1 +darktrunkleaves,18,1 +darkwoodleaves,18,1 +dtreeleaves,18,1 +dlogleaves,18,1 +dtrunkleaves,18,1 +dwoodleaves,18,1 +sprucetreeleaf,18,1 +sprucelogleaf,18,1 +sprucetrunkleaf,18,1 +sprucewoodleaf,18,1 +streeleaf,18,1 +slogleaf,18,1 +strunkleaf,18,1 +swoodleaf,18,1 +pinetreeleaf,18,1 +pinelogleaf,18,1 +pinetrunkleaf,18,1 +pinewoodleaf,18,1 +ptreeleaf,18,1 +plogleaf,18,1 +ptrunkleaf,18,1 +pwoodleaf,18,1 +darktreeleaf,18,1 +darklogleaf,18,1 +darktrunkleaf,18,1 +darkwoodleaf,18,1 +dtreeleaf,18,1 +dlogleaf,18,1 +dtrunkleaf,18,1 +dwoodleaf,18,1 +birchleaves,18,2 +birchleaf,18,2 +bleaves,18,2 +bleaf,18,2 +birchtreeleaves,18,2 +birchlogleaves,18,2 +birchtrunkleaves,18,2 +birchwoodleaves,18,2 +btreeleaves,18,2 +blogleaves,18,2 +btrunkleaves,18,2 +bwoodleaves,18,2 +lightleaves,18,2 +lightleaf,18,2 +lleaves,18,2 +lleaf,18,2 +lighttreeleaves,18,2 +lightlogleaves,18,2 +lighttrunkleaves,18,2 +lightwoodleaves,18,2 +ltreeleaves,18,2 +llogleaves,18,2 +ltrunkleaves,18,2 +lwoodleaves,18,2 +whiteleaves,18,2 +whiteleaf,18,2 +wleaves,18,2 +wleaf,18,2 +whitetreeleaves,18,2 +whitelogleaves,18,2 +whitetrunkleaves,18,2 +whitewoodleaves,18,2 +wtreeleaves,18,2 +wlogleaves,18,2 +wtrunkleaves,18,2 +wwoodleaves,18,2 +birchtreeleaf,18,2 +birchlogleaf,18,2 +birchtrunkleaf,18,2 +birchwoodleaf,18,2 +btreeleaf,18,2 +blogleaf,18,2 +btrunkleaf,18,2 +bwoodleaf,18,2 +lighttreeleaf,18,2 +lightlogleaf,18,2 +lighttrunkleaf,18,2 +lightwoodleaf,18,2 +ltreeleaf,18,2 +llogleaf,18,2 +ltrunkleaf,18,2 +lwoodleaf,18,2 +whitetreeleaf,18,2 +whitelogleaf,18,2 +whitetrunkleaf,18,2 +whitewoodleaf,18,2 +wtreeleaf,18,2 +wlogleaf,18,2 +wtrunkleaf,18,2 +wwoodleaf,18,2 +jungleleaves,18,3 +jungleleaf,18,3 +jleaves,18,3 +jleaf,18,3 +jungletreeleaves,18,3 +junglelogleaves,18,3 +jungletrunkleaves,18,3 +junglewoodleaves,18,3 +jtreeleaves,18,3 +jlogleaves,18,3 +jtrunkleaves,18,3 +jwoodleaves,18,3 +forestleaves,18,3 +forestleaf,18,3 +fleaves,18,3 +fleaf,18,3 +foresttreeleaves,18,3 +forestlogleaves,18,3 +foresttrunkleaves,18,3 +forestwoodleaves,18,3 +ftreeleaves,18,3 +flogleaves,18,3 +ftrunkleaves,18,3 +fwoodleaves,18,3 +jungletreeleaf,18,3 +junglelogleaf,18,3 +jungletrunkleaf,18,3 +junglewoodleaf,18,3 +jtreeleaf,18,3 +jlogleaf,18,3 +jtrunkleaf,18,3 +jwoodleaf,18,3 +foresttreeleaf,18,3 +forestlogleaf,18,3 +foresttrunkleaf,18,3 +forestwoodleaf,18,3 +ftreeleaf,18,3 +flogleaf,18,3 +ftrunkleaf,18,3 +fwoodleaf,18,3 +sponge,19,0 +glass,20,0 +blockglass,20,0 +glassblock,20,0 +lapislazuliore,21,0 +lapislazulio,21,0 +orelapislazuli,21,0 +olapislazuli,21,0 +lapisore,21,0 +lapiso,21,0 +orelapis,21,0 +olapis,21,0 +lore,21,0 +orel,21,0 +lapislazuliblock,22,0 +blocklapislazuli,22,0 +lapisblock,22,0 +blocklapis,22,0 +lblock,22,0 +blockl,22,0 +dispenser,23,0 +dispense,23,0 +sandstone,24,0 +sastone,24,0 +creepersandstone,24,1 +creepersastone,24,1 +creepsandstone,24,1 +creepsastone,24,1 +csandstone,24,1 +csastone,24,1 +hieroglyphicsandstone,24,1 +hieroglyphicsastone,24,1 +hieroglyphsandstone,24,1 +hieroglyphsastone,24,1 +hsandstone,24,1 +hsastone,24,1 +pyramidsandstone,24,1 +pyramidsastone,24,1 +psandstone,24,1 +psastone,24,1 +chiseledsandstone,24,1 +chiseledsastone,24,1 +chiselsandstone,24,1 +chiselsastone,24,1 +smoothsandstone,24,2 +smoothsastone,24,2 +ssandstone,24,2 +smsastone,24,2 +ssastone,24,2 +noteblock,25,0 +musicblock,25,0 +nblock,25,0 +mblock,25,0 +poweredtrack,27,0 +poweredrails,27,0 +poweredrail,27,0 +boostertrack,27,0 +boosterrails,27,0 +boosterrail,27,0 +powertrack,27,0 +powerrails,27,0 +powerrail,27,0 +boosttrack,27,0 +boostrails,27,0 +boostrail,27,0 +ptrack,27,0 +prails,27,0 +prail,27,0 +btrack,27,0 +brails,27,0 +brail,27,0 +detectortrack,28,0 +detectorrails,28,0 +detectorrail,28,0 +detectingtrack,28,0 +detectingrails,28,0 +detectingrail,28,0 +detecttrack,28,0 +detectrails,28,0 +detectrail,28,0 +dtrack,28,0 +drails,28,0 +drail,28,0 +stickypistonbase,29,0 +stickypiston,29,0 +stickpistonbase,29,0 +stickpiston,29,0 +stickyp,29,0 +spistonbase,29,0 +spiston,29,0 +pistonstickybase,29,0 +pistonsticky,29,0 +pistonstickbase,29,0 +pistonstick,29,0 +pistonsbase,29,0 +pistons,29,0 +psticky,29,0 +pstick,29,0 +spiderweb,30,0 +cobweb,30,0 +sweb,30,0 +cweb,30,0 +web,30,0 +longgrass,31,1 +tallgrass,31,1 +wildgrass,31,1 +grasslong,31,1 +grasstall,31,1 +grasswild,31,1 +lgrass,31,1 +tgrass,31,1 +wgrass,31,1 +fern,31,2 +bush,31,2 +deadshrub,32,0 +dshrub,32,0 +deadbush,32,0 +dbush,32,0 +deadsapling,32,0 +piston,33,0 +pistonbase,33,0 +pistonblock,33,0 +whitewool,35,0 +whitecloth,35,0 +whitecotton,35,0 +wcloth,35,0 +wwool,35,0 +wcotton,35,0 +cloth,35,0 +wool,35,0 +cotton,35,0 +orangewool,35,1 +orangecloth,35,1 +orangecotton,35,1 +ocloth,35,1 +owool,35,1 +ocotton,35,1 +magentawool,35,2 +magentacloth,35,2 +magentacotton,35,2 +mcloth,35,2 +mwool,35,2 +mcotton,35,2 +lightbluewool,35,3 +lightbluecloth,35,3 +lightbluecotton,35,3 +lbluecloth,35,3 +lbluewool,35,3 +lbluecotton,35,3 +lightblucloth,35,3 +lightbluwool,35,3 +lightblucotton,35,3 +lblucloth,35,3 +lbluwool,35,3 +lblucotton,35,3 +lbcloth,35,3 +lbwool,35,3 +lbcotton,35,3 +yellowwool,35,4 +yellowcloth,35,4 +yellowcotton,35,4 +ycloth,35,4 +ywool,35,4 +ycotton,35,4 +lightgreenwool,35,5 +lightgreencloth,35,5 +lightgreencotton,35,5 +lgreencloth,35,5 +lgreenwool,35,5 +lgreencotton,35,5 +lightgrecloth,35,5 +lightgrewool,35,5 +lightgrecotton,35,5 +lgrecloth,35,5 +lgrewool,35,5 +lgrecotton,35,5 +limecloth,35,5 +limewool,35,5 +limecotton,35,5 +lcloth,35,5 +lwool,35,5 +lcotton,35,5 +pinkwool,35,6 +pinkcloth,35,6 +pinkcotton,35,6 +picloth,35,6 +piwool,35,6 +picotton,35,6 +darkgraywool,35,7 +darkgraycloth,35,7 +darkgraycotton,35,7 +darkgreywool,35,7 +darkgreycloth,35,7 +darkgreycotton,35,7 +dgraycloth,35,7 +dgraywool,35,7 +dgraycotton,35,7 +dgreycloth,35,7 +dgreywool,35,7 +dgreycotton,35,7 +darkgracloth,35,7 +darkgrawool,35,7 +darkgracotton,35,7 +dgracloth,35,7 +dgrawool,35,7 +dgracotton,35,7 +graycloth,35,7 +graywool,35,7 +graycotton,35,7 +greycloth,35,7 +greywool,35,7 +greycotton,35,7 +gracloth,35,7 +grawool,35,7 +gracotton,35,7 +lightgraywool,35,8 +lightgraycloth,35,8 +lightgraycotton,35,8 +lgraycloth,35,8 +lgraywool,35,8 +lgraycotton,35,8 +lightgreywool,35,8 +lightgreycloth,35,8 +lightgreycotton,35,8 +lgreycloth,35,8 +lgreywool,35,8 +lgreycotton,35,8 +lightgracloth,35,8 +lightgrawool,35,8 +lightgracotton,35,8 +lgracloth,35,8 +lgrawool,35,8 +lgracotton,35,8 +silvercloth,35,8 +silverwool,35,8 +silvercotton,35,8 +sicloth,35,8 +siawool,35,8 +siacotton,35,8 +cyanwool,35,9 +cyancloth,35,9 +cyancotton,35,9 +ccloth,35,9 +cwool,35,9 +ccotton,35,9 +purplewool,35,10 +purplecloth,35,10 +purplecotton,35,10 +pucloth,35,10 +puwool,35,10 +pucotton,35,10 +bluewool,35,11 +bluecloth,35,11 +bluecotton,35,11 +blucloth,35,11 +bluwool,35,11 +blucotton,35,11 +brownwool,35,12 +browncloth,35,12 +browncotton,35,12 +brocloth,35,12 +browool,35,12 +brocotton,35,12 +darkgreenwool,35,13 +darkgreencloth,35,13 +darkgreencotton,35,13 +dgreencloth,35,13 +dgreenwool,35,13 +dgreencotton,35,13 +greencloth,35,13 +greenwool,35,13 +greencotton,35,13 +darkgrecloth,35,13 +darkgrewool,35,13 +darkgrecotton,35,13 +dgrecloth,35,13 +dgrewool,35,13 +dgrecotton,35,13 +grecloth,35,13 +grewool,35,13 +grecotton,35,13 +redwool,35,14 +redcloth,35,14 +redcotton,35,14 +rcloth,35,14 +rwool,35,14 +rcotton,35,14 +blackwool,35,15 +blackcloth,35,15 +blackcotton,35,15 +blacloth,35,15 +blawool,35,15 +blacotton,35,15 +dandelion,37,0 +yellowdandelion,37,0 +ydandelion,37,0 +yellowflower,37,0 +yflower,37,0 +flower,37,0 +rose,38,0 +redrose,38,0 +rrose,38,0 +redflower,38,0 +rflower,38,0 +poppy,38,0 +redpoppy,38,0 +blueorchid,38,1 +cyanorchid,38,1 +lightblueorchid,38,1 +lblueorchid,38,1 +orchid,38,1 +allium,38,2 +magentaallium,38,2 +azurebluet,38,3 +whiteazurebluet,38,3 +abluet,38,3 +azureb,38,3 +houstonia,38,3 +redtulip,38,4 +tulipred,38,4 +rtulip,38,4 +tulipr,38,4 +orangetulip,38,5 +tuliporange,38,5 +otulip,38,5 +tulipo,38,5 +whitetulip,38,6 +tulipwhite,38,6 +wtulip,38,6 +tulipw,38,6 +pinktulip,38,7 +tulippink,38,7 +ptulip,38,7 +tulipp,38,7 +oxeye,38,8 +daisy,38,8 +oxeyedaisy,38,8 +daisyoxeye,38,8 +moondaisy,38,8 +daisymoon,38,8 +lightgrayoxeye,38,8 +lgrayoxeye,38,8 +lightgreyoxeye,38,8 +lgreyoxeye,38,8 +brownmushroom,39,0 +brownshroom,39,0 +brownmush,39,0 +bmushroom,39,0 +bshroom,39,0 +bmush,39,0 +redmushroom,40,0 +redshroom,40,0 +redmush,40,0 +rmushroom,40,0 +rshroom,40,0 +rmush,40,0 +goldblock,41,0 +blockgold,41,0 +gblock,41,0 +blockg,41,0 +ironblock,42,0 +steelblock,42,0 +blockiron,42,0 +blocksteel,42,0 +iblock,42,0 +stblock,42,0 +blocki,42,0 +blockst,42,0 +stonedoublestep,43,0 +stonedstep,43,0 +sdoublestep,43,0 +sdstep,43,0 +doublestonestep,43,0 +dstonestep,43,0 +doublesstep,43,0 +doublestep,43,0 +dstep,43,0 +stonedoubleslab,43,0 +stonedslab,43,0 +sdoubleslab,43,0 +sdslab,43,0 +doublestoneslab,43,0 +dstoneslab,43,0 +doublesslab,43,0 +doubleslab,43,0 +dslab,43,0 +stonedoublehalfblock,43,0 +stonedhalfblock,43,0 +sdoublehalfblock,43,0 +sdhalfblock,43,0 +doublestonehalfblock,43,0 +dstonehalfblock,43,0 +doubleshalfblock,43,0 +doublehalfblock,43,0 +dhalfblock,43,0 +sandstonedoublestep,43,1 +sandstonedstep,43,1 +sstonedoublestep,43,1 +sstonedstep,43,1 +ssdoublestep,43,1 +ssdstep,43,1 +doublesandstonestep,43,1 +dsandstonestep,43,1 +doublesstonestep,43,1 +dsstonestep,43,1 +doublessstep,43,1 +dsstep,43,1 +sandstonedoubleslab,43,1 +sandstonedslab,43,1 +sstonedoubleslab,43,1 +sstonedslab,43,1 +ssdoubleslab,43,1 +ssdslab,43,1 +doublesandstoneslab,43,1 +dsandstoneslab,43,1 +doublesstoneslab,43,1 +dsstoneslab,43,1 +doublessslab,43,1 +dsslab,43,1 +sandstonedoublehalfblock,43,1 +sandstonedhalfblock,43,1 +sstonedoublehalfblock,43,1 +sstonedhalfblock,43,1 +ssdoublehalfblock,43,1 +ssdhalfblock,43,1 +doublesandstonehalfblock,43,1 +dsandstonehalfblock,43,1 +doublesstonehalfblock,43,1 +dsstonehalfblock,43,1 +doublesshalfblock,43,1 +dsshalfblock,43,1 +plankstonedoublestep,43,2 +woodenstonedoublestep,43,2 +woodenstonedstep,43,2 +woodstonedoublestep,43,2 +woodstonedstep,43,2 +wstonedoublestep,43,2 +wstonedstep,43,2 +doublewoodenstonestep,43,2 +dwoodenstonestep,43,2 +doublewoodstonestep,43,2 +dwoodstonestep,43,2 +doublewstonestep,43,2 +dwstonestep,43,2 +woodenstonedoubleslab,43,2 +woodenstonedslab,43,2 +woodstonedoubleslab,43,2 +woodstonedslab,43,2 +wstonedoubleslab,43,2 +wstonedslab,43,2 +doublewoodenstoneslab,43,2 +dwoodenstoneslab,43,2 +doublewoodstoneslab,43,2 +dwoodstoneslab,43,2 +doublewstoneslab,43,2 +dwstoneslab,43,2 +woodenstonedoublehalfblock,43,2 +woodenstonedhalfblock,43,2 +woodstonedoublehalfblock,43,2 +woodstonedhalfblock,43,2 +wstonedoublehalfblock,43,2 +wstonedhalfblock,43,2 +doublewoodenstonehalfblock,43,2 +dwoodenstonehalfblock,43,2 +doublewoodstonehalfblock,43,2 +dwoodstonehalfblock,43,2 +doublewstonehalfblock,43,2 +dwstonehalfblock,43,2 +cobblestonedoublestep,43,3 +cobblestonedstep,43,3 +cobbledoublestep,43,3 +cobbledstep,43,3 +cstonedoublestep,43,3 +cstonedstep,43,3 +csdoublestep,43,3 +csdstep,43,3 +doublecobblestonestep,43,3 +dcobblestonestep,43,3 +doublecobblestep,43,3 +dcobblestep,43,3 +doublecstonestep,43,3 +dcstonestep,43,3 +doublecsstep,43,3 +dcsstep,43,3 +cobblestonedoubleslab,43,3 +cobblestonedslab,43,3 +cobbledoubleslab,43,3 +cobbledslab,43,3 +cstonedoubleslab,43,3 +cstonedslab,43,3 +csdoubleslab,43,3 +csdslab,43,3 +doublecobblestoneslab,43,3 +dcobblestoneslab,43,3 +doublecobbleslab,43,3 +dcobbleslab,43,3 +doublecstoneslab,43,3 +dcstoneslab,43,3 +doublecsslab,43,3 +dcsslab,43,3 +cobblestonedoublehalfblock,43,3 +cobblestonedhalfblock,43,3 +cobbledoublehalfblock,43,3 +cobbledhalfblock,43,3 +cstonedoublehalfblock,43,3 +cstonedhalfblock,43,3 +csdoublehalfblock,43,3 +csdhalfblock,43,3 +doublecobblestonehalfblock,43,3 +dcobblestonehalfblock,43,3 +doublecobblehalfblock,43,3 +dcobblehalfblock,43,3 +doublecstonehalfblock,43,3 +dcstonehalfblock,43,3 +doublecshalfblock,43,3 +dcshalfblock,43,3 +brickdoublestep,43,4 +brickdstep,43,4 +bdoublestep,43,4 +bdstep,43,4 +brickdoubleslab,43,4 +brickdslab,43,4 +bdoubleslab,43,4 +bdslab,43,4 +doublebrickstep,43,4 +dbrickstep,43,4 +doublebstep,43,4 +dbstep,43,4 +doublebrickslab,43,4 +dbrickslab,43,4 +doublebslab,43,4 +dbslab,43,4 +brickdoublehalfblock,43,4 +brickdhalfblock,43,4 +bdoublehalfblock,43,4 +bdhalfblock,43,4 +doublebrickhalfblock,43,4 +dbrickhalfblock,43,4 +doublebhalfblock,43,4 +dbhalfblock,43,4 +stonebrickdoublestep,43,5 +stonebrickdstep,43,5 +stonebdoublestep,43,5 +stonebdstep,43,5 +sbrickdoublestep,43,5 +sbrickdstep,43,5 +sbdoublestep,43,5 +sbdstep,43,5 +stonebrickdoubleslab,43,5 +stonebrickdslab,43,5 +stonebdoubleslab,43,5 +stonebdslab,43,5 +sbrickdoubleslab,43,5 +sbrickdslab,43,5 +sbdoubleslab,43,5 +sbdslab,43,5 +doublestonebrickstep,43,5 +dstonebrickstep,43,5 +doublestonebstep,43,5 +dstonebstep,43,5 +doublesbrickstep,43,5 +dsbrickstep,43,5 +doublesbstep,43,5 +dsbstep,43,5 +doublestonebrickslab,43,5 +dstonebrickslab,43,5 +doublestonebslab,43,5 +dstonebslab,43,5 +doublesbrickslab,43,5 +dsbrickdslab,43,5 +doublesbslab,43,5 +dsbslab,43,5 +stonebrickdoublehalfblock,43,5 +stonebrickdhalfblock,43,5 +stonebdoublehalfblock,43,5 +stonebdhalfblock,43,5 +sbrickdoublehalfblock,43,5 +sbrickdhalfblock,43,5 +sbdoublehalfblock,43,5 +sbdhalfblock,43,5 +doublestonebrickhalfblock,43,5 +dstonebrickhalfblock,43,5 +doublestonebhalfblock,43,5 +dstonebhalfblock,43,5 +doublesbrickhalfblock,43,5 +dsbrickhalfblock,43,5 +doublesbhalfblock,43,5 +dsbhalfblock,43,5 +netherbrickdoubleslab,43,6 +hellbrickdoubleslab,43,6 +nbrickdoubleslab,43,6 +hbrickdoubleslab,43,6 +netherdoubleslab,43,6 +helldoubleslab,43,6 +nbdoubleslab,43,6 +hbdoubleslab,43,6 +hdoubleslab,43,6 +ndoubleslab,43,6 +netherbrickdoublestep,43,6 +hellbrickdoublestep,43,6 +nbrickdoublestep,43,6 +hbrickdoublestep,43,6 +netherdoublestep,43,6 +helldoublestep,43,6 +nbdoublestep,43,6 +hbdoublestep,43,6 +ndoublestep,43,6 +hdoublestep,43,6 +netherbrickdoublehalfblock,43,6 +hellbrickdoublehalfblock,43,6 +nbrickdoublehalfblock,43,6 +hbrickdoublehalfblock,43,6 +netherdoublehalfblock,43,6 +helldoublehalfblock,43,6 +nbdoublehalfblock,43,6 +hbdoublehalfblock,43,6 +ndoublehalfblock,43,6 +hdoublehalfblock,43,6 +netherbrickdslab,43,6 +hellbrickdslab,43,6 +nbrickdslab,43,6 +hbrickdslab,43,6 +netherdslab,43,6 +helldslab,43,6 +nbdslab,43,6 +hbdslab,43,6 +hdslab,43,6 +ndslab,43,6 +netherbrickdstep,43,6 +hellbrickdstep,43,6 +nbrickdstep,43,6 +hbrickdstep,43,6 +netherdstep,43,6 +helldstep,43,6 +nbdstep,43,6 +hbdstep,43,6 +ndstep,43,6 +hdstep,43,6 +netherbrickdhalfblock,43,6 +hellbrickdhalfblock,43,6 +nbrickdhalfblock,43,6 +hbrickdhalfblock,43,6 +netherdhalfblock,43,6 +helldhalfblock,43,6 +nbdhalfblock,43,6 +hbdhalfblock,43,6 +ndhalfblock,43,6 +hdhalfblock,43,6 +doublenetherbrickslab,43,6 +doublehellbrickslab,43,6 +doublenbrickslab,43,6 +doublehbrickslab,43,6 +doublenetherslab,43,6 +doublehellslab,43,6 +doublenbslab,43,6 +doublehbslab,43,6 +doublehslab,43,6 +doublenslab,43,6 +doublenetherbrickstep,43,6 +doublehellbrickstep,43,6 +doublenbrickstep,43,6 +doublehbrickstep,43,6 +doublenetherstep,43,6 +doublehellstep,43,6 +doublenbstep,43,6 +doublehbstep,43,6 +doublenstep,43,6 +doublehstep,43,6 +doublenetherbrickhalfblock,43,6 +doublehellbrickhalfblock,43,6 +doublenbrickhalfblock,43,6 +doublehbrickhalfblock,43,6 +doublenetherhalfblock,43,6 +doublehellhalfblock,43,6 +doublenbhalfblock,43,6 +doublehbhalfblock,43,6 +doublenhalfblock,43,6 +doublehhalfblock,43,6 +dnetherbrickslab,43,6 +dhellbrickslab,43,6 +dnbrickslab,43,6 +dhbrickslab,43,6 +dnetherslab,43,6 +dhellslab,43,6 +dnbslab,43,6 +dhbslab,43,6 +dhslab,43,6 +dnslab,43,6 +dnetherbrickstep,43,6 +dhellbrickstep,43,6 +dnbrickstep,43,6 +dhbrickstep,43,6 +dnetherstep,43,6 +dhellstep,43,6 +dnbstep,43,6 +dhbstep,43,6 +dnstep,43,6 +dhstep,43,6 +dnetherbrickhalfblock,43,6 +dhellbrickhalfblock,43,6 +dnbrickhalfblock,43,6 +dhbrickhalfblock,43,6 +dnetherhalfblock,43,6 +dhellhalfblock,43,6 +dnbhalfblock,43,6 +dhbhalfblock,43,6 +dnhalfblock,43,6 +dhhalfblock,43,6 +netherquartzdoublestep,43,7 +hellquartzdoublestep,43,7 +deathquartzdoublestep,43,7 +nquartzdoublestep,43,7 +hquartzdoublestep,43,7 +dquartzdoublestep,43,7 +quartzdoublestep,43,7 +nqdoublestep,43,7 +hqdoublestep,43,7 +dqdoublestep,43,7 +qdoublestep,43,7 +netherquartzdoubleslab,43,7 +hellquartzdoubleslab,43,7 +deathquartzdoubleslab,43,7 +nquartzdoubleslab,43,7 +hquartzdoubleslab,43,7 +dquartzdoubleslab,43,7 +quartzdoubleslab,43,7 +nqdoubleslab,43,7 +hqdoubleslab,43,7 +dqdoubleslab,43,7 +qdoubleslab,43,7 +netherquartzdoublehalfblock,43,7 +hellquartzdoublehalfblock,43,7 +deathquartzdoublehalfblock,43,7 +nquartzdoublehalfblock,43,7 +hquartzdoublehalfblock,43,7 +dquartzdoublehalfblock,43,7 +quartzdoublehalfblock,43,7 +nqdoublehalfblock,43,7 +hqdoublehalfblock,43,7 +dqdoublehalfblock,43,7 +qdoublehalfblock,43,7 +netherquartzdslab,43,7 +hellquartzdslab,43,7 +deathquartzdslab,43,7 +nquartzdslab,43,7 +hquartzdslab,43,7 +dquartzdslab,43,7 +quartzdslab,43,7 +nqdslab,43,7 +hqdslab,43,7 +dqdslab,43,7 +qdslab,43,7 +netherquartzdstep,43,7 +hellquartzdstep,43,7 +deathquartzdstep,43,7 +nquartzdstep,43,7 +hquartzdstep,43,7 +dquartzdstep,43,7 +quartzdstep,43,7 +nqdstep,43,7 +hqdstep,43,7 +dqdstep,43,7 +qdstep,43,7 +netherquartzdhalfblock,43,7 +hellquartzdhalfblock,43,7 +deathquartzdhalfblock,43,7 +nquartzdhalfblock,43,7 +hquartzdhalfblock,43,7 +dquartzdhalfblock,43,7 +quartzdhalfblock,43,7 +nqdhalfblock,43,7 +hqdhalfblock,43,7 +dqdhalfblock,43,7 +qdhalfblock,43,7 +doublenetherquartzslab,43,7 +doublehellquartzslab,43,7 +doubledeathquartzslab,43,7 +doublenquartzslab,43,7 +doublehquartzslab,43,7 +doubledquartzslab,43,7 +doublequartzslab,43,7 +doublenqslab,43,7 +doublehqslab,43,7 +doubledqslab,43,7 +doubleqslab,43,7 +doublenetherquartzstep,43,7 +doublehellquartzstep,43,7 +doubledeathquartzstep,43,7 +doublenquartzstep,43,7 +doublehquartzstep,43,7 +doubledquartzstep,43,7 +doublequartzstep,43,7 +doublenqstep,43,7 +doublehqstep,43,7 +doubledqstep,43,7 +doubleqstep,43,7 +doublenetherquartzhalfblock,43,7 +doublehellquartzhalfblock,43,7 +doubledeathquartzhalfblock,43,7 +doublenquartzhalfblock,43,7 +doublehquartzhalfblock,43,7 +doubledquartzhalfblock,43,7 +doublequartzhalfblock,43,7 +doublenqhalfblock,43,7 +doublehqhalfblock,43,7 +doubledqhalfblock,43,7 +doubleqhalfblock,43,7 +dnetherquartzslab,43,7 +dhellquartzslab,43,7 +ddeathquartzslab,43,7 +dnquartzslab,43,7 +dhquartzslab,43,7 +ddquartzslab,43,7 +dnqslab,43,7 +dhqslab,43,7 +ddqslab,43,7 +dnetherquartzstep,43,7 +dhellquartzstep,43,7 +ddeathquartzstep,43,7 +dnquartzstep,43,7 +dhquartzstep,43,7 +ddquartzstep,43,7 +dnqstep,43,7 +dhqstep,43,7 +ddqstep,43,7 +dnetherquartzhalfblock,43,7 +dhellquartzhalfblock,43,7 +ddeathquartzhalfblock,43,7 +dnquartzhalfblock,43,7 +dhquartzhalfblock,43,7 +ddquartzhalfblock,43,7 +dnqhalfblock,43,7 +dhqhalfblock,43,7 +ddqhalfblock,43,7 +smoothstonedoubleslab,43,8 +smoothstonedoublestep,43,8 +smoothstonedoublehalfblock,43,8 +smoothstonedslab,43,8 +smoothstonedstep,43,8 +smoothstonedhalfblock,43,8 +doublesmoothstoneslab,43,8 +doublesmoothstonestep,43,8 +doublesmoothstonehalfblock,43,8 +dsmoothstoneslab,43,8 +dsmoothstonestep,43,8 +dsmoothstonehalfblock,43,8 +smoothsandstonedoubleslab,43,9 +ssandstonedoubleslab,43,9 +ssstonedoubleslab,43,9 +sssdoubleslab,43,9 +smoothsandstonedoublestep,43,9 +ssandstonedoublestep,43,9 +ssstonedoublestep,43,9 +sssdoublestep,43,9 +smoothsandstonedoublehalfblock,43,9 +ssandstonedoublehalfblock,43,9 +ssstonedoublehalfblock,43,9 +sssdoublehalfblock,43,9 +smoothsandstonedslab,43,9 +ssandstonedslab,43,9 +ssstonedslab,43,9 +sssdslab,43,9 +smoothsandstonedstep,43,9 +ssandstonedstep,43,9 +ssstonedstep,43,9 +sssdstep,43,9 +smoothsandstonedhalfblock,43,9 +ssandstonedhalfblock,43,9 +ssstonedhalfblock,43,9 +sssdhalfblock,43,9 +doublesmoothsandstoneslab,43,9 +doublessandstoneslab,43,9 +doublessstoneslab,43,9 +doublesssslab,43,9 +doublesmoothsandstonestep,43,9 +doublessandstonestep,43,9 +doublessstonestep,43,9 +doublesssstep,43,9 +doublesmoothsandstonehalfblock,43,9 +doublessandstonehalfblock,43,9 +doublessstonehalfblock,43,9 +doublessshalfblock,43,9 +dsmoothsandstoneslab,43,9 +dssandstoneslab,43,9 +dssstoneslab,43,9 +dsssslab,43,9 +dsmoothsandstonestep,43,9 +dssandstonestep,43,9 +dssstonestep,43,9 +dsssstep,43,9 +dsmoothsandstonehalfblock,43,9 +dssandstonehalfblock,43,9 +dssstonehalfblock,43,9 +dssshalfblock,43,9 +smoothstonestep,44,0 +stonestep,44,0 +sstep,44,0 +step,44,0 +smoothstoneslab,44,0 +stoneslab,44,0 +sslab,44,0 +slab,44,0 +smoothstonehalfblock,44,0 +stonehalfblock,44,0 +shalfblock,44,0 +halfblock,44,0 +sandstonestep,44,1 +sstonestep,44,1 +ssstep,44,1 +sandstoneslab,44,1 +sstoneslab,44,1 +ssslab,44,1 +sandstonehalfblock,44,1 +sstonehalfblock,44,1 +sshalfblock,44,1 +woodenstonestep,44,2 +woodstonestep,44,2 +wstonestep,44,2 +woodenstoneslab,44,2 +woodstoneslab,44,2 +wstoneslab,44,2 +woodenstonehalfblock,44,2 +woodstonehalfblock,44,2 +wstonehalfblock,44,2 +cobblestonestep,44,3 +cobblestep,44,3 +cstonestep,44,3 +csstep,44,3 +cobblestoneslab,44,3 +cobbleslab,44,3 +cstoneslab,44,3 +csslab,44,3 +cobblestonehalfblock,44,3 +cobblehalfblock,44,3 +cstonehalfblock,44,3 +cshalfblock,44,3 +brickstep,44,4 +bstep,44,4 +brickslab,44,4 +bslab,44,4 +brickhalfblock,44,4 +bhalfblock,44,4 +stonebrickstep,44,5 +stonebstep,44,5 +sbrickstep,44,5 +sbstep,44,5 +stonebrickslab,44,5 +stonebslab,44,5 +sbrickslab,44,5 +sbslab,44,5 +stonebrickhalfblock,44,5 +stonebhalfblock,44,5 +sbrickhalfblock,44,5 +sbhalfblock,44,5 +netherbrickslab,44,6 +hellbrickslab,44,6 +nbrickslab,44,6 +hbrickslab,44,6 +netherslab,44,6 +hellslab,44,6 +nbslab,44,6 +hbslab,44,6 +hslab,44,6 +nslab,44,6 +netherbrickstep,44,6 +hellbrickstep,44,6 +nbrickstep,44,6 +hbrickstep,44,6 +netherstep,44,6 +hellstep,44,6 +nbstep,44,6 +hbstep,44,6 +nstep,44,6 +hstep,44,6 +netherbrickhalfblock,44,6 +hellbrickhalfblock,44,6 +nbrickhalfblock,44,6 +hbrickhalfblock,44,6 +netherhalfblock,44,6 +hellhalfblock,44,6 +nbhalfblock,44,6 +hbhalfblock,44,6 +nhalfblock,44,6 +hhalfblock,44,6 +netherquartzstep,44,7 +hellquartzstep,44,7 +deathquartzstep,44,7 +nquartzstep,44,7 +hquartzstep,44,7 +dquartzstep,44,7 +quartzstep,44,7 +nqstep,44,7 +hqstep,44,7 +dqstep,44,7 +qstep,44,7 +netherquartzslab,44,7 +hellquartzslab,44,7 +deathquartzslab,44,7 +nquartzslab,44,7 +hquartzslab,44,7 +dquartzslab,44,7 +quartzslab,44,7 +nqslab,44,7 +hqslab,44,7 +dqslab,44,7 +qslab,44,7 +netherquartzhalfblock,44,7 +hellquartzhalfblock,44,7 +deathquartzhalfblock,44,7 +nquartzhalfblock,44,7 +hquartzhalfblock,44,7 +dquartzhalfblock,44,7 +quartzhalfblock,44,7 +nqhalfblock,44,7 +hqhalfblock,44,7 +dqhalfblock,44,7 +qhalfblock,44,7 +brickblock,45,0 +blockbrick,45,0 +bblock,45,0 +blockb,45,0 +tnt,46,0 +tntblock,46,0 +blocktnt,46,0 +bombblock,46,0 +blockbomb,46,0 +dynamiteblock,46,0 +blockdynamite,46,0 +bomb,46,0 +dynamite,46,0 +bookcase,47,0 +casebook,47,0 +bookshelf,47,0 +shelfbook,47,0 +bookblock,47,0 +blockbook,47,0 +mossycobblestone,48,0 +mosscobblestone,48,0 +mcobblestone,48,0 +mossycobble,48,0 +mosscobble,48,0 +mcobble,48,0 +mossstone,48,0 +mossystone,48,0 +mstone,48,0 +obsidian,49,0 +obsi,49,0 +obby,49,0 +torch,50,0 +burningstick,50,0 +burnstick,50,0 +fire,51,0 +flame,51,0 +flames,51,0 +mobspawner,52,0 +mobcage,52,0 +monsterspawner,52,0 +monstercage,52,0 +mspawner,52,0 +mcage,52,0 +spawner,52,0 +cage,52,0 +woodenstairs,53,0 +woodstairs,53,0 +wstairs,53,0 +woodenstair,53,0 +woodstair,53,0 +wstair,53,0 +chest,54,0 +container,54,0 +diamondore,56,0 +crystalore,56,0 +orediamond,56,0 +orecrystal,56,0 +dore,56,0 +ored,56,0 +diamondblock,57,0 +blockdiamond,57,0 +crystalblock,57,0 +blockcrystal,57,0 +dblock,57,0 +blockd,57,0 +workbench,58,0 +craftingbench,58,0 +crafterbench,58,0 +craftbench,58,0 +worktable,58,0 +craftingtable,58,0 +craftertable,58,0 +crafttable,58,0 +wbench,58,0 +cbench,58,0 +soil,60,0 +furnace,61,0 +litfurnace,62,0 +lfurnace,62,0 +burningfurnace,62,0 +burnfurnace,62,0 +bfurnace,62,0 +ladder,65,0 +minecarttrack,66,0 +minecartrails,66,0 +minecartrail,66,0 +mcarttrack,66,0 +mcartrails,66,0 +mcartrail,66,0 +mctrack,66,0 +mcrails,66,0 +mcrail,66,0 +track,66,0 +rails,66,0 +rail,66,0 +cobblestonestairs,67,0 +cstonestairs,67,0 +stonestairs,67,0 +cobblestairs,67,0 +csstairs,67,0 +sstairs,67,0 +cstairs,67,0 +cobblestonestair,67,0 +cstonestair,67,0 +stonestair,67,0 +cobblestair,67,0 +csstair,67,0 +sstair,67,0 +cstair,67,0 +lever,69,0 +stonepressureplate,70,0 +stonepressplate,70,0 +stonepplate,70,0 +stoneplate,70,0 +spressureplate,70,0 +spressplate,70,0 +spplate,70,0 +splate,70,0 +smoothstonepressureplate,70,0 +smoothstonepressplate,70,0 +smoothstonepplate,70,0 +smoothstoneplate,70,0 +sstonepressureplate,70,0 +sstonepressplate,70,0 +sstonepplate,70,0 +sstoneplate,70,0 +woodenpressureplate,72,0 +woodenpressplate,72,0 +woodenpplate,72,0 +woodenplate,72,0 +woodpressureplate,72,0 +woodpressplate,72,0 +woodpplate,72,0 +woodplate,72,0 +wpressureplate,72,0 +wpressplate,72,0 +wpplate,72,0 +wplate,72,0 +redstoneore,73,0 +redsore,73,0 +redore,73,0 +rstoneore,73,0 +rsore,73,0 +rore,73,0 +oreredstone,73,0 +orereds,73,0 +orered,73,0 +orerstone,73,0 +orers,73,0 +orer,73,0 +redstonetorch,76,0 +rstonetorch,76,0 +redstorch,76,0 +redtorch,76,0 +rstorch,76,0 +stonebutton,77,0 +smoothstonebutton,77,0 +sstonebutton,77,0 +sbutton,77,0 +button,77,0 +snowcover,78,0 +snowcovering,78,0 +scover,78,0 +ice,79,0 +frozenwater,79,0 +waterfrozen,79,0 +freezewater,79,0 +waterfreeze,79,0 +snowblock,80,0 +blocksnow,80,0 +sblock,80,0 +blocks,80,0 +cactus,81,0 +cactuses,81,0 +cacti,81,0 +clayblock,82,0 +blockclay,82,0 +cblock,82,0 +blockc,82,0 +jukebox,84,0 +jbox,84,0 +woodenfence,85,0 +fence,85,0 +woodfence,85,0 +wfence,85,0 +fencewooden,85,0 +fencewood,85,0 +fencew,85,0 +pumpkin,86,0 +netherrack,87,0 +netherrock,87,0 +netherstone,87,0 +hellrack,87,0 +hellrock,87,0 +hellstone,87,0 +deathrack,87,0 +deathrock,87,0 +deathstone,87,0 +nrack,87,0 +nrock,87,0 +nstone,87,0 +hrack,87,0 +hrock,87,0 +hstone,87,0 +drack,87,0 +drock,87,0 +dstone,87,0 +soulsand,88,0 +slowsand,88,0 +slowmud,88,0 +ssand,88,0 +smud,88,0 +mud,88,0 +glowstone,89,0 +glowingstoneblock,89,0 +lightstoneblock,89,0 +glowstoneblock,89,0 +blockglowingstone,89,0 +blocklightstone,89,0 +blockglowstone,89,0 +glowingstone,89,0 +lightstone,89,0 +glowingblock,89,0 +lightblock,89,0 +glowblock,89,0 +lstone,89,0 +gstone,89,0 +portal,90,0 +jackolantern,91,0 +pumpkinlantern,91,0 +glowingpumpkin,91,0 +lightpumpkin,91,0 +jpumpkin,91,0 +plantren,91,0 +glowpumpkin,91,0 +gpumpkin,91,0 +lpumpkin,91,0 +lockedchest,95,0 +lockchest,95,0 +jokechest,95,0 +whiteglass,95,0 +whitesglass,95,0 +whitestainedglass,95,0 +wglass,95,0 +wsglass,95,0 +wstainedglass,95,0 +sglass,95,0 +stainedglass,95,0 +orangeglass,95,1 +orangesglass,95,1 +orangestainedglass,95,1 +oglass,95,1 +osglass,95,1 +ostainedglass,95,1 +magentaglass,95,2 +magentasglass,95,2 +magentastainedglass,95,2 +mglass,95,2 +msglass,95,2 +mstainedglass,95,2 +lightblueglass,95,3 +lightbluesglass,95,3 +lightbluestainedglass,95,3 +lblueglass,95,3 +lbluesglass,95,3 +lbluestainedglass,95,3 +lightbluglass,95,3 +lightblusglass,95,3 +lightblustainedglass,95,3 +lbluglass,95,3 +lblusglass,95,3 +lblustainedglass,95,3 +lbglass,95,3 +lbsglass,95,3 +lbstainedglass,95,3 +yellowglass,95,4 +yellowsglass,95,4 +yellowstainedglass,95,4 +yglass,95,4 +ysglass,95,4 +ystainedglass,95,4 +lightgreenglass,95,5 +lightgreensglass,95,5 +lightgreenstainedglass,95,5 +lgreenglass,95,5 +lgreensglass,95,5 +lgreenstainedglass,95,5 +lightgreglass,95,5 +lightgresglass,95,5 +lightgrestainedglass,95,5 +lgreglass,95,5 +lgresglass,95,5 +lgrestainedglass,95,5 +limeglass,95,5 +limesglass,95,5 +limestainedglass,95,5 +lglass,95,5 +lsglass,95,5 +lstainedglass,95,5 +pinkglass,95,6 +pinksglass,95,6 +pinkstainedglass,95,6 +piglass,95,6 +pisglass,95,6 +pistainedglass,95,6 +darkgrayglass,95,7 +darkgraysglass,95,7 +darkgraystainedglass,95,7 +dgrayglass,95,7 +dgraysglass,95,7 +dgraystainedglass,95,7 +darkgreyglass,95,7 +darkgreysglass,95,7 +darkgreystainedglass,95,7 +dgreyglass,95,7 +dgreysglass,95,7 +dgreystainedglass,95,7 +darkgraglass,95,7 +darkgrasglass,95,7 +darkgrastainedglass,95,7 +dgraglass,95,7 +dgrasglass,95,7 +dgrastainedglass,95,7 +grayglass,95,7 +graysglass,95,7 +graystainedglass,95,7 +greyglass,95,7 +greysglass,95,7 +greystainedglass,95,7 +graglass,95,7 +grasglass,95,7 +grastainedglass,95,7 +lightgrayglass,95,8 +lightgraysglass,95,8 +lightgraystainedglass,95,8 +lgrayglass,95,8 +lgraysglass,95,8 +lgraystainedglass,95,8 +lightgreyglass,95,8 +lightgreysglass,95,8 +lightgreystainedglass,95,8 +lgreyglass,95,8 +lgreysglass,95,8 +lgreystainedglass,95,8 +lightgraglass,95,8 +lightgrasglass,95,8 +lightgrastainedglass,95,8 +lgraglass,95,8 +lgrasglass,95,8 +lgrastainedglass,95,8 +silverglass,95,8 +silversglass,95,8 +silverstainedglass,95,8 +siglass,95,8 +siasglass,95,8 +siastainedglass,95,8 +cyanglass,95,9 +cyansglass,95,9 +cyanstainedglass,95,9 +cglass,95,9 +csglass,95,9 +cstainedglass,95,9 +purpleglass,95,10 +purplesglass,95,10 +purplestainedglass,95,10 +puglass,95,10 +pusglass,95,10 +pustainedglass,95,10 +blueglass,95,11 +bluesglass,95,11 +bluestainedglass,95,11 +bluglass,95,11 +blusglass,95,11 +blustainedglass,95,11 +brownglass,95,12 +brownsglass,95,12 +brownstainedglass,95,12 +broglass,95,12 +brosglass,95,12 +brostainedglass,95,12 +darkgreenglass,95,13 +darkgreensglass,95,13 +darkgreenstainedglass,95,13 +dgreenglass,95,13 +dgreensglass,95,13 +dgreenstainedglass,95,13 +greenglass,95,13 +greensglass,95,13 +greenstainedglass,95,13 +darkgreglass,95,13 +darkgresglass,95,13 +darkgrestainedglass,95,13 +dgreglass,95,13 +dgresglass,95,13 +dgrestainedglass,95,13 +greglass,95,13 +gresglass,95,13 +grestainedglass,95,13 +redglass,95,14 +redsglass,95,14 +redstainedglass,95,14 +rglass,95,14 +rsglass,95,14 +rstainedglass,95,14 +blackglass,95,15 +blacksglass,95,15 +blackstainedglass,95,15 +blaglass,95,15 +blasglass,95,15 +blastainedglass,95,15 +trapdoor,96,0 +doortrap,96,0 +hatch,96,0 +tdoor,96,0 +doort,96,0 +trapd,96,0 +dtrap,96,0 +silverfish,97,0 +silverfishsmoothstone,97,0 +silverfishsstone,97,0 +sfishsmoothstone,97,0 +sfishsstone,97,0 +fishsmoothstone,97,0 +fishsstone,97,0 +sfsmoothstone,97,0 +sfsstone,97,0 +trapsmoothstone,97,0 +trapsstone,97,0 +monsteregg,97,0 +monstereggsmoothstone,97,0 +monstereggsstone,97,0 +meggsmoothstone,97,0 +meggsstone,97,0 +mesmoothstone,97,0 +messtone,97,0 +silverfishcobblestone,97,1 +silverfishcstone,97,1 +sfishcobblestone,97,1 +sfishcstone,97,1 +fishcobblestone,97,1 +fishcstone,97,1 +sfcobblestone,97,1 +sfcstone,97,1 +trapcobblestone,97,1 +trapcstone,97,1 +monstereggcobblestone,97,1 +monstereggcstone,97,1 +meggcobblestone,97,1 +meggcstone,97,1 +mecobblestone,97,1 +mecstone,97,1 +silverfishstonebrick,97,2 +silverfishsbrick,97,2 +sfishstonebrick,97,2 +sfishsbrick,97,2 +fishstonebrick,97,2 +fishsbrick,97,2 +sfstonebrick,97,2 +sfsbrick,97,2 +trapstonebrick,97,2 +trapsbrick,97,2 +monstereggstonebrick,97,2 +monstereggsbrick,97,2 +meggstonebrick,97,2 +meggsbrick,97,2 +mestonebrick,97,2 +mesbrick,97,2 +silverfishmossystonebrick,97,3 +silverfishmossstonebrick,97,3 +silverfishmstonebrick,97,3 +silverfishmsbrick,97,3 +sfishmossystonebrick,97,3 +sfishmossstonebrick,97,3 +sfishmstonebrick,97,3 +sfishmsbrick,97,3 +fishmossystonebrick,97,3 +fishmossstonebrick,97,3 +fishmstonebrick,97,3 +fishmsbrick,97,3 +sfmossystonebrick,97,3 +sfmossstonebrick,97,3 +sfmstonebrick,97,3 +sfmsbrick,97,3 +trapmossystonebrick,97,3 +trapmossstonebrick,97,3 +trapmstonebrick,97,3 +trapmsbrick,97,3 +monstereggmossystonebrick,97,3 +monstereggmossstonebrick,97,3 +monstereggmstonebrick,97,3 +monstereggmsbrick,97,3 +meggmossystonebrick,97,3 +meggmossstonebrick,97,3 +meggmstonebrick,97,3 +meggmsbrick,97,3 +memossystonebrick,97,3 +memossstonebrick,97,3 +memstonebrick,97,3 +memsbrick,97,3 +silverfishcrackedstonebrick,97,4 +silverfishcrackstonebrick,97,4 +silverfishcrstonebrick,97,4 +silverfishcrsbrick,97,4 +sfishcrackedstonebrick,97,4 +sfishcrackstonebrick,97,4 +sfishcrstonebrick,97,4 +sfishcrsbrick,97,4 +fishcrackedstonebrick,97,4 +fishcrackstonebrick,97,4 +fishcrstonebrick,97,4 +fishcrsbrick,97,4 +sfcrackedstonebrick,97,4 +sfcrackstonebrick,97,4 +sfcrstonebrick,97,4 +sfcrsbrick,97,4 +trapcrackedstonebrick,97,4 +trapcrackstonebrick,97,4 +trapcrstonebrick,97,4 +trapcrsbrick,97,4 +monstereggcrackedstonebrick,97,4 +monstereggcrackstonebrick,97,4 +monstereggcrstonebrick,97,4 +monstereggcrsbrick,97,4 +meggcrackedstonebrick,97,4 +meggcrackstonebrick,97,4 +meggcrstonebrick,97,4 +meggcrsbrick,97,4 +mecrackedstonebrick,97,4 +mecrackstonebrick,97,4 +mecrstonebrick,97,4 +mecrsbrick,97,4 +silverfishcirclestonebrick,97,5 +silverfishcistonebrick,97,5 +silverfishcisbrick,97,5 +sfishcirclestonebrick,97,5 +sfishcistonebrick,97,5 +sfishcisbrick,97,5 +fishcirclestonebrick,97,5 +fishcistonebrick,97,5 +fishcisbrick,97,5 +sfcirclestonebrick,97,5 +sfcistonebrick,97,5 +sfcisbrick,97,5 +trapcirclestonebrick,97,5 +trapcistonebrick,97,5 +trapcisbrick,97,5 +monstereggcirclestonebrick,97,5 +monstereggcistonebrick,97,5 +monstereggcisbrick,97,5 +meggcirclestonebrick,97,5 +meggcistonebrick,97,5 +meggcisbrick,97,5 +mecirclestonebrick,97,5 +mecistonebrick,97,5 +mecisbrick,97,5 +stonebrick,98,0 +stonebricks,98,0 +stonebrickblock,98,0 +stonebb,98,0 +sbrick,98,0 +mossystonebrick,98,1 +mossystonebricks,98,1 +mossystonebrickblock,98,1 +mossystonebb,98,1 +mossstonebrick,98,1 +mossstonebricks,98,1 +mossstonebrickblock,98,1 +mossstonebb,98,1 +mstonebrick,98,1 +mstonebricks,98,1 +mstonebrickblock,98,1 +mstonebb,98,1 +mosssbrick,98,1 +mosssbricks,98,1 +mosssbrickblock,98,1 +mosssbb,98,1 +msbrick,98,1 +msbricks,98,1 +msbrickblock,98,1 +crackedstone,98,2 +crackedstonebrick,98,2 +crackedstonebricks,98,2 +crackedstonebrickblock,98,2 +crackedstonebb,98,2 +crackstonebrick,98,2 +crackstonebricks,98,2 +crackstonebrickblock,98,2 +crackstonebb,98,2 +crstonebrick,98,2 +crstonebricks,98,2 +crstonebrickblock,98,2 +crstonebb,98,2 +cracksbrick,98,2 +cracksbricks,98,2 +cracksbrickblock,98,2 +cracksbb,98,2 +crsbrick,98,2 +crsbricks,98,2 +crsbrickblock,98,2 +circlestone,98,3 +circlestonebrick,98,3 +circlestonebricks,98,3 +circlestonebrickblock,98,3 +circlestonebb,98,3 +cistonebrick,98,3 +cistonebricks,98,3 +cistonebrickblock,98,3 +cistonebb,98,3 +circlesbrick,98,3 +circlesbricks,98,3 +circlesbrickblock,98,3 +circlesbb,98,3 +cisbrick,98,3 +cisbricks,98,3 +cisbrickblock,98,3 +giantredmushroom,99,0 +hugeredmushroom,99,0 +bigredmushroom,99,0 +gredmushroom,99,0 +hredmushroom,99,0 +bredmushroom,99,0 +giantrmushroom,99,0 +hugermushroom,99,0 +bigrmushroom,99,0 +grmushroom,99,0 +hrmushroom,99,0 +brmushroom,99,0 +giantredmush,99,0 +hugeredmush,99,0 +bigredmush,99,0 +gredmush,99,0 +hredmush,99,0 +bredmush,99,0 +giantrmush,99,0 +hugermush,99,0 +bigrmush,99,0 +grmush,99,0 +hrmush,99,0 +brmush,99,0 +giantbrownmushroom,100,0 +hugebrownmushroom,100,0 +bigbrownmushroom,100,0 +gbrownmushroom,100,0 +hbrownmushroom,100,0 +bbrownmushroom,100,0 +giantbmushroom,100,0 +hugebmushroom,100,0 +bigbmushroom,100,0 +gbmushroom,100,0 +hbmushroom,100,0 +bbmushroom,100,0 +giantbrownmush,100,0 +hugebrownmush,100,0 +bigbrownmush,100,0 +gbrownmush,100,0 +hbrownmush,100,0 +bbrownmush,100,0 +giantbmush,100,0 +hugebmush,100,0 +bigbmush,100,0 +gbmush,100,0 +hbmush,100,0 +bbmush,100,0 +ironbars,101,0 +ironbarsb,101,0 +ironbarsblock,101,0 +ironfence,101,0 +metalbars,101,0 +metalbarsb,101,0 +metalbarsblock,101,0 +metalfence,101,0 +jailbars,101,0 +jailbarsb,101,0 +jailbarsblock,101,0 +jailfence,101,0 +mbars,101,0 +mbarsb,101,0 +mbarsblock,101,0 +mfence,101,0 +jbars,101,0 +jbarsb,101,0 +jbarsblock,101,0 +jfence,101,0 +ibars,101,0 +ibarsb,101,0 +ibarsblock,101,0 +ifence,101,0 +glasspane,102,0 +glassp,102,0 +paneglass,102,0 +pglass,102,0 +flatglass,102,0 +fglass,102,0 +skinnyglass,102,0 +glassflat,102,0 +glassf,102,0 +glassskinny,102,0 +glasss,102,0 +melon,103,0 +watermelon,103,0 +greenmelon,103,0 +melongreen,103,0 +melonblock,103,0 +watermelonblock,103,0 +greenmelonblock,103,0 +vines,106,0 +vine,106,0 +greenvines,106,0 +greenvine,106,0 +gardenvines,106,0 +gardenvine,106,0 +vinesgreen,106,0 +vinegreen,106,0 +vinesgarden,106,0 +vinegarden,106,0 +vinesg,106,0 +vineg,106,0 +gvines,106,0 +gvine,106,0 +woodgate,107,0 +woodenfencegate,107,0 +wfencegate,107,0 +woodfencegate,107,0 +woodengate,107,0 +wgate,107,0 +gate,107,0 +gardengate,107,0 +ggate,107,0 +fencegate,107,0 +fgate,107,0 +brickstairs,108,0 +redbrickstairs,108,0 +redbstairs,108,0 +rbrickstairs,108,0 +bstairs,108,0 +redstairs,108,0 +brickstair,108,0 +redbrickstair,108,0 +redbstair,108,0 +rbrickstair,108,0 +bstair,108,0 +redstair,108,0 +stonebrickstairs,109,0 +stonebstairs,109,0 +sbstairs,109,0 +cementbrickstairs,109,0 +cementstairs,109,0 +cementbstairs,109,0 +cbstairs,109,0 +greybrickstairs,109,0 +greybstairs,109,0 +greystairs,109,0 +mycelium,110,0 +purplegrass,110,0 +pinkgrass,110,0 +mycel,110,0 +swampgrass,110,0 +sgrass,110,0 +mushroomgrass,110,0 +mushgrass,110,0 +lilypad,111,0 +waterlily,111,0 +lily,111,0 +swamppad,111,0 +lpad,111,0 +wlily,111,0 +netherbrickblock,112,0 +hellbrickblock,112,0 +deathbrickblock,112,0 +nbrickblock,112,0 +hbrickblock,112,0 +dbrickblock,112,0 +netherbblock,112,0 +hellbblock,112,0 +deathbblock,112,0 +nbblock,112,0 +hbblock,112,0 +dbblock,112,0 +netherbrickfence,113,0 +hellbrickfence,113,0 +nbrickfence,113,0 +hbrickfence,113,0 +netherbfence,113,0 +hellbfence,113,0 +netherfence,113,0 +hellfence,113,0 +nbfence,113,0 +hbfence,113,0 +nfence,113,0 +hfence,113,0 +netherbrickstairs,114,0 +hellbrickstairs,114,0 +nbrickstairs,114,0 +hbrickstairs,114,0 +netherbstairs,114,0 +hellbstairs,114,0 +netherstairs,114,0 +hellstairs,114,0 +nbstairs,114,0 +hbstairs,114,0 +nstairs,114,0 +hstairs,114,0 +netherbrickstair,114,0 +hellbrickstair,114,0 +nbrickstair,114,0 +hbrickstair,114,0 +netherbstair,114,0 +hellbstair,114,0 +netherstair,114,0 +hellstair,114,0 +nbstair,114,0 +hbstair,114,0 +nstair,114,0 +hstair,114,0 +enchantmenttable,116,0 +enchantingtable,116,0 +enchanttable,116,0 +etable,116,0 +magicaltable,116,0 +magictable,116,0 +mtable,116,0 +enchantmentdesk,116,0 +enchantingdesk,116,0 +enchantdesk,116,0 +edesk,116,0 +magicaldesk,116,0 +magicdesk,116,0 +mdesk,116,0 +booktable,116,0 +bookdesk,116,0 +btable,116,0 +bdesk,116,0 +enderportal,119,0 +endergoo,119,0 +endgoo,119,0 +endportal,119,0 +egoo,119,0 +eportal,119,0 +enderportalframe,120,0 +endportalframe,120,0 +endgooframe,120,0 +endergooframe,120,0 +egooframe,120,0 +eportalframe,120,0 +enderframe,120,0 +endframe,120,0 +enderstone,121,0 +endstone,121,0 +endrock,121,0 +enderrock,121,0 +erock,121,0 +estone,121,0 +enderdragonegg,122,0 +endegg,122,0 +dragonegg,122,0 +degg,122,0 +bossegg,122,0 +begg,122,0 +redstonelamp,123,0 +redlamp,123,0 +rslamp,123,0 +woodendoublestep,125,0 +woodendstep,125,0 +wooddoublestep,125,0 +wooddstep,125,0 +wdoublestep,125,0 +wdstep,125,0 +doublewoodenstep,125,0 +dwoodenstep,125,0 +doublewoodstep,125,0 +dwoodstep,125,0 +doublewstep,125,0 +dwstep,125,0 +woodendoubleslab,125,0 +woodendslab,125,0 +wooddoubleslab,125,0 +wooddslab,125,0 +wdoubleslab,125,0 +wdslab,125,0 +doublewoodenslab,125,0 +dwoodenslab,125,0 +doublewoodslab,125,0 +dwoodslab,125,0 +doublewslab,125,0 +dwslab,125,0 +woodendoublehalfblock,125,0 +woodendhalfblock,125,0 +wooddoublehalfblock,125,0 +wooddhalfblock,125,0 +wdoublehalfblock,125,0 +wdhalfblock,125,0 +doublewoodenhalfblock,125,0 +dwoodenhalfblock,125,0 +doublewoodhalfblock,125,0 +dwoodhalfblock,125,0 +doublewhalfblock,125,0 +dwhalfblock,125,0 +oakwoodendoublehalfblock,125,0 +oakwoodendhalfblock,125,0 +oakwooddoublehalfblock,125,0 +oakwooddhalfblock,125,0 +oakwdoublehalfblock,125,0 +oakwdhalfblock,125,0 +oakdoublewoodenhalfblock,125,0 +oakdwoodenhalfblock,125,0 +oakdoublewoodhalfblock,125,0 +oakdwoodhalfblock,125,0 +oakdoublewhalfblock,125,0 +oakdwhalfblock,125,0 +oakdoublehalfblock,125,0 +oakdhalfblock,125,0 +odhalfblock,125,0 +oakwoodendoublestep,125,0 +oakwoodendstep,125,0 +oakwooddoublestep,125,0 +oakwooddstep,125,0 +oakwdoublestep,125,0 +oakwdstep,125,0 +oakdoublewoodenstep,125,0 +oakdwoodenstep,125,0 +oakdoublewoodstep,125,0 +oakdwoodstep,125,0 +oakdoublewstep,125,0 +oakdwstep,125,0 +oakdoublestep,125,0 +oakdstep,125,0 +odstep,125,0 +oakwoodendoubleslab,125,0 +oakwoodendslab,125,0 +oakwooddoubleslab,125,0 +oakwooddslab,125,0 +oakwdoubleslab,125,0 +oakwdslab,125,0 +oakdoublewoodenslab,125,0 +oakdwoodenslab,125,0 +oakdoublewoodslab,125,0 +oakdwoodslab,125,0 +oakdoublewslab,125,0 +oakdwslab,125,0 +oakdoubleslab,125,0 +oakdslab,125,0 +odslab,125,0 +sprucewoodendoublestep,125,1 +sprucewoodendstep,125,1 +sprucewooddoublestep,125,1 +sprucewooddstep,125,1 +sprucewdoublestep,125,1 +sprucewdstep,125,1 +sprucedoublewoodenstep,125,1 +sprucedwoodenstep,125,1 +sprucedoublewoodstep,125,1 +sprucedwoodstep,125,1 +sprucedoublewstep,125,1 +sprucedwstep,125,1 +sprucedoublestep,125,1 +sprucedstep,125,1 +sprucewoodendoubleslab,125,1 +sprucewoodendslab,125,1 +sprucewooddoubleslab,125,1 +sprucewooddslab,125,1 +sprucewdoubleslab,125,1 +sprucewdslab,125,1 +sprucedoublewoodenslab,125,1 +sprucedwoodenslab,125,1 +sprucedoublewoodslab,125,1 +sprucedwoodslab,125,1 +sprucedoublewslab,125,1 +sprucedwslab,125,1 +sprucedoubleslab,125,1 +sprucedslab,125,1 +sprucewoodendoublehalfblock,125,1 +sprucewoodendhalfblock,125,1 +sprucewooddoublehalfblock,125,1 +sprucewooddhalfblock,125,1 +sprucewdoublehalfblock,125,1 +sprucewdhalfblock,125,1 +sprucedoublewoodenhalfblock,125,1 +sprucedwoodenhalfblock,125,1 +sprucedoublewoodhalfblock,125,1 +sprucedwoodhalfblock,125,1 +sprucedoublewhalfblock,125,1 +sprucedwhalfblock,125,1 +sprucedoublehalfblock,125,1 +sprucedhalfblock,125,1 +darkwoodendoublestep,125,1 +darkwoodendstep,125,1 +darkwooddoublestep,125,1 +darkwooddstep,125,1 +darkwdoublestep,125,1 +darkwdstep,125,1 +darkdoublewoodenstep,125,1 +darkdwoodenstep,125,1 +darkdoublewoodstep,125,1 +darkdwoodstep,125,1 +darkdoublewstep,125,1 +darkdwstep,125,1 +darkdoublestep,125,1 +darkdstep,125,1 +ddstep,125,1 +darkwoodendoubleslab,125,1 +darkwoodendslab,125,1 +darkwooddoubleslab,125,1 +darkwooddslab,125,1 +darkwdoubleslab,125,1 +darkwdslab,125,1 +darkdoublewoodenslab,125,1 +darkdwoodenslab,125,1 +darkdoublewoodslab,125,1 +darkdwoodslab,125,1 +darkdoublewslab,125,1 +darkdwslab,125,1 +darkdoubleslab,125,1 +darkdslab,125,1 +ddslab,125,1 +darkwoodendoublehalfblock,125,1 +darkwoodendhalfblock,125,1 +darkwooddoublehalfblock,125,1 +darkwooddhalfblock,125,1 +darkwdoublehalfblock,125,1 +darkwdhalfblock,125,1 +darkdoublewoodenhalfblock,125,1 +darkdwoodenhalfblock,125,1 +darkdoublewoodhalfblock,125,1 +darkdwoodhalfblock,125,1 +darkdoublewhalfblock,125,1 +darkdwhalfblock,125,1 +darkdoublehalfblock,125,1 +darkdhalfblock,125,1 +ddhalfblock,125,1 +birchwoodendoublestep,125,2 +birchwoodendstep,125,2 +birchwooddoublestep,125,2 +birchwooddstep,125,2 +birchwdoublestep,125,2 +birchwdstep,125,2 +birchdoublewoodenstep,125,2 +birchdwoodenstep,125,2 +birchdoublewoodstep,125,2 +birchdwoodstep,125,2 +birchdoublewstep,125,2 +birchdwstep,125,2 +birchdoublestep,125,2 +birchdstep,125,2 +birchwoodendoubleslab,125,2 +birchwoodendslab,125,2 +birchwooddoubleslab,125,2 +birchwooddslab,125,2 +birchwdoubleslab,125,2 +birchwdslab,125,2 +birchdoublewoodenslab,125,2 +birchdwoodenslab,125,2 +birchdoublewoodslab,125,2 +birchdwoodslab,125,2 +birchdoublewslab,125,2 +birchdwslab,125,2 +birchdoubleslab,125,2 +birchdslab,125,2 +birchwoodendoublehalfblock,125,2 +birchwoodendhalfblock,125,2 +birchwooddoublehalfblock,125,2 +birchwooddhalfblock,125,2 +birchwdoublehalfblock,125,2 +birchwdhalfblock,125,2 +birchdoublewoodenhalfblock,125,2 +birchdwoodenhalfblock,125,2 +birchdoublewoodhalfblock,125,2 +birchdwoodhalfblock,125,2 +birchdoublewhalfblock,125,2 +birchdwhalfblock,125,2 +birchdoublehalfblock,125,2 +birchdhalfblock,125,2 +lightwoodendoublehalfblock,125,2 +lightwoodendhalfblock,125,2 +lightwooddoublehalfblock,125,2 +lightwooddhalfblock,125,2 +lightwdoublehalfblock,125,2 +lightwdhalfblock,125,2 +lightdoublewoodenhalfblock,125,2 +lightdwoodenhalfblock,125,2 +lightdoublewoodhalfblock,125,2 +lightdwoodhalfblock,125,2 +lightdoublewhalfblock,125,2 +lightdwhalfblock,125,2 +lightdoublehalfblock,125,2 +lightdhalfblock,125,2 +ldhalfblock,125,2 +lightwoodendoublestep,125,2 +lightwoodendstep,125,2 +lightwooddoublestep,125,2 +lightwooddstep,125,2 +lightwdoublestep,125,2 +lightwdstep,125,2 +lightdoublewoodenstep,125,2 +lightdwoodenstep,125,2 +lightdoublewoodstep,125,2 +lightdwoodstep,125,2 +lightdoublewstep,125,2 +lightdwstep,125,2 +lightdoublestep,125,2 +lightdstep,125,2 +ldstep,125,2 +lightwoodendoubleslab,125,2 +lightwoodendslab,125,2 +lightwooddoubleslab,125,2 +lightwooddslab,125,2 +lightwdoubleslab,125,2 +lightwdslab,125,2 +lightdoublewoodenslab,125,2 +lightdwoodenslab,125,2 +lightdoublewoodslab,125,2 +lightdwoodslab,125,2 +lightdoublewslab,125,2 +lightdwslab,125,2 +lightdoubleslab,125,2 +lightdslab,125,2 +ldslab,125,2 +junglewoodendoublestep,125,3 +junglewoodendstep,125,3 +junglewooddoublestep,125,3 +junglewooddstep,125,3 +junglewdoublestep,125,3 +junglewdstep,125,3 +jungledoublewoodenstep,125,3 +jungledwoodenstep,125,3 +jungledoublewoodstep,125,3 +jungledwoodstep,125,3 +jungledoublewstep,125,3 +jungledwstep,125,3 +jungledoublestep,125,3 +jungledstep,125,3 +jdstep,125,3 +junglewoodendoubleslab,125,3 +junglewoodendslab,125,3 +junglewooddoubleslab,125,3 +junglewooddslab,125,3 +junglewdoubleslab,125,3 +junglewdslab,125,3 +jungledoublewoodenslab,125,3 +jungledwoodenslab,125,3 +jungledoublewoodslab,125,3 +jungledwoodslab,125,3 +jungledoublewslab,125,3 +jungledwslab,125,3 +jungledoubleslab,125,3 +jungledslab,125,3 +jdslab,125,3 +junglewoodendoublehalfblock,125,3 +junglewoodendhalfblock,125,3 +junglewooddoublehalfblock,125,3 +junglewooddhalfblock,125,3 +junglewdoublehalfblock,125,3 +junglewdhalfblock,125,3 +jungledoublewoodenhalfblock,125,3 +jungledwoodenhalfblock,125,3 +jungledoublewoodhalfblock,125,3 +jungledwoodhalfblock,125,3 +jungledoublewhalfblock,125,3 +jungledwhalfblock,125,3 +jungledoublehalfblock,125,3 +jungledhalfblock,125,3 +jdhalfblock,125,3 +forestwoodendoublehalfblock,125,3 +forestwoodendhalfblock,125,3 +forestwooddoublehalfblock,125,3 +forestwooddhalfblock,125,3 +forestwdoublehalfblock,125,3 +forestwdhalfblock,125,3 +forestdoublewoodenhalfblock,125,3 +forestdwoodenhalfblock,125,3 +forestdoublewoodhalfblock,125,3 +forestdwoodhalfblock,125,3 +forestdoublewhalfblock,125,3 +forestdwhalfblock,125,3 +forestdoublehalfblock,125,3 +forestdhalfblock,125,3 +fdhalfblock,125,3 +forestwoodendoublestep,125,3 +forestwoodendstep,125,3 +forestwooddoublestep,125,3 +forestwooddstep,125,3 +forestwdoublestep,125,3 +forestwdstep,125,3 +forestdoublewoodenstep,125,3 +forestdwoodenstep,125,3 +forestdoublewoodstep,125,3 +forestdwoodstep,125,3 +forestdoublewstep,125,3 +forestdwstep,125,3 +forestdoublestep,125,3 +forestdstep,125,3 +fdstep,125,3 +forestwoodendoubleslab,125,3 +forestwoodendslab,125,3 +forestwooddoubleslab,125,3 +forestwooddslab,125,3 +forestwdoubleslab,125,3 +forestwdslab,125,3 +forestdoublewoodenslab,125,3 +forestdwoodenslab,125,3 +forestdoublewoodslab,125,3 +forestdwoodslab,125,3 +forestdoublewslab,125,3 +forestdwslab,125,3 +forestdoubleslab,125,3 +forestdslab,125,3 +fdslab,125,3 +acaciawoodendoublestep,125,4 +acaciawoodendstep,125,4 +acaciawooddoublestep,125,4 +acaciawooddstep,125,4 +acaciawdoublestep,125,4 +acaciawdstep,125,4 +acaciadoublewoodenstep,125,4 +acaciadwoodenstep,125,4 +acaciadoublewoodstep,125,4 +acaciadwoodstep,125,4 +acaciadoublewstep,125,4 +acaciadwstep,125,4 +acaciadoublestep,125,4 +acaciadstep,125,4 +adstep,125,4 +acaciawoodendoubleslab,125,4 +acaciawoodendslab,125,4 +acaciawooddoubleslab,125,4 +acaciawooddslab,125,4 +acaciawdoubleslab,125,4 +acaciawdslab,125,4 +acaciadoublewoodenslab,125,4 +acaciadwoodenslab,125,4 +acaciadoublewoodslab,125,4 +acaciadwoodslab,125,4 +acaciadoublewslab,125,4 +acaciadwslab,125,4 +acaciadoubleslab,125,4 +acaciadslab,125,4 +adslab,125,4 +acaciawoodendoublehalfblock,125,4 +acaciawoodendhalfblock,125,4 +acaciawooddoublehalfblock,125,4 +acaciawooddhalfblock,125,4 +acaciawdoublehalfblock,125,4 +acaciawdhalfblock,125,4 +acaciadoublewoodenhalfblock,125,4 +acaciadwoodenhalfblock,125,4 +acaciadoublewoodhalfblock,125,4 +acaciadwoodhalfblock,125,4 +acaciadoublewhalfblock,125,4 +acaciadwhalfblock,125,4 +acaciadoublehalfblock,125,4 +acaciadhalfblock,125,4 +adhalfblock,125,4 +darkoakwoodendoublehalfblock,125,5 +darkoakwoodendhalfblock,125,5 +darkoakwooddoublehalfblock,125,5 +darkoakwooddhalfblock,125,5 +darkoakwdoublehalfblock,125,5 +darkoakwdhalfblock,125,5 +darkoakdoublewoodenhalfblock,125,5 +darkoakdwoodenhalfblock,125,5 +darkoakdoublewoodhalfblock,125,5 +darkoakdwoodhalfblock,125,5 +darkoakdoublewhalfblock,125,5 +darkoakdwhalfblock,125,5 +darkoakdoublehalfblock,125,5 +darkoakdhalfblock,125,5 +dodhalfblock,125,5 +darkoakwoodendoublestep,125,5 +darkoakwoodendstep,125,5 +darkoakwooddoublestep,125,5 +darkoakwooddstep,125,5 +darkoakwdoublestep,125,5 +darkoakwdstep,125,5 +darkoakdoublewoodenstep,125,5 +darkoakdwoodenstep,125,5 +darkoakdoublewoodstep,125,5 +darkoakdwoodstep,125,5 +darkoakdoublewstep,125,5 +darkoakdwstep,125,5 +darkoakdoublestep,125,5 +darkoakdstep,125,5 +dodstep,125,5 +darkoakwoodendoubleslab,125,5 +darkoakwoodendslab,125,5 +darkoakwooddoubleslab,125,5 +darkoakwooddslab,125,5 +darkoakwdoubleslab,125,5 +darkoakwdslab,125,5 +darkoakdoublewoodenslab,125,5 +darkoakdwoodenslab,125,5 +darkoakdoublewoodslab,125,5 +darkoakdwoodslab,125,5 +darkoakdoublewslab,125,5 +darkoakdwslab,125,5 +darkoakdoubleslab,125,5 +darkoakdslab,125,5 +dodslab,125,5 +woodenstep,126,0 +woodstep,126,0 +wstep,126,0 +woodenslab,126,0 +woodslab,126,0 +wslab,126,0 +woodenhalfblock,126,0 +woodhalfblock,126,0 +whalfblock,126,0 +oakwoodenstep,126,0 +oakwoodstep,126,0 +oakwstep,126,0 +oakstep,126,0 +ostep,126,0 +oakwoodenslab,126,0 +oakwoodslab,126,0 +oakwslab,126,0 +oakslab,126,0 +oslab,126,0 +oakwoodenhalfblock,126,0 +oakwoodhalfblock,126,0 +oakwhalfblock,126,0 +oakhalfblock,126,0 +ohalfblock,126,0 +sprucewoodenstep,126,1 +sprucewoodstep,126,1 +sprucewstep,126,1 +sprucestep,126,1 +sprucewoodenslab,126,1 +sprucewoodslab,126,1 +sprucewslab,126,1 +spruceslab,126,1 +sprucewoodenhalfblock,126,1 +sprucewoodhalfblock,126,1 +sprucewhalfblock,126,1 +sprucehalfblock,126,1 +darkwoodenstep,126,1 +darkwoodstep,126,1 +darkwstep,126,1 +darkstep,126,1 +darkwoodenslab,126,1 +darkwoodslab,126,1 +darkwslab,126,1 +darkslab,126,1 +darkwoodenhalfblock,126,1 +darkwoodhalfblock,126,1 +darkwhalfblock,126,1 +darkhalfblock,126,1 +birchwoodenstep,126,2 +birchwoodstep,126,2 +birchwstep,126,2 +birchstep,126,2 +birchwoodenslab,126,2 +birchwoodslab,126,2 +birchwslab,126,2 +birchslab,126,2 +birchwoodenhalfblock,126,2 +birchwoodhalfblock,126,2 +birchwhalfblock,126,2 +birchhalfblock,126,2 +lightwoodenstep,126,2 +lightwoodstep,126,2 +lightwstep,126,2 +lightstep,126,2 +lstep,126,2 +lightwoodenslab,126,2 +lightwoodslab,126,2 +lightwslab,126,2 +lightslab,126,2 +lslab,126,2 +lightwoodenhalfblock,126,2 +lightwoodhalfblock,126,2 +lightwhalfblock,126,2 +lighthalfblock,126,2 +lhalfblock,126,2 +junglewoodenstep,126,3 +junglewoodstep,126,3 +junglewstep,126,3 +junglestep,126,3 +jstep,126,3 +junglewoodenslab,126,3 +junglewoodslab,126,3 +junglewslab,126,3 +jungleslab,126,3 +jslab,126,3 +junglewoodenhalfblock,126,3 +junglewoodhalfblock,126,3 +junglewhalfblock,126,3 +junglehalfblock,126,3 +jhalfblock,126,3 +forestwoodenstep,126,3 +forestwoodstep,126,3 +forestwstep,126,3 +foreststep,126,3 +fstep,126,3 +forestwoodenslab,126,3 +forestwoodslab,126,3 +forestwslab,126,3 +forestslab,126,3 +fslab,126,3 +forestwoodenhalfblock,126,3 +forestwoodhalfblock,126,3 +forestwhalfblock,126,3 +foresthalfblock,126,3 +fhalfblock,126,3 +acaciawoodenstep,126,4 +acaciawoodstep,126,4 +acaciawstep,126,4 +acaciastep,126,4 +astep,126,4 +acaciawoodenslab,126,4 +acaciawoodslab,126,4 +acaciawslab,126,4 +acaciaslab,126,4 +aslab,126,4 +acaciawoodenhalfblock,126,4 +acaciawoodhalfblock,126,4 +acaciawhalfblock,126,4 +acaciahalfblock,126,4 +ahalfblock,126,4 +darkoakwoodenstep,126,5 +darkoakwoodstep,126,5 +darkoakwstep,126,5 +darkoakstep,126,5 +dostep,126,5 +darkoakwoodenslab,126,5 +darkoakwoodslab,126,5 +darkoakwslab,126,5 +darkoakslab,126,5 +doslab,126,5 +darkoakwoodenhalfblock,126,5 +darkoakwoodhalfblock,126,5 +darkoakwhalfblock,126,5 +darkoakhalfblock,126,5 +dohalfblock,126,5 +cocoaplant,127,0 +cocoplant,127,0 +cplant,127,0 +cocoafruit,127,0 +cocofruit,127,0 +cfruit,127,0 +cocoapod,127,0 +cocopod,127,0 +cpod,127,0 +sandstonestairs,128,0 +sandstairs,128,0 +sandsstairs,128,0 +sstonestairs,128,0 +ssstairs,128,0 +sandstair,128,0 +sandstonestair,128,0 +sandsstair,128,0 +sstonestair,128,0 +ssstair,128,0 +emeraldore,129,0 +eore,129,0 +oreemerald,129,0 +oree,129,0 +enderchest,130,0 +endchest,130,0 +echest,130,0 +chestender,130,0 +chestend,130,0 +cheste,130,0 +endercontainer,130,0 +endcontainer,130,0 +econtainer,130,0 +tripwirehook,131,0 +tripwire,131,0 +trip,131,0 +tripwirelever,131,0 +triphook,131,0 +emeraldblock,133,0 +blockemerald,133,0 +eblock,133,0 +blocke,133,0 +sprucewoodenstairs,134,0 +sprucewoodstairs,134,0 +sprucewstairs,134,0 +sprucestairs,134,0 +darkwoodenstairs,134,0 +darkwoodstairs,134,0 +darkwstairs,134,0 +darkstairs,134,0 +dstairs,134,0 +sprucewoodenstair,134,0 +sprucewoodstair,134,0 +sprucewstair,134,0 +sprucestair,134,0 +darkwoodenstair,134,0 +darkwoodstair,134,0 +darkwstair,134,0 +darkstair,134,0 +dstair,134,0 +birchwoodenstairs,135,0 +birchwoodstairs,135,0 +birchwstairs,135,0 +birchstairs,135,0 +lightwoodenstairs,135,0 +lightwoodstairs,135,0 +lightwstairs,135,0 +lightstairs,135,0 +lstairs,135,0 +birchwoodenstair,135,0 +birchwoodstair,135,0 +birchwstair,135,0 +birchstair,135,0 +lightwoodenstair,135,0 +lightwoodstair,135,0 +lightwstair,135,0 +lightstair,135,0 +lstair,135,0 +junglewoodenstairs,136,0 +junglewoodstairs,136,0 +junglewstairs,136,0 +junglestairs,136,0 +jstairs,136,0 +forestwoodenstairs,136,0 +forestwoodstairs,136,0 +forestwstairs,136,0 +foreststairs,136,0 +fstairs,136,0 +junglewoodenstair,136,0 +junglewoodstair,136,0 +junglewstair,136,0 +junglestair,136,0 +jstair,136,0 +forestwoodenstair,136,0 +forestwoodstair,136,0 +forestwstair,136,0 +foreststair,136,0 +fstair,136,0 +commandblock,137,0 +blockcommand,137,0 +cmdblock,137,0 +blockcmd,137,0 +macroblock,137,0 +blockmacro,137,0 +beacon,138,0 +beaconblock,138,0 +cobblestonewall,139,0 +cstonewall,139,0 +cobblewall,139,0 +cobblestonefence,139,0 +cstonefence,139,0 +cobblefence,139,0 +cswall,139,0 +csfence,139,0 +cwall,139,0 +cfence,139,0 +mosscobblestonewall,139,1 +mosscstonewall,139,1 +mosscobblewall,139,1 +mcobblestonewall,139,1 +mcstonewall,139,1 +mcobblewall,139,1 +mosscobblestonefence,139,1 +mosscstonefence,139,1 +mosscobblefence,139,1 +mcobblestonefence,139,1 +mcstonefence,139,1 +mcobblefence,139,1 +mcswall,139,0 +mcsfence,139,0 +mcwall,139,0 +mcfence,139,0 +plantedcarrot,141,0 +plantcarrot,141,0 +carrots,141,0 +growingcarrot,141,0 +potatoplant,142,0 +potatoes,142,0 +plantedpotato,142,0 +plantpotato,142,0 +growingpotato,142,0 +woodenbutton,143,0 +woodenplankbutton,143,0 +woodplankbutton,143,0 +wplankbutton,143,0 +plankbutton,143,0 +woodbutton,143,0 +wbutton,143,0 +anvil,145,0 +slightlydamagedanvil,145,1 +slightdamageanvil,145,1 +damagedanvil,145,1 +verydamagedanvil,145,2 +trapchest,146,0 +trappedchest,146,0 +chesttrapped,146,0 +chesttrap,146,0 +goldpressureplate,147,0 +weightedgoldpressureplate,147,0 +weightgoldpressureplate,147,0 +wgoldpressureplate,147,0 +weightedgoldpressplate,147,0 +weightgoldpressplate,147,0 +wgoldpressplate,147,0 +goldpressplate,147,0 +weightedgoldpplate,147,0 +weightgoldpplate,147,0 +wgoldpplate,147,0 +goldpplate,147,0 +weightedgoldplate,147,0 +weightgoldplate,147,0 +wgoldplate,147,0 +goldplate,147,0 +weightedgpressureplate,147,0 +weightgpressureplate,147,0 +wgpressureplate,147,0 +gpressureplate,147,0 +weightedgpressplate,147,0 +weightgpressplate,147,0 +wgpressplate,147,0 +gpressplate,147,0 +weightedgpplate,147,0 +weightgpplate,147,0 +wgpplate,147,0 +gpplate,147,0 +weightedgplate,147,0 +weightgplate,147,0 +wgplate,147,0 +gplate,147,0 +ironpressureplate,148,0 +weightedironpressureplate,148,0 +weightironpressureplate,148,0 +wironpressureplate,148,0 +weightedironpressplate,148,0 +weightironpressplate,148,0 +wironpressplate,148,0 +ironpressplate,148,0 +weightedironpplate,148,0 +weightironpplate,148,0 +wironpplate,148,0 +ironpplate,148,0 +weightedironplate,148,0 +weightironplate,148,0 +wironplate,148,0 +ironplate,148,0 +weightedipressureplate,148,0 +weightipressureplate,148,0 +wipressureplate,148,0 +ipressureplate,148,0 +weightedipressplate,148,0 +weightipressplate,148,0 +wipressplate,148,0 +ipressplate,148,0 +weightedipplate,148,0 +weightipplate,148,0 +wipplate,148,0 +ipplate,148,0 +weightediplate,148,0 +weightiplate,148,0 +wiplate,148,0 +iplate,148,0 +daylightsensor,151,0 +daylightsense,151,0 +lightsensor,151,0 +lightsense,151,0 +daysensor,151,0 +daysense,151,0 +timesensor,151,0 +timesense,151,0 +redstoneblock,152,0 +rstoneblock,152,0 +redsblock,152,0 +rsblock,152,0 +blockredstone,152,0 +blockrstone,152,0 +blockreds,152,0 +blockrs,152,0 +netherquartzore,153,0 +hellquartzore,153,0 +deathquartzore,153,0 +nquartzore,153,0 +hquartzore,153,0 +dquartzore,153,0 +quartzore,153,0 +netherqore,153,0 +hellqore,153,0 +deathqore,153,0 +nqore,153,0 +hqore,153,0 +dqore,153,0 +qore,153,0 +hopper,154,0 +chestpuller,154,0 +chestpull,154,0 +cheststorer,154,0 +cheststore,154,0 +itempuller,154,0 +itempull,154,0 +itemstorer,154,0 +itemstore,154,0 +quartzblock,155,0 +netherquartzblock,155,0 +nqblock,155,0 +qblock,155,0 +chiseledquartzblock,155,1 +chiselquartzblock,155,1 +cquartzblock,155,1 +cqblock,155,1 +pillarquartzblock,155,2 +pquartzblock,155,2 +pqblock,155,2 +quartzstairs,156,0 +qstairs,156,0 +quartzstair,156,0 +qstair,156,0 +activatorrails,157,0 +activaterails,157,0 +triggerrails,157,0 +arails,157,0 +trails,157,0 +activatorrail,157,0 +activaterail,157,0 +triggerrail,157,0 +arail,157,0 +trail,157,0 +activatortrack,157,0 +activatetrack,157,0 +triggertrack,157,0 +atrack,157,0 +ttrack,157,0 +dropper,158,0 +drop,158,0 +chestdispenser,158,0 +chestdispense,158,0 +chestdropper,158,0 +chestdrop,158,0 +whiteclay,159,0 +whitesclay,159,0 +whitestainedclay,159,0 +wclay,159,0 +wsclay,159,0 +wstainedclay,159,0 +sclay,159,0 +stainedclay,159,0 +orangeclay,159,1 +orangesclay,159,1 +orangestainedclay,159,1 +oclay,159,1 +osclay,159,1 +ostainedclay,159,1 +magentaclay,159,2 +magentasclay,159,2 +magentastainedclay,159,2 +mclay,159,2 +msclay,159,2 +mstainedclay,159,2 +lightblueclay,159,3 +lightbluesclay,159,3 +lightbluestainedclay,159,3 +lblueclay,159,3 +lbluesclay,159,3 +lbluestainedclay,159,3 +lightbluclay,159,3 +lightblusclay,159,3 +lightblustainedclay,159,3 +lbluclay,159,3 +lblusclay,159,3 +lblustainedclay,159,3 +lbclay,159,3 +lbsclay,159,3 +lbstainedclay,159,3 +yellowclay,159,4 +yellowsclay,159,4 +yellowstainedclay,159,4 +yclay,159,4 +ysclay,159,4 +ystainedclay,159,4 +lightgreenclay,159,5 +lightgreensclay,159,5 +lightgreenstainedclay,159,5 +lgreenclay,159,5 +lgreensclay,159,5 +lgreenstainedclay,159,5 +lightgreclay,159,5 +lightgresclay,159,5 +lightgrestainedclay,159,5 +lgreclay,159,5 +lgresclay,159,5 +lgrestainedclay,159,5 +limeclay,159,5 +limesclay,159,5 +limestainedclay,159,5 +lclay,159,5 +lsclay,159,5 +lstainedclay,159,5 +pinkclay,159,6 +pinksclay,159,6 +pinkstainedclay,159,6 +piclay,159,6 +pisclay,159,6 +pistainedclay,159,6 +darkgrayclay,159,7 +darkgraysclay,159,7 +darkgraystainedclay,159,7 +dgrayclay,159,7 +dgraysclay,159,7 +dgraystainedclay,159,7 +darkgreyclay,159,7 +darkgreeysclay,159,7 +darkgreystainedclay,159,7 +dgreyclay,159,7 +dgreysclay,159,7 +dgreystainedclay,159,7 +darkgraclay,159,7 +darkgrasclay,159,7 +darkgrastainedclay,159,7 +dgraclay,159,7 +dgrasclay,159,7 +dgrastainedclay,159,7 +grayclay,159,7 +graysclay,159,7 +graystainedclay,159,7 +greyclay,159,7 +greysclay,159,7 +greystainedclay,159,7 +graclay,159,7 +grasclay,159,7 +grastainedclay,159,7 +lightgrayclay,159,8 +lightgraysclay,159,8 +lightgraystainedclay,159,8 +lgrayclay,159,8 +lgraysclay,159,8 +lgraystainedclay,159,8 +lightgreyclay,159,8 +lightgreysclay,159,8 +lightgreystainedclay,159,8 +lgreyclay,159,8 +lgreysclay,159,8 +lgreystainedclay,159,8 +lightgraclay,159,8 +lightgrasclay,159,8 +lightgrastainedclay,159,8 +lgraclay,159,8 +lgrasclay,159,8 +lgrastainedclay,159,8 +silverclay,159,8 +silversclay,159,8 +silverstainedclay,159,8 +siclay,159,8 +siasclay,159,8 +siastainedclay,159,8 +cyanclay,159,9 +cyansclay,159,9 +cyanstainedclay,159,9 +cclay,159,9 +csclay,159,9 +cstainedclay,159,9 +purpleclay,159,10 +purplesclay,159,10 +purplestainedclay,159,10 +puclay,159,10 +pusclay,159,10 +pustainedclay,159,10 +blueclay,159,11 +bluesclay,159,11 +bluestainedclay,159,11 +bluclay,159,11 +blusclay,159,11 +blustainedclay,159,11 +brownclay,159,12 +brownsclay,159,12 +brownstainedclay,159,12 +broclay,159,12 +brosclay,159,12 +brostainedclay,159,12 +darkgreenclay,159,13 +darkgreensclay,159,13 +darkgreenstainedclay,159,13 +dgreenclay,159,13 +dgreensclay,159,13 +dgreenstainedclay,159,13 +greenclay,159,13 +greensclay,159,13 +greenstainedclay,159,13 +darkgreclay,159,13 +darkgresclay,159,13 +darkgrestainedclay,159,13 +dgreclay,159,13 +dgresclay,159,13 +dgrestainedclay,159,13 +greclay,159,13 +gresclay,159,13 +grestainedclay,159,13 +redclay,159,14 +redsclay,159,14 +redstainedclay,159,14 +rclay,159,14 +rsclay,159,14 +rstainedclay,159,14 +blackclay,159,15 +blacksclay,159,15 +blackstainedclay,159,15 +blaclay,159,15 +blasclay,159,15 +blastainedclay,159,15 +whiteglasspane,160,0 +whitesglasspane,160,0 +whitestainedglasspane,160,0 +wglasspane,160,0 +wsglasspane,160,0 +wstainedglasspane,160,0 +sglasspane,160,0 +stainedglasspane,160,0 +orangeglasspane,160,1 +orangesglasspane,160,1 +orangestainedglasspane,160,1 +oglasspane,160,1 +osglasspane,160,1 +ostainedglasspane,160,1 +magentaglasspane,160,2 +magentasglasspane,160,2 +magentastainedglasspane,160,2 +mglasspane,160,2 +msglasspane,160,2 +mstainedglasspane,160,2 +lightblueglasspane,160,3 +lightbluesglasspane,160,3 +lightbluestainedglasspane,160,3 +lblueglasspane,160,3 +lbluesglasspane,160,3 +lbluestainedglasspane,160,3 +lightbluglasspane,160,3 +lightblusglasspane,160,3 +lightblustainedglasspane,160,3 +lbluglasspane,160,3 +lblusglasspane,160,3 +lblustainedglasspane,160,3 +lbglasspane,160,3 +lbsglasspane,160,3 +lbstainedglasspane,160,3 +yellowglasspane,160,4 +yellowsglasspane,160,4 +yellowstainedglasspane,160,4 +yglasspane,160,4 +ysglasspane,160,4 +ystainedglasspane,160,4 +lightgreenglasspane,160,5 +lightgreensglasspane,160,5 +lightgreenstainedglasspane,160,5 +lgreenglasspane,160,5 +lgreensglasspane,160,5 +lgreenstainedglasspane,160,5 +lightgreglasspane,160,5 +lightgresglasspane,160,5 +lightgrestainedglasspane,160,5 +lgreglasspane,160,5 +lgresglasspane,160,5 +lgrestainedglasspane,160,5 +limeglasspane,160,5 +limesglasspane,160,5 +limestainedglasspane,160,5 +lglasspane,160,5 +lsglasspane,160,5 +lstainedglasspane,160,5 +pinkglasspane,160,6 +pinksglasspane,160,6 +pinkstainedglasspane,160,6 +piglasspane,160,6 +pisglasspane,160,6 +pistainedglasspane,160,6 +darkgrayglasspane,160,7 +darkgraysglasspane,160,7 +darkgraystainedglasspane,160,7 +dgrayglasspane,160,7 +dgraysglasspane,160,7 +dgraystainedglasspane,160,7 +darkgreyglasspane,160,7 +darkgreysglasspane,160,7 +darkgreystainedglasspane,160,7 +dgreyglasspane,160,7 +dgreysglasspane,160,7 +dgreystainedglasspane,160,7 +darkgraglasspane,160,7 +darkgrasglasspane,160,7 +darkgrastainedglasspane,160,7 +dgraglasspane,160,7 +dgrasglasspane,160,7 +dgrastainedglasspane,160,7 +grayglasspane,160,7 +graysglasspane,160,7 +graystainedglasspane,160,7 +greyglasspane,160,7 +greysglasspane,160,7 +greystainedglasspane,160,7 +graglasspane,160,7 +grasglasspane,160,7 +grastainedglasspane,160,7 +lightgrayglasspane,160,8 +lightgraysglasspane,160,8 +lightgraystainedglasspane,160,8 +lgrayglasspane,160,8 +lgraysglasspane,160,8 +lgraystainedglasspane,160,8 +lightgreyglasspane,160,8 +lightgreysglasspane,160,8 +lightgreystainedglasspane,160,8 +lgreyglasspane,160,8 +lgreysglasspane,160,8 +lgreystainedglasspane,160,8 +lightgraglasspane,160,8 +lightgrasglasspane,160,8 +lightgrastainedglasspane,160,8 +lgraglasspane,160,8 +lgrasglasspane,160,8 +lgrastainedglasspane,160,8 +silverglasspane,160,8 +silversglasspane,160,8 +silverstainedglasspane,160,8 +siglasspane,160,8 +siasglasspane,160,8 +siastainedglasspane,160,8 +cyanglasspane,160,9 +cyansglasspane,160,9 +cyanstainedglasspane,160,9 +cglasspane,160,9 +csglasspane,160,9 +cstainedglasspane,160,9 +purpleglasspane,160,10 +purplesglasspane,160,10 +purplestainedglasspane,160,10 +puglasspane,160,10 +pusglasspane,160,10 +pustainedglasspane,160,10 +blueglasspane,160,11 +bluesglasspane,160,11 +bluestainedglasspane,160,11 +bluglasspane,160,11 +blusglasspane,160,11 +blustainedglasspane,160,11 +brownglasspane,160,12 +brownsglasspane,160,12 +brownstainedglasspane,160,12 +broglasspane,160,12 +brosglasspane,160,12 +brostainedglasspane,160,12 +darkgreenglasspane,160,13 +darkgreensglasspane,160,13 +darkgreenstainedglasspane,160,13 +dgreenglasspane,160,13 +dgreensglasspane,160,13 +dgreenstainedglasspane,160,13 +greenglasspane,160,13 +greensglasspane,160,13 +greenstainedglasspane,160,13 +darkgreglasspane,160,13 +darkgresglasspane,160,13 +darkgrestainedglasspane,160,13 +dgreglasspane,160,13 +dgresglasspane,160,13 +dgrestainedglasspane,160,13 +greglasspane,160,13 +gresglasspane,160,13 +grestainedglasspane,160,13 +redglasspane,160,14 +redsglasspane,160,14 +redstainedglasspane,160,14 +rglasspane,160,14 +rsglasspane,160,14 +rstainedglasspane,160,14 +blackglasspane,160,15 +blacksglasspane,160,15 +blackstainedglasspane,160,15 +blaglasspane,160,15 +blasglasspane,160,15 +blastainedglasspane,160,15 +acacialeaves,161,0 +acaciatreeleaves,161,0 +acacialogleaves,161,0 +acaciatrunkleaves,161,0 +acaciawoodleaves,161,0 +aleaves,161,0 +atreeleaves,161,0 +alogleaves,161,0 +atrunkleaves,161,0 +awoodleaves,161,0 +acacialeave,161,0 +acaciatreeleave,161,0 +acacialogleave,161,0 +acaciatrunkleave,161,0 +acaciawoodleave,161,0 +aleave,161,0 +atreeleave,161,0 +alogleave,161,0 +atrunkleave,161,0 +awoodleave,161,0 +acaciatreeleaf,161,0 +acacialogleaf,161,0 +acaciatrunkleaf,161,0 +acaciawoodleaf,161,0 +aleaf,161,0 +atreeleaf,161,0 +alogleaf,161,0 +atrunkleaf,161,0 +awoodleaf,161,0 +darkoakleaves,161,1 +darkoaktreeleaves,161,1 +darkoaklogleaves,161,1 +darkoaktrunkleaves,161,1 +darkoakwoodleaves,161,1 +doakleaves,161,1 +doaktreeleaves,161,1 +doaklogleaves,161,1 +doaktrunkleaves,161,1 +doakwoodleaves,161,1 +doleaves,161,1 +dotreeleaves,161,1 +dologleaves,161,1 +dotrunkleaves,161,1 +dowoodleaves,161,1 +darkoakleave,161,1 +darkoaktreeleave,161,1 +darkoaklogleave,161,1 +darkoaktrunkleave,161,1 +darkoakwoodleave,161,1 +doakleave,161,1 +doaktreeleave,161,1 +doaklogleave,161,1 +doaktrunkleave,161,1 +doakwoodleave,161,1 +doleave,161,1 +dotreeleave,161,1 +dologleave,161,1 +dotrunkleave,161,1 +dowoodleave,161,1 +darkoaktreeleaf,161,1 +darkoaklogleaf,161,1 +darkoaktrunkleaf,161,1 +darkoakwoodleaf,161,1 +doakleaf,161,1 +doaktreeleaf,161,1 +doaklogleaf,161,1 +doaktrunkleaf,161,1 +doakwoodleaf,161,1 +doleaf,161,1 +dotreeleaf,161,1 +dologleaf,161,1 +dotrunkleaf,161,1 +dowoodleaf,161,1 +acacia,162,0 +acaciatree,162,0 +acacialog,162,0 +acaciatrunk,162,0 +acaciawood,162,0 +atree,162,0 +alog,162,0 +atrunk,162,0 +awood,162,0 +darkoak,162,1 +darkoaktree,162,1 +darkoaklog,162,1 +darkoaktrunk,162,1 +darkoakwood,162,1 +doak,162,1 +doaktree,162,1 +doaklog,162,1 +doaktrunk,162,1 +doakwood,162,1 +dotree,162,1 +dolog,162,1 +dotrunk,162,1 +dowood,162,1 +acaciawoodenstairs,163,0 +acaciawoodstairs,163,0 +acaciawstairs,163,0 +acaciastairs,163,0 +awoodenstairs,163,0 +awoodstairs,163,0 +awstairs,163,0 +astairs,163,0 +acaciawoodenstair,163,0 +acaciawoodstair,163,0 +acaciawstair,163,0 +acaciastair,163,0 +awoodenstair,163,0 +awoodstair,163,0 +awstair,163,0 +astair,163,0 +darkoakwoodenstairs,164,0 +darkoakwoodstairs,164,0 +darkoakwstairs,164,0 +darkoakstairs,164,0 +doakwoodenstairs,164,0 +doakwoodstairs,164,0 +doakwstairs,164,0 +doakstairs,164,0 +dowoodenstairs,164,0 +dowoodstairs,164,0 +dowstairs,164,0 +dostairs,164,0 +darkoakwoodenstair,164,0 +darkoakwoodstair,164,0 +darkoakwstair,164,0 +darkoakstair,164,0 +doakwoodenstair,164,0 +doakwoodstair,164,0 +doakwstair,164,0 +doakstair,164,0 +dowoodenstair,164,0 +dowoodstair,164,0 +dowstair,164,0 +dostair,164,0 +hay,170,0 +hayblock,170,0 +haybale,170,0 +baleofhay,170,0 +hayofbale,170,0 +whitecarpet,171,0 +whitefloor,171,0 +wcarpet,171,0 +wfloor,171,0 +carpet,171,0 +floor,171,0 +orangecarpet,171,1 +orangefloor,171,1 +ocarpet,171,1 +ofloor,171,1 +magentacarpet,171,2 +magentafloor,171,2 +mcarpet,171,2 +mfloor,171,2 +lightbluecarpet,171,3 +lightbluefloor,171,3 +lbluecarpet,171,3 +lbluefloor,171,3 +lbcarpet,171,3 +lbfloor,171,3 +lightblucarpet,171,3 +lightblufloor,171,3 +lblucarpet,171,3 +lblufloor,171,3 +yellowcarpet,171,4 +yellowfloor,171,4 +ycarpet,171,4 +yfloor,171,4 +lightgreencarpet,171,5 +lightgreenfloor,171,5 +lgreencarpet,171,5 +lgreenfloor,171,5 +lightgrecarpet,171,5 +lightgrefloor,171,5 +lgrecarpet,171,5 +lgrefloor,171,5 +limecarpet,171,5 +limefloor,171,5 +lcarpet,171,5 +lfloor,171,5 +pinkcarpet,171,6 +pinkfloor,171,6 +picarpet,171,6 +pifloor,171,6 +darkgraycarpet,171,7 +darkgrayfloor,171,7 +dgraycarpet,171,7 +dgrayfloor,171,7 +darkgreycarpet,171,7 +darkgreyfloor,171,7 +dgreycarpet,171,7 +dgreyfloor,171,7 +darkgracarpet,171,7 +darkgrafloor,171,7 +dgracarpet,171,7 +dgrafloor,171,7 +graycarpet,171,7 +grayfloor,171,7 +greycarpet,171,7 +greyfloor,171,7 +gracarpet,171,7 +grafloor,171,7 +lightgraycarpet,171,8 +lightgrayfloor,171,8 +lgraycarpet,171,8 +lgrayfloor,171,8 +lightgreycarpet,171,8 +lightgreyfloor,171,8 +lgreycarpet,171,8 +lgreyfloor,171,8 +lightgracarpet,171,8 +lightgrafloor,171,8 +lgracarpet,171,8 +lgrafloor,171,8 +silvercarpet,171,8 +silverfloor,171,8 +sicarpet,171,8 +siafloor,171,8 +cyancarpet,171,9 +cyanfloor,171,9 +ccarpet,171,9 +cfloor,171,9 +purplecarpet,171,10 +purplefloor,171,10 +pucarpet,171,10 +pufloor,171,10 +bluecarpet,171,11 +bluefloor,171,11 +blucarpet,171,11 +blufloor,171,11 +browncarpet,171,12 +brownfloor,171,12 +brocarpet,171,12 +brofloor,171,12 +darkgreencarpet,171,13 +darkgreenfloor,171,13 +dgreencarpet,171,13 +dgreenfloor,171,13 +greencarpet,171,13 +greenfloor,171,13 +darkgrecarpet,171,13 +darkgrefloor,171,13 +dgrecarpet,171,13 +dgrefloor,171,13 +grecarpet,171,13 +grefloor,171,13 +redcarpet,171,14 +redfloor,171,14 +rcarpet,171,14 +rfloor,171,14 +blackcarpet,171,15 +blackfloor,171,15 +blacarpet,171,15 +blafloor,171,15 +hardenedclay,172,0 +hardclay,172,0 +hclay,172,0 +coalblock,173,0 +blockcoal,173,0 +coblock,173,0 +blockco,173,0 +coalb,173,0 +bcoal,173,0 +packedice,174,0 +packice,174,0 +solidice,174,0 +sunflower,175,0 +yellowsunflower,175,0 +lilac,175,1 +magentalilac,175,1 +syringa,175,1 +longtallgrass,175,2 +extratallgrass,175,2 +doubletallgrass,175,2 +largetallgrass,175,2 +longtgrass,175,2 +extratgrass,175,2 +doubletgrass,175,2 +largetgrass,175,2 +ltgrass,175,2 +etgrass,175,2 +dtgrass,175,2 +bigfern,175,3 +largefern,175,3 +doublefern,175,3 +bfern,175,3 +lfern,175,3 +dfern,175,3 +rosebush,175,4 +redrosebush,175,4 +peony,175,5 +pinkpeony,175,5 +paeonia,175,5 +ironshovel,256,0 +ironspade,256,0 +ishovel,256,0 +ispade,256,0 +steelshovel,256,0 +steelspade,256,0 +ironpickaxe,257,0 +ironpick,257,0 +steelpickaxe,257,0 +steelpick,257,0 +ipickaxe,257,0 +ipick,257,0 +ironaxe,258,0 +iaxe,258,0 +steelaxe,258,0 +flintandsteel,259,0 +flintandiron,259,0 +flintandtinder,259,0 +flintnsteel,259,0 +flintniron,259,0 +flintntinder,259,0 +flintsteel,259,0 +flintiron,259,0 +flinttinder,259,0 +lighter,259,0 +apple,260,0 +normalapple,260,0 +redapple,260,0 +bow,261,0 +arrow,262,0 +coal,263,0 +charcoal,263,1 +ccoal,263,1 +diamond,264,0 +crystal,264,0 +ironingot,265,0 +ironbar,265,0 +ironi,265,0 +steelingot,265,0 +steelbar,265,0 +steeli,265,0 +iingot,265,0 +ibar,265,0 +ingotiron,265,0 +bariron,265,0 +iiron,265,0 +ingotsteel,265,0 +barsteel,265,0 +isteel,265,0 +ingoti,265,0 +bari,265,0 +goldingot,266,0 +goldbar,266,0 +goldi,266,0 +gingot,266,0 +gbar,266,0 +ingotgold,266,0 +bargold,266,0 +igold,266,0 +ingotg,266,0 +barg,266,0 +ironsword,267,0 +steelsword,267,0 +isword,267,0 +woodensword,268,0 +woodsword,268,0 +wsword,268,0 +woodenshovel,269,0 +woodenspade,269,0 +woodshovel,269,0 +woodspade,269,0 +wshovel,269,0 +wspade,269,0 +woodenpickaxe,270,0 +woodenpick,270,0 +woodpickaxe,270,0 +woodpick,270,0 +wpickaxe,270,0 +wpick,270,0 +woodenaxe,271,0 +woodaxe,271,0 +waxe,271,0 +stonesword,272,0 +cobblestonesword,272,0 +cstonesword,272,0 +cssword,272,0 +ssword,272,0 +stoneshovel,273,0 +cobblestoneshovel,273,0 +cobblestonespade,273,0 +cstoneshovel,273,0 +cstonespade,273,0 +stonespade,273,0 +csshovel,273,0 +csspade,273,0 +sshovel,273,0 +sspade,273,0 +stonepickaxe,274,0 +cobblestonepickaxe,274,0 +cobblestonepick,274,0 +cstonepickaxe,274,0 +cstonepick,274,0 +stonepick,274,0 +cspickaxe,274,0 +cspick,274,0 +spickaxe,274,0 +spick,274,0 +stoneaxe,275,0 +cobblestoneaxe,275,0 +cstoneaxe,275,0 +csaxe,275,0 +saxe,275,0 +diamondsword,276,0 +crystalsword,276,0 +dsword,276,0 +diamondshovel,277,0 +diamondspade,277,0 +crystalshovel,277,0 +crystalspade,277,0 +dshovel,277,0 +dspade,277,0 +diamondpickaxe,278,0 +diamondpick,278,0 +crystalpickaxe,278,0 +crystalpick,278,0 +dpickaxe,278,0 +dpick,278,0 +diamondaxe,279,0 +crystalaxe,279,0 +daxe,279,0 +stick,280,0 +twig,280,0 +branch,280,0 +bowl,281,0 +woodenbowl,281,0 +woodbowl,281,0 +mushroomsoup,282,0 +mrsoup,282,0 +soup,282,0 +goldsword,283,0 +gsword,283,0 +goldshovel,284,0 +goldspade,284,0 +gshovel,284,0 +gspade,284,0 +goldpickaxe,285,0 +goldpick,285,0 +gpickaxe,285,0 +gpick,285,0 +goldaxe,286,0 +gaxe,286,0 +string,287,0 +thread,287,0 +feather,288,0 +gunpowder,289,0 +sulfur,289,0 +woodenhoe,290,0 +woodhoe,290,0 +whoe,290,0 +stonehoe,291,0 +cobblestonehoe,291,0 +cstonehoe,291,0 +cshoe,291,0 +shoe,291,0 +ironhoe,292,0 +steelhoe,292,0 +ihoe,292,0 +diamondhoe,293,0 +crystalhoe,293,0 +dhoe,293,0 +goldhoe,294,0 +ghoe,294,0 +seeds,295,0 +seed,295,0 +wheat,296,0 +crops,296,0 +crop,296,0 +bread,297,0 +leatherhelmet,298,0 +leatherhelm,298,0 +leatherhat,298,0 +leathercoif,298,0 +lhelmet,298,0 +lhelm,298,0 +lhat,298,0 +lcoif,298,0 +leatherchestplate,299,0 +leatherplatebody,299,0 +leatherplate,299,0 +leathershirt,299,0 +leathertunic,299,0 +lchestplate,299,0 +lplatebody,299,0 +lplate,299,0 +lshirt,299,0 +ltunic,299,0 +leatherleggings,300,0 +leatherlegs,300,0 +leatherpants,300,0 +lleggings,300,0 +llegs,300,0 +lpants,300,0 +leatherboots,301,0 +leathershoes,301,0 +lboots,301,0 +lshoes,301,0 +chainmailhelmet,302,0 +chainmailhelm,302,0 +chainmailhat,302,0 +chainmailcoif,302,0 +chainmhelmet,302,0 +chainmhelm,302,0 +chainmhat,302,0 +chainmcoif,302,0 +cmailhelmet,302,0 +cmailhelm,302,0 +cmailhat,302,0 +cmailcoif,302,0 +chainhelmet,302,0 +chainhelm,302,0 +chainhat,302,0 +chaincoif,302,0 +cmhelmet,302,0 +cmhelm,302,0 +cmhat,302,0 +cmcoif,302,0 +chainmailchestplate,303,0 +chainmailplatebody,303,0 +chainmailplate,303,0 +chainmailshirt,303,0 +chainmailtunic,303,0 +chainmchestplate,303,0 +chainmplatebody,303,0 +chainmplate,303,0 +chainmshirt,303,0 +chainmtunic,303,0 +cmailchestplate,303,0 +cmailplatebody,303,0 +cmailplate,303,0 +cmailshirt,303,0 +cmailtunic,303,0 +chainchestplate,303,0 +chainplatebody,303,0 +chainplate,303,0 +chainshirt,303,0 +chaintunic,303,0 +cmchestplate,303,0 +cmplatebody,303,0 +cmplate,303,0 +cmshirt,303,0 +cmtunic,303,0 +chainmailleggings,304,0 +chainmaillegs,304,0 +chainmailpants,304,0 +chainmleggings,304,0 +chainmlegs,304,0 +chainmpants,304,0 +cmailleggings,304,0 +cmaillegs,304,0 +cmailpants,304,0 +chainleggings,304,0 +chainlegs,304,0 +chainpants,304,0 +cmleggings,304,0 +cmlegs,304,0 +cmpants,304,0 +chainmailboots,305,0 +chainmailshoes,305,0 +chainmboots,305,0 +chainmshoes,305,0 +cmailboots,305,0 +cmailshoes,305,0 +chainboots,305,0 +chainshoes,305,0 +cmboots,305,0 +cmshoes,305,0 +ironhelmet,306,0 +ironhelm,306,0 +ironhat,306,0 +ironcoif,306,0 +ihelmet,306,0 +ihelm,306,0 +ihat,306,0 +icoif,306,0 +steelhelmet,306,0 +steelhelm,306,0 +steelhat,306,0 +steelcoif,306,0 +shelmet,306,0 +shelm,306,0 +shat,306,0 +scoif,306,0 +ironchestplate,307,0 +ironplatebody,307,0 +ironshirt,307,0 +irontunic,307,0 +ichestplate,307,0 +iplatebody,307,0 +ishirt,307,0 +itunic,307,0 +steelchestplate,307,0 +steelplatebody,307,0 +steelplate,307,0 +steelshirt,307,0 +steeltunic,307,0 +schestplate,307,0 +splatebody,307,0 +sshirt,307,0 +stunic,307,0 +ironleggings,308,0 +ironlegs,308,0 +ironpants,308,0 +ileggings,308,0 +ilegs,308,0 +ipants,308,0 +steelleggings,308,0 +steellegs,308,0 +steelpants,308,0 +sleggings,308,0 +slegs,308,0 +spants,308,0 +ironboots,309,0 +ironshoes,309,0 +iboots,309,0 +ishoes,309,0 +steelboots,309,0 +steelshoes,309,0 +sboots,309,0 +sshoes,309,0 +diamondhelmet,310,0 +diamondhelm,310,0 +diamondhat,310,0 +diamondcoif,310,0 +dhelmet,310,0 +dhelm,310,0 +dhat,310,0 +dcoif,310,0 +crystalhelmet,310,0 +crystalhelm,310,0 +crystalhat,310,0 +crystalcoif,310,0 +chelmet,310,0 +chelm,310,0 +chat,310,0 +ccoif,310,0 +diamondchestplate,311,0 +diamondplatebody,311,0 +diamondplate,311,0 +diamondshirt,311,0 +diamondtunic,311,0 +dchestplate,311,0 +dplatebody,311,0 +dplate,311,0 +dshirt,311,0 +dtunic,311,0 +crystalchestplate,311,0 +crystalplatebody,311,0 +crystalplate,311,0 +crystalshirt,311,0 +crystaltunic,311,0 +cchestplate,311,0 +cplatebody,311,0 +cplate,311,0 +cshirt,311,0 +ctunic,311,0 +diamondleggings,312,0 +diamondlegs,312,0 +diamondpants,312,0 +dleggings,312,0 +dlegs,312,0 +dpants,312,0 +crystalleggings,312,0 +crystallegs,312,0 +crystalpants,312,0 +cleggings,312,0 +clegs,312,0 +cpants,312,0 +diamondboots,313,0 +diamondshoes,313,0 +dboots,313,0 +dshoes,313,0 +crystalboots,313,0 +crystalshoes,313,0 +cboots,313,0 +cshoes,313,0 +goldhelmet,314,0 +goldhelm,314,0 +goldhat,314,0 +goldcoif,314,0 +ghelmet,314,0 +ghelm,314,0 +ghat,314,0 +gcoif,314,0 +goldchestplate,315,0 +goldplatebody,315,0 +goldshirt,315,0 +goldtunic,315,0 +gchestplate,315,0 +gplatebody,315,0 +gplateplate,315,0 +gshirt,315,0 +gtunic,315,0 +goldleggings,316,0 +goldlegs,316,0 +goldpants,316,0 +gleggings,316,0 +glegs,316,0 +gpants,316,0 +goldboots,317,0 +goldshoes,317,0 +gboots,317,0 +gshoes,317,0 +flint,318,0 +pork,319,0 +porkchop,319,0 +rawpork,319,0 +rpork,319,0 +rawporkchop,319,0 +rporkchop,319,0 +cookedpork,320,0 +grilledpork,320,0 +grillpork,320,0 +gpork,320,0 +cookpork,320,0 +cpork,320,0 +grilledporkchop,320,0 +grillporkchop,320,0 +gporkchop,320,0 +cookedporkchop,320,0 +cookporkchop,320,0 +cporkchop,320,0 +bacon,320,0 +painting,321,0 +picture,321,0 +goldenapple,322,0 +goldapple,322,0 +gapple,322,0 +enchantedgoldenapple,322,1 +enchantedgoldapple,322,1 +enchantedgapple,322,1 +supergoldenapple,322,1 +supergoldapple,322,1 +supergapple,322,1 +magicalgoldenapple,322,1 +magicalgoldapple,322,1 +magicalgapple,322,1 +magicgoldenapple,322,1 +magicgoldapple,322,1 +magicgapple,322,1 +egoldenapple,322,1 +egoldapple,322,1 +egapple,322,1 +sgoldenapple,322,1 +sgoldapple,322,1 +sgapple,322,1 +mgoldenapple,322,1 +mgoldapple,322,1 +mgapple,322,1 +sign,323,0 +woodendoor,324,0 +wooddoor,324,0 +wdoor,324,0 +door,324,0 +bucket,325,0 +bukkit,325,0 +waterbucket,326,0 +waterbukkit,326,0 +wbucket,326,0 +wbukkit,326,0 +magmabucket,327,0 +magmabukkit,327,0 +lavabucket,327,0 +lavabukkit,327,0 +lbucket,327,0 +lbukkit,327,0 +minecart,328,0 +mcart,328,0 +cart,328,0 +saddle,329,0 +irondoor,330,0 +idoor,330,0 +steeldoor,330,0 +sdoor,330,0 +dooriron,330,0 +doori,330,0 +doorsteel,330,0 +doors,330,0 +redstonedust,331,0 +redstone,331,0 +rstonedust,331,0 +rstone,331,0 +redsdust,331,0 +reddust,331,0 +rsdust,331,0 +rdust,331,0 +snow,332,0 +snowball,332,0 +snball,332,0 +sball,332,0 +boat,333,0 +leather,334,0 +cowhide,334,0 +hide,334,0 +milkbucket,335,0 +milkbukkit,335,0 +mbucket,335,0 +mbukkit,335,0 +claybrick,336,0 +brick,336,0 +redbrick,336,0 +rbrick,336,0 +clayball,337,0 +cball,337,0 +clay,337,0 +reeds,338,0 +reed,338,0 +sugarcane,338,0 +scane,338,0 +bamboo,338,0 +paper,339,0 +papyrus,339,0 +book,340,0 +slimeball,341,0 +slball,341,0 +chestminecart,342,0 +storageminecart,342,0 +storagemcart,342,0 +chestmcart,342,0 +storagecart,342,0 +chestcart,342,0 +sminecart,342,0 +cminecart,342,0 +smcart,342,0 +cmcart,342,0 +scart,342,0 +ccart,342,0 +furnaceminecart,343,0 +engineminecart,343,0 +poweredminecart,343,0 +powerminecart,343,0 +enginemcart,343,0 +poweredmcart,343,0 +powermcart,343,0 +furnacemcart,343,0 +enginecart,343,0 +poweredcart,343,0 +powercart,343,0 +furnacecart,343,0 +eminecart,343,0 +pminecart,343,0 +fminecart,343,0 +emcart,343,0 +pmcart,343,0 +fmcart,343,0 +ecart,343,0 +pcart,343,0 +fcart,343,0 +egg,344,0 +compass,345,0 +fishingrod,346,0 +fishrod,346,0 +frod,346,0 +rod,346,0 +watch,347,0 +goldwatch,347,0 +goldclock,347,0 +gwatch,347,0 +gclock,347,0 +clock,347,0 +glowstonedust,348,0 +glowingstonedust,348,0 +lightstonedust,348,0 +lbdust,348,0 +gbdust,348,0 +lsdust,348,0 +gsdust,348,0 +rawfish,349,0 +rafish,349,0 +fish,349,0 +rawsalmonfish,349,1 +rasalmonfish,349,1 +salmonfish,349,1 +rawsalmon,349,1 +rasalmon,349,1 +salmon,349,1 +sfish,349,1 +fishs,349,1 +rawclownfish,349,2 +raclownfish,349,2 +clownfish,349,2 +rawnemo,349,2 +ranemo,349,2 +nemo,349,2 +nemofish,349,2 +fishnemo,349,2 +clfish,349,2 +fishcl,349,2 +nfish,349,2 +fishn,349,2 +rawpufferfish,349,3 +rapufferfish,349,3 +pufferfish,349,3 +pufffish,349,3 +fishpuff,349,3 +pfish,349,3 +fishp,349,3 +cookedfish,350,0 +cookfish,350,0 +cfish,350,0 +grilledfish,350,0 +grillfish,350,0 +gfish,350,0 +roastedfish,350,0 +roastfish,350,0 +rofish,350,0 +cookedsalmonfish,350,1 +cooksalmonfish,350,1 +csalmonfish,350,1 +grilledsalmonfish,350,1 +grillsalmonfish,350,1 +gsalmonfish,350,1 +roastedsalmonfish,350,1 +roastsalmonfish,350,1 +rosalmonfish,350,1 +cookedsalmon,350,1 +cooksalmon,350,1 +csalmon,350,1 +grilledsalmon,350,1 +grillsalmon,350,1 +gsalmon,350,1 +roastedsalmon,350,1 +roastsalmon,350,1 +rosalmon,350,1 +dye,351,0 +inksack,351,0 +inksac,351,0 +isack,351,0 +isac,351,0 +sack,351,0 +sac,351,0 +blackinksack,351,0 +blackinksac,351,0 +blackisack,351,0 +blackisac,351,0 +blacksack,351,0 +blacksac,351,0 +inksackblack,351,0 +inksacblack,351,0 +isackblack,351,0 +isacblack,351,0 +sackblack,351,0 +sacblack,351,0 +blackinksackcolour,351,0 +blackinksaccolour,351,0 +blackisackcolour,351,0 +blackisaccolour,351,0 +blacksackcolour,351,0 +blacksaccolour,351,0 +inksackblackcolour,351,0 +inksacblackcolour,351,0 +isackblackcolour,351,0 +isacclackcolour,351,0 +sackblackcolour,351,0 +sacblackcolour,351,0 +blackinksackcolor,351,0 +blackinksaccolor,351,0 +blackisackcolor,351,0 +blackisaccolor,351,0 +blacksackcolor,351,0 +blacksaccolor,351,0 +inksackblackcolor,351,0 +inksacblackcolor,351,0 +isackblackcolor,351,0 +isacblackcolor,351,0 +sackblackcolor,351,0 +sacblackcolor,351,0 +blackinksackdye,351,0 +blackinksacdye,351,0 +blackisackdye,351,0 +blackisacdye,351,0 +blacksackdye,351,0 +blacksacdye,351,0 +inksackblackdye,351,0 +inksacblackdye,351,0 +isackblackdye,351,0 +isacclackdye,351,0 +sackblackdye,351,0 +sacblackdye,351,0 +blackcolor,351,0 +blackdye,351,0 +rosered,351,1 +roseredcolor,351,1 +roseredcolour,351,1 +rosereddye,351,1 +redrosecolor,351,1 +redrosecolour,351,1 +redrosedye,351,1 +redr,351,1 +redrcolor,351,1 +redrcolour,351,1 +redrdye,351,1 +redcolor,351,1 +redcolour,351,1 +reddye,351,1 +cactusgreen,351,2 +greencactus,351,2 +cactusgreencolour,351,2 +greencactuscolour,351,2 +cactusgreencolor,351,2 +greencactuscolor,351,2 +cactusgreendye,351,2 +greencactusdye,351,2 +greencolour,351,2 +greencolor,351,2 +greendye,351,2 +cocoabeans,351,3 +cocoabean,351,3 +cocobeans,351,3 +cocobean,351,3 +cbeans,351,3 +cbean,351,3 +beans,351,3 +bean,351,3 +browncocoabeans,351,3 +browncocoabean,351,3 +browncocobeans,351,3 +browncocobean,351,3 +browncbeans,351,3 +browncbean,351,3 +brownbeans,351,3 +brownbean,351,3 +brownb,351,3 +cocoabeanscolour,351,3 +cocoabeancolour,351,3 +cocobeanscolour,351,3 +cocobeancolour,351,3 +cbeanscolour,351,3 +cbeancolour,351,3 +beanscolour,351,3 +beancolour,351,3 +browncocoabeanscolour,351,3 +browncocoabeancolour,351,3 +browncocobeanscolour,351,3 +browncocobeancolour,351,3 +browncbeanscolour,351,3 +browncbeancolour,351,3 +brownbeanscolour,351,3 +brownbeancolour,351,3 +brownbcolour,351,3 +cocoabeanscolor,351,3 +cocoabeancolor,351,3 +cocobeanscolor,351,3 +cocobeancolor,351,3 +cbeanscolor,351,3 +cbeancolor,351,3 +beanscolor,351,3 +beancolor,351,3 +browncocoabeanscolor,351,3 +browncocoabeancolor,351,3 +browncocobeanscolor,351,3 +browncocobeancolor,351,3 +browncbeanscolor,351,3 +browncbeancolor,351,3 +brownbeanscolor,351,3 +brownbeancolor,351,3 +brownbcolor,351,3 +cocoabeansdye,351,3 +cocoabeandye,351,3 +cocobeansdye,351,3 +cocobeandye,351,3 +cbeansdye,351,3 +cbeandye,351,3 +beansdye,351,3 +beandye,351,3 +browncocoabeansdye,351,3 +browncocoabeandye,351,3 +browncocobeansdye,351,3 +browncocobeandye,351,3 +browncbeansdye,351,3 +browncbeandye,351,3 +brownbeansdye,351,3 +brownbeandye,351,3 +brownbdye,351,3 +browncolour,351,3 +browncolor,351,3 +browndye,351,3 +lapislazuli,351,4 +bluelapislazuli,351,4 +bluelapisl,351,4 +bluelapis,351,4 +bluel,351,4 +lapislazuliblue,351,4 +lapislblue,351,4 +lapisblue,351,4 +lapisl,351,4 +lapis,351,4 +bluelapislazulicolour,351,4 +bluelapislcolour,351,4 +bluelapiscolour,351,4 +lapislazulibluecolour,351,4 +lapislbluecolour,351,4 +lapisbluecolour,351,4 +lapislazulicolour,351,4 +lapislcolour,351,4 +lapiscolour,351,4 +bluelapislazulicolor,351,4 +bluelapislcolor,351,4 +bluelapiscolor,351,4 +lapislazulibluecolor,351,4 +lapislbluecolor,351,4 +lapisbluecolor,351,4 +lapislazulicolor,351,4 +lapislcolor,351,4 +lapiscolor,351,4 +bluelapislazulidye,351,4 +bluelapisldye,351,4 +bluelapisdye,351,4 +lapislazulibluedye,351,4 +lapislbluedye,351,4 +lapisbluedye,351,4 +lapislazulidye,351,4 +lapisldye,351,4 +lapisdye,351,4 +bluecolour,351,4 +bluecolor,351,4 +bluedye,351,4 +purpledye,351,5 +purplecolour,351,5 +purplecolor,351,5 +cyandye,351,6 +cyancolour,351,6 +cyancolor,351,6 +lightgraydye,351,7 +lightgraycolour,351,7 +lightgraycolor,351,7 +lgraycolour,351,7 +lgraycolor,351,7 +lgraydye,351,7 +lightgreydye,351,7 +lightgreycolour,351,7 +lightgreycolor,351,7 +lgreycolour,351,7 +lgreycolor,351,7 +lgreydye,351,7 +silvercolour,351,7 +silvercolor,351,7 +silverdye,351,7 +darkgraydye,351,8 +darkgraycolour,351,8 +darkgraycolor,351,8 +dgraycolour,351,8 +dgraycolor,351,8 +dgraydye,351,8 +graycolour,351,8 +graycolor,351,8 +graydye,351,8 +darkgreydye,351,8 +darkgreycolour,351,8 +darkgreycolor,351,8 +dgreycolour,351,8 +dgreycolor,351,8 +dgreydye,351,8 +greycolour,351,8 +greycolor,351,8 +greydye,351,8 +pinkdye,351,9 +pinkcolour,351,9 +pinkcolor,351,9 +limedye,351,10 +limecolour,351,10 +limecolor,351,10 +dandelionyellow,351,11 +dandelionyellowcolour,351,11 +dandelionyellowcolor,351,11 +dandelionyellowdye,351,11 +yellowdandelioncolour,351,11 +yellowdandelioncolor,351,11 +yellowdandeliondye,351,11 +yellowd,351,11 +yellowdcolour,351,11 +yellowdcolor,351,11 +yellowddye,351,11 +dyellow,351,11 +dyellowcolour,351,11 +dyellowcolor,351,11 +dyellowdye,351,11 +yellowcolour,351,11 +yellowcolor,351,11 +yellowdye,351,11 +lightbluecolour,351,12 +lightbluecolor,351,12 +lightbluedye,351,12 +lbluecolour,351,12 +lbluecolor,351,12 +lbluedye,351,12 +magentacolour,351,13 +magentacolor,351,13 +magentadye,351,13 +orangecolour,351,14 +orangecolor,351,14 +orangedye,351,14 +bonemeal,351,15 +whitebonemeal,351,15 +whitebonemealcolour,351,15 +whitebonemealcolor,351,15 +whitebonemealdye,351,15 +bonemealwhite,351,15 +bonemealwhitecolour,351,15 +bonemealwhitecolor,351,15 +bonemealwhitedye,351,15 +whitebonem,351,15 +whitebonemcolour,351,15 +whitebonemcolor,351,15 +whitebonemdye,351,15 +bonemwhite,351,15 +bonemwhitecolour,351,15 +bonemwhitecolor,351,15 +bonemwhitedye,351,15 +bonemealcolour,351,15 +bonemealcolor,351,15 +bonemealdye,351,15 +bonem,351,15 +bonemcolour,351,15 +bonemcolor,351,15 +bonemdye,351,15 +whitecolour,351,15 +whitecolor,351,15 +whitedye,351,15 +bone,352,0 +sugar,353,0 +whitedust,353,0 +cake,354,0 +bed,355,0 +redstonerepeater,356,0 +redstonerepeat,356,0 +redstonedelayer,356,0 +redstonedelay,356,0 +redstonedioder,356,0 +redstonediode,356,0 +rstonerepeater,356,0 +rstonerepeat,356,0 +rstonedelayer,356,0 +rstonedelay,356,0 +rstonedioder,356,0 +rstonediode,356,0 +redsrepeater,356,0 +redsrepeat,356,0 +redsdelayer,356,0 +redsdelay,356,0 +redsdioder,356,0 +redsdiode,356,0 +rsrepeater,356,0 +rsrepeat,356,0 +rsdelayer,356,0 +rsdelay,356,0 +rsdioder,356,0 +rsdiode,356,0 +repeater,356,0 +repeat,356,0 +delayer,356,0 +delay,356,0 +dioder,356,0 +diode,356,0 +cookie,357,0 +chart,358,0 +map0,358,0 +map1,358,1 +map2,358,2 +map3,358,3 +map4,358,4 +map5,358,5 +map6,358,6 +map7,358,7 +map8,358,8 +map9,358,9 +map10,358,10 +map11,358,11 +map12,358,12 +map13,358,13 +map14,358,14 +map15,358,15 +shears,359,0 +shear,359,0 +sheers,359,0 +sheer,359,0 +woolcutters,359,0 +woolcutter,359,0 +cutterswool,359,0 +cutterwool,359,0 +melonslice,360,0 +mslice,360,0 +slicemelon,360,0 +watermelonslice,360,0 +greenmelonslice,360,0 +melongreenslice,360,0 +pumpkinseeds,361,0 +pseeds,361,0 +seedsp,361,0 +seedspumpkin,361,0 +pumpseeds,361,0 +seedspump,361,0 +melonseeds,362,0 +mseeds,362,0 +watermelonseeds,362,0 +greenmelonseeds,362,0 +gmelonseeds,362,0 +seedsmelon,362,0 +seedswatermelon,362,0 +rawbeef,363,0 +rawsteak,363,0 +uncookedbeef,363,0 +uncookedsteak,363,0 +cowmeat,363,0 +plainbeef,363,0 +beef,364,0 +steak,364,0 +cookedbeef,364,0 +grilledbeef,364,0 +cookedsteak,364,0 +grilledsteak,364,0 +cookedcowmeat,364,0 +rawchicken,365,0 +uncookedchicken,365,0 +plainchicken,365,0 +chickenplain,365,0 +chickenuncooked,365,0 +chickenraw,365,0 +cookedchicken,366,0 +grilledchicken,366,0 +toastedchicken,366,0 +gchicken,366,0 +bbqchicken,366,0 +friedchicken,366,0 +cchicken,366,0 +rottenflesh,367,0 +zombieflesh,367,0 +rottenmeat,367,0 +zombiemeat,367,0 +badflesh,367,0 +poisonflesh,367,0 +zombieremains,367,0 +enderpearl,368,0 +endpearl,368,0 +pearl,368,0 +epearl,368,0 +bluepearl,368,0 +endergem,368,0 +blazerod,369,0 +goldenrod,369,0 +goldrod,369,0 +blazestick,369,0 +goldstick,369,0 +brod,369,0 +grod,369,0 +bstick,369,0 +gstick,369,0 +ghasttear,370,0 +ghastdrop,370,0 +ghosttear,370,0 +ghostdrop,370,0 +gtear,370,0 +gdrop,370,0 +tear,370,0 +goldnugget,371,0 +gnugget,371,0 +goldpebble,371,0 +gpebble,371,0 +goldball,371,0 +gball,371,0 +netherstalk,372,0 +deathstalk,372,0 +hellstalk,372,0 +nstalk,372,0 +dstalk,372,0 +hstalk,372,0 +netherwarts,372,0 +netherwart,372,0 +netherplant,372,0 +nethercrop,372,0 +hellwarts,372,0 +hellwart,372,0 +hellplant,372,0 +hellcrop,372,0 +deathwarts,372,0 +deathwart,372,0 +deathplant,372,0 +deathcrop,372,0 +nwarts,372,0 +nwart,372,0 +ncrop,372,0 +nplant,372,0 +hwarts,372,0 +hwart,372,0 +hplant,372,0 +hcrop,372,0 +dwarts,372,0 +dwart,372,0 +dplant,372,0 +dcrop,372,0 +potion,373,0 +mixture,373,0 +potions,373,0 +waterbottle,373,0 +fullbottle,373,0 +watervase,373,0 +fullvase,373,0 +clearpotion,373,6 +clearpot,373,6 +clearextendedpotion,373,7 +clearexpotion,373,7 +clear2potion,373,7 +clearextendedpot,373,7 +clearexpot,373,7 +clear2pot,373,7 +diffusepotion,373,11 +diffusepot,373,11 +artlesspotion,373,13 +artlesspot,373,13 +thinpotion,373,14 +thinpot,373,14 +thinextendedpotion,373,15 +thinexpotion,373,15 +thin2potion,373,15 +thinextendedpot,373,15 +thinexpot,373,15 +thin2pot,373,15 +awkwardpotion,373,16 +awkwardpot,373,16 +bunglingpotion,373,22 +bunglingpot,373,22 +bunglingextendedpotion,373,23 +bunglingexpotion,373,23 +bungling2potion,373,23 +bunglingextendedpot,373,23 +bunglingexpot,373,23 +bungling2pot,373,23 +smoothpotion,373,27 +smoothpot,373,27 +suavepotion,373,29 +suavepot,373,29 +debonairpotion,373,30 +debonairpot,373,30 +debonairextendedpotion,373,31 +debonairexpotion,373,31 +debonair2potion,373,31 +debonairextendedpot,373,31 +debonairexpot,373,31 +debonair2pot,373,31 +thickpotion,373,32 +thickpot,373,32 +charmingpotion,373,38 +charmingpot,373,38 +charmingextendedpotion,373,39 +charmingexpotion,373,39 +charming2potion,373,39 +charmingextendedpot,373,39 +charmingexpot,373,39 +charming2pot,373,39 +refinedpotion,373,43 +refinedpot,373,43 +cordialpotion,373,45 +cordialpot,373,45 +sparklingpotion,373,46 +sparklingpot,373,46 +sparklingextendedpotion,373,47 +sparklingexpotion,373,47 +sparkling2potion,373,47 +sparklingextendedpot,373,47 +sparklingexpot,373,47 +sparkling2pot,373,47 +potentpotion,373,48 +potentpot,373,48 +rankpotion,373,54 +rankpot,373,54 +rankextendedpotion,373,55 +rankexpotion,373,55 +rank2potion,373,55 +rankextendedpot,373,55 +rankexpot,373,55 +rank2pot,373,55 +acridpotion,373,59 +acridpot,373,59 +grosspotion,373,61 +grosspot,373,61 +stinkypotion,373,62 +stinkypot,373,62 +stinkyextendedpotion,373,63 +stinkyexpotion,373,63 +stinky2potion,373,63 +stinkyextendedpot,373,63 +stinkyexpot,373,63 +stinky2pot,373,63 +mundaneextendedpotion,373,64 +mundaneexpotion,373,64 +mundane2potion,373,64 +mundaneextendedpot,373,64 +mundaneexpot,373,64 +mundane2pot,373,64 +mundanepotion,373,8192 +mundanepot,373,8192 +regenerationpotion,373,8193 +regeneratepotion,373,8193 +regenpotion,373,8193 +regenerationpot,373,8193 +regeneratepot,373,8193 +regenpot,373,8193 +rpot,373,8193 +swiftnesspotion,373,8194 +swiftpotion,373,8194 +speedpotion,373,8194 +swiftnesspot,373,8194 +swiftpot,373,8194 +speedpot,373,8194 +swpot,373,8194 +fireresistancepotion,373,8195 +fireresistpotion,373,8195 +firerespotion,373,8195 +fireresistancepot,373,8195 +fireresistpot,373,8195 +firerespot,373,8195 +fpot,373,8195 +poisonpotion,373,8196 +acidpotion,373,8196 +poisonpot,373,8196 +acidpot,373,8196 +ppot,373,8196 +healingpotion,373,8197 +healpotion,373,8197 +lifepotion,373,8197 +healingpot,373,8197 +healpot,373,8197 +lifepot,373,8197 +hpot,373,8197 +nightvisionpotion,373,8198 +nvisionpotion,373,8198 +nightvpotion,373,8198 +darkvisionpotion,373,8198 +dvisionpotion,373,8198 +darkvpotion,373,8198 +nightvisionpot,373,8198 +nvisionpot,373,8198 +nightvpot,373,8198 +darkvisionpot,373,8198 +dvisionpot,373,8198 +darkvpot,373,8198 +npot,373,8198 +weaknesspotion,373,8200 +weakpotion,373,8200 +weaknesspot,373,8200 +weakpot,373,8200 +wpot,373,8200 +strengthpotion,373,8201 +strongpotion,373,8201 +strpotion,373,8201 +strengthpot,373,8201 +strongpot,373,8201 +strpot,373,8201 +stpot,373,8201 +slownesspotion,373,8202 +slowpotion,373,8202 +slownesspot,373,8202 +slowpot,373,8202 +slpot,373,8202 +harmingpotion,373,8204 +damagepotion,373,8204 +dmgpotion,373,8204 +harmingpot,373,8204 +damagepot,373,8204 +dmgpot,373,8204 +dpot,373,8204 +waterbreathingpotion,373,8205 +waterbreathpotion,373,8205 +breathingpotion,373,8205 +breathpotion,373,8205 +waterbreathingpot,373,8205 +waterbreathpot,373,8205 +breathingpot,373,8205 +breathpot,373,8205 +wbpot,373,8205 +invisibilitypotion,373,8206 +invisiblepotion,373,8206 +invpotion,373,8206 +invisibilitypot,373,8206 +invisiblepot,373,8206 +invpot,373,8206 +ipot,373,8206 +regenerationleveliipotion,373,8225 +regenerateleveliipotion,373,8225 +regenleveliipotion,373,8225 +regenerationlevel2potion,373,8225 +regeneratelevel2potion,373,8225 +regenlevel2potion,373,8225 +regenerationiipotion,373,8225 +regenerateiipotion,373,8225 +regeniipotion,373,8225 +regenerationleveliipot,373,8225 +regenerateleveliipot,373,8225 +regenleveliipot,373,8225 +regenerationlevel2pot,373,8225 +regeneratelevel2pot,373,8225 +regenlevel2pot,373,8225 +regenerationiipot,373,8225 +regenerateiipot,373,8225 +regeniipot,373,8225 +r2pot,373,8225 +swiftnessleveliipotion,373,8226 +swiftleveliipotion,373,8226 +speedleveliipotion,373,8226 +swiftnesslevel2potion,373,8226 +swiftlevel2potion,373,8226 +speedlevel2potion,373,8226 +swiftnessiipotion,373,8226 +swiftiipotion,373,8226 +speediipotion,373,8226 +swiftnessleveliipot,373,8226 +swiftleveliipot,373,8226 +speedleveliipot,373,8226 +swiftnesslevel2pot,373,8226 +swiftlevel2pot,373,8226 +speedlevel2pot,373,8226 +swiftnessiipot,373,8226 +swiftiipot,373,8226 +speediipot,373,8226 +sw2pot,373,8226 +poisonleveliipotion,373,8228 +acidleveliipotion,373,8228 +poisonlevel2potion,373,8228 +acidlevel2potion,373,8228 +poisoniipotion,373,8228 +acidiipotion,373,8228 +poisonleveliipot,373,8228 +acidleveliipot,373,8228 +poisonlevel2pot,373,8228 +acidlevel2pot,373,8228 +poisoniipot,373,8228 +acidiipot,373,8228 +p2pot,373,8228 +healingleveliipotion,373,8229 +healleveliipotion,373,8229 +healinglevel2potion,373,8229 +heallevel2potion,373,8229 +healingiipotion,373,8229 +healiipotion,373,8229 +healingleveliipot,373,8229 +healleveliipot,373,8229 +healinglevel2pot,373,8229 +heallevel2pot,373,8229 +healingiipot,373,8229 +healiipot,373,8229 +h2pot,373,8229 +strengthleveliipotion,373,8233 +strongleveliipotion,373,8233 +strleveliipotion,373,8233 +strengthlevel2potion,373,8233 +stronglevel2potion,373,8233 +strlevel2potion,373,8233 +strengthiipotion,373,8233 +strongiipotion,373,8233 +striipotion,373,8233 +strengthleveliipot,373,8233 +strongleveliipot,373,8233 +strleveliipot,373,8233 +strengthlevel2pot,373,8233 +stronglevel2pot,373,8233 +strlevel2pot,373,8233 +strengthiipot,373,8233 +strongiipot,373,8233 +striipot,373,8233 +st2pot,373,8233 +harmingleveliipotion,373,8236 +damageleveliipotion,373,8236 +dmgleveliipotion,373,8236 +harminglevel2potion,373,8236 +damagelevel2potion,373,8236 +dmglevel2potion,373,8236 +harmingiipotion,373,8236 +damageiipotion,373,8236 +dmgiipotion,373,8236 +harmingleveliipot,373,8236 +damageleveliipot,373,8236 +dmgleveliipot,373,8236 +harminglevel2pot,373,8236 +damagelevel2pot,373,8236 +dmglevel2pot,373,8236 +harmingiipot,373,8236 +damageiipot,373,8236 +dmgiipot,373,8236 +d2pot,373,8236 +regenerationextendedpotion,373,8257 +regenerateextendedpotion,373,8257 +regenextendepotion,373,8257 +regenerationexpotion,373,8257 +regenerateexpotion,373,8257 +regenexpotion,373,8257 +regenerationextendedpot,373,8257 +regenerateextendedpot,373,8257 +regenextendepot,373,8257 +regenerationexpot,373,8257 +regenerateexpot,373,8257 +regenexpot,373,8257 +repot,373,8257 +swiftnessextendedpotion,373,8258 +swiftextendedpotion,373,8258 +speedextendedpotion,373,8258 +swiftnessexpotion,373,8258 +swiftexpotion,373,8258 +speedexpotion,373,8258 +swiftnessextendedpot,373,8258 +swiftextendedpot,373,8258 +speedextendedpot,373,8258 +swiftnessexpot,373,8258 +swiftexpot,373,8258 +speedexpot,373,8258 +swepot,373,8258 +fireresistanceextendedpotion,373,8259 +fireresistextendedpotion,373,8259 +fireresextendedpotion,373,8259 +fireresistanceexpotion,373,8259 +fireresistexpotion,373,8259 +fireresexpotion,373,8259 +fireresistanceextendedpot,373,8259 +fireresistextendedpot,373,8259 +fireresextendedpot,373,8259 +fireresistanceexpot,373,8259 +fireresistexpot,373,8259 +fireresexpot,373,8259 +fepot,373,8259 +poisonextendedpotion,373,8260 +acidextendedpotion,373,8260 +poisonexpotion,373,8260 +acidexpotion,373,8260 +poisonextendedpot,373,8260 +acidextendedpot,373,8260 +poisonexpot,373,8260 +acidexpot,373,8260 +pepot,373,8260 +nightvisionextendedpotion,373,8262 +nvisionextendedpotion,373,8262 +nightvextendedpotion,373,8262 +darkvisionextendedpotion,373,8262 +dvisionextendedpotion,373,8262 +darkvextendedpotion,373,8262 +nightvisionexpotion,373,8262 +nvisionexpotion,373,8262 +nightvexpotion,373,8262 +darkvisionexpotion,373,8262 +dvisionexpotion,373,8262 +darkvexpotion,373,8262 +nightvisionextendedpot,373,8262 +nvisionextendedpot,373,8262 +nightvextendedpot,373,8262 +darkvisionextendedpot,373,8262 +dvisionextendedpot,373,8262 +darkvextendedpot,373,8262 +nightvisionexpot,373,8262 +nvisionexpot,373,8262 +nightvexpot,373,8262 +darkvisionexpot,373,8262 +dvisionexpot,373,8262 +darkvexpot,373,8262 +nepot,373,8262 +weaknessextendedpotion,373,8264 +weakextendedpotion,373,8264 +weaknessexpotion,373,8264 +weakexpotion,373,8264 +weaknessextendedpot,373,8264 +weakextendedpot,373,8264 +weaknessexpot,373,8264 +weakexpot,373,8264 +wepot,373,8264 +strengthextendedpotion,373,8265 +strongextendedpotion,373,8265 +strextendedpotion,373,8265 +strengthexpotion,373,8265 +strongexpotion,373,8265 +strexpotion,373,8265 +strengthextendedpot,373,8265 +strongextendedpot,373,8265 +strextendedpot,373,8265 +strengthexpot,373,8265 +strongexpot,373,8265 +strexpot,373,8265 +stepot,373,8265 +slownessextendedpotion,373,8266 +slowextenedpotion,373,8266 +slownessexpotion,373,8266 +slowexpotion,373,8266 +slownessextendedpot,373,8266 +slowextenedpot,373,8266 +slownessexpot,373,8266 +slowexpot,373,8266 +slepot,373,8266 +waterbreathingextendedpotion,373,8269 +waterbreathextendedpotion,373,8269 +breathingextendedpotion,373,8269 +breathextendedpotion,373,8269 +waterbreathingextendedpot,373,8269 +waterbreathextendedpot,373,8269 +breathingextendedpot,373,8269 +breathextendedpot,373,8269 +waterbreathingexpotion,373,8269 +waterbreathexpotion,373,8269 +breathingexpotion,373,8269 +breathexpotion,373,8269 +waterbreathingexpot,373,8269 +waterbreathexpot,373,8269 +breathingexpot,373,8269 +breathexpot,373,8269 +wbepot,373,8269 +invisibilityextendedpotion,373,8270 +invisibleextendedpotion,373,8270 +invextendedpotion,373,8270 +invisibilityexpotion,373,8270 +invisibleexpotion,373,8270 +invexpotion,373,8270 +invisibilityextendedpot,373,8270 +invisibleextendedpot,373,8270 +invextendedpot,373,8270 +invisibilityexpot,373,8270 +invisibleexpot,373,8270 +invexpot,373,8270 +iepot,373,8270 +regenerationdualbitpotion,373,8289 +regeneratedualbitpotion,373,8289 +regendualbitpotion,373,8289 +regenerationdbpotion,373,8289 +regeneratedbpotion,373,8289 +regendbpotion,373,8289 +regenerationdualbitpot,373,8289 +regeneratedualbitpot,373,8289 +regendualbitpot,373,8289 +regenerationdbpot,373,8289 +regeneratedbpot,373,8289 +regendbpot,373,8289 +rdbpot,373,8289 +swiftnessdualbitpotion,373,8290 +swiftdualbitpotion,373,8290 +speeddualbitpotion,373,8290 +swiftnessdualbitpot,373,8290 +swiftdualbitpot,373,8290 +speeddualbitpot,373,8290 +swiftnessdbpotion,373,8290 +swiftdbpotion,373,8290 +speeddbpotion,373,8290 +swiftnessdbpot,373,8290 +swiftdbpot,373,8290 +speeddbpot,373,8290 +swdbpot,373,8290 +poisondualbitpotion,373,8292 +aciddualbitpotion,373,8292 +poisondualbitpot,373,8292 +aciddualbitpot,373,8292 +poisondbpotion,373,8292 +aciddbpotion,373,8292 +poisondbpot,373,8292 +aciddbpot,373,8292 +pdbpot,373,8292 +strengthdualbitpotion,373,8297 +strongdualbitpotion,373,8297 +strdualbitpotion,373,8297 +strengthdualbitpot,373,8297 +strongdualbitpot,373,8297 +strdualbitpot,373,8297 +strengthdbpotion,373,8297 +strongdbpotion,373,8297 +strdbpotion,373,8297 +strengthdbpot,373,8297 +strongdbpot,373,8297 +strdbpot,373,8297 +stdbpot,373,8297 +splashmundanepotion,373,16384 +splmundanepotion,373,16384 +splashregenerationpotion,373,16385 +splashregeneratepotion,373,16385 +splashregenpotion,373,16385 +splashregenerationpot,373,16385 +splashregeneratepot,373,16385 +splashregenpot,373,16385 +regenerationsplashpotion,373,16385 +regeneratesplashpotion,373,16385 +regensplashpotion,373,16385 +splregenerationpotion,373,16385 +splregeneratepotion,373,16385 +splregenpotion,373,16385 +splregenerationpot,373,16385 +splregeneratepot,373,16385 +splregenpot,373,16385 +sprpot,373,16385 +splashswiftnesspotion,373,16386 +splashswiftpotion,373,16386 +splashspeedpotion,373,16386 +splashswiftnesspot,373,16386 +splashswiftpot,373,16386 +splashspeedpot,373,16386 +splswiftnesspotion,373,16386 +splswiftpotion,373,16386 +splspeedpotion,373,16386 +splswiftnesspot,373,16386 +splswiftpot,373,16386 +splspeedpot,373,16386 +spswpot,373,16386 +splashfireresistancepotion,373,16387 +splashfireresistpotion,373,16387 +splashfirerespotion,373,16387 +splashfireresistancepot,373,16387 +splashfireresistpot,373,16387 +splashfirerespot,373,16387 +splfireresistancepotion,373,16387 +splfireresistpotion,373,16387 +splfirerespotion,373,16387 +splfireresistancepot,373,16387 +splfireresistpot,373,16387 +splfirerespot,373,16387 +spfpot,373,16387 +splashpoisonpotion,373,16388 +splashacidpotion,373,16388 +splashpoisonpot,373,16388 +splashacidpot,373,16388 +splpoisonpotion,373,16388 +splacidpotion,373,16388 +splpoisonpot,373,16388 +splacidpot,373,16388 +spppot,373,16388 +splashhealingpotion,373,16389 +splashhealpotion,373,16389 +splashlifepotion,373,16389 +splashhealingpot,373,16389 +splashhealpot,373,16389 +splashlifepot,373,16389 +splhealingpotion,373,16389 +splhealpotion,373,16389 +spllifepotion,373,16389 +splhealingpot,373,16389 +splhealpot,373,16389 +spllifepot,373,16389 +sphpot,373,16389 +splashclearpotion,373,16390 +splashclearpot,373,16390 +splclearpotion,373,16390 +splclearpot,373,16390 +splashnightvisionpotion,373,16390 +splashnvisionpotion,373,16390 +splashnightvpotion,373,16390 +splashdarkvisionpotion,373,16390 +splashdvisionpotion,373,16390 +splashdarkvpotion,373,16390 +splashnightvisionpot,373,16390 +splashnvisionpot,373,16390 +splashnightvpot,373,16390 +splashdarkvisionpot,373,16390 +splashdvisionpot,373,16390 +splashdarkvpot,373,16390 +splnightvisionpotion,373,16390 +splnvisionpotion,373,16390 +splnightvpotion,373,16390 +spldarkvisionpotion,373,16390 +spldvisionpotion,373,16390 +spldarkvpotion,373,16390 +splnightvisionpot,373,16390 +splnvisionpot,373,16390 +splnightvpot,373,16390 +spldarkvisionpot,373,16390 +spldvisionpot,373,16390 +spldarkvpot,373,16390 +spnpot,373,16390 +splashclearextendedpotion,373,16391 +splashclearexpotion,373,16391 +splashclear2potion,373,16391 +splashclearextendedpot,373,16391 +splashclearexpot,373,16391 +splashclear2pot,373,16391 +splclearextendedpotion,373,16391 +splclearexpotion,373,16391 +splclear2potion,373,16391 +splclearextendedpot,373,16391 +splclearexpot,373,16391 +splclear2pot,373,16391 +splashweaknesspotion,373,16392 +splashweakpotion,373,16392 +splashweaknesspot,373,16392 +splashweakpot,373,16392 +splweaknesspotion,373,16392 +splweakpotion,373,16392 +splweaknesspot,373,16392 +splweakpot,373,16392 +spwpot,373,16392 +splashstrengthpotion,373,16393 +splashstrongpotion,373,16393 +splashstrpotion,373,16393 +splashstrengthpot,373,16393 +splashstrongpot,373,16393 +splashstrpot,373,16393 +splstrengthpotion,373,16393 +splstrongpotion,373,16393 +splstrpotion,373,16393 +splstrengthpot,373,16393 +splstrongpot,373,16393 +splstrpot,373,16393 +spstpot,373,16393 +splashslownesspotion,373,16394 +splashslowpotion,373,16394 +splashslownesspot,373,16394 +splashslowpot,373,16394 +splslownesspotion,373,16394 +splslowpotion,373,16394 +splslownesspot,373,16394 +splslowpot,373,16394 +spslpot,373,16394 +splashdiffusepotion,373,16395 +splashdiffusepot,373,16395 +spldiffusepotion,373,16395 +spldiffusepot,373,16395 +splashharmingpotion,373,16396 +splashdamagepotion,373,16396 +splashdmgpotion,373,16396 +splashharmingpot,373,16396 +splashdamagepot,373,16396 +splashdmgpot,373,16396 +splharmingpotion,373,16396 +spldamagepotion,373,16396 +spldmgpotion,373,16396 +splharmingpot,373,16396 +spldamagepot,373,16396 +spldmgpot,373,16396 +spdpot,373,16396 +splashartlesspotion,373,16397 +splashartlesspot,373,16397 +splartlesspotion,373,16397 +splartlesspot,373,16397 +splashwaterbreathingpotion,373,16397 +splashwaterbreathpotion,373,16397 +splashbreathingpotion,373,16397 +splashbreathpotion,373,16397 +splashwaterbreathingpot,373,16397 +splashwaterbreathpot,373,16397 +splashbreathingpot,373,16397 +splashbreathpot,373,16397 +splwaterbreathingpotion,373,16397 +splwaterbreathpotion,373,16397 +splbreathingpotion,373,16397 +splbreathpotion,373,16397 +splwaterbreathingpot,373,16397 +splwaterbreathpot,373,16397 +splbreathingpot,373,16397 +splbreathpot,373,16397 +spwbpot,373,16397 +splashthinpotion,373,16398 +splashthinpot,373,16398 +splthinpotion,373,16398 +splthinpot,373,16398 +splashinvisibilitypotion,373,16398 +splashinvisiblepotion,373,16398 +splashinvpotion,373,16398 +splashinvisibilitypot,373,16398 +splashinvisiblepot,373,16398 +splashinvpot,373,16398 +splinvisibilitypotion,373,16398 +splinvisiblepotion,373,16398 +splinvpotion,373,16398 +splinvisibilitypot,373,16398 +splinvisiblepot,373,16398 +splinvpot,373,16398 +spipot,373,16398 +splashthinextendedpotion,373,16399 +splashthinexpotion,373,16399 +splashthin2potion,373,16399 +splashthinextendedpot,373,16399 +splashthinexpot,373,16399 +splashthin2pot,373,16399 +splthinextendedpotion,373,16399 +splthinexpotion,373,16399 +splthin2potion,373,16399 +splthinextendedpot,373,16399 +splthinexpot,373,16399 +splthin2pot,373,16399 +splashawkwardpotion,373,16400 +splashawkwardpot,373,16400 +splawkwardpotion,373,16400 +splawkwardpot,373,16400 +splashbunglingpotion,373,16406 +splashbunglingpot,373,16406 +splbunglingpotion,373,16406 +splbunglingpot,373,16406 +splashbunglingextendedpotion,373,16407 +splashbunglingexpotion,373,16407 +splashbungling2potion,373,16407 +splashbunglingextendedpot,373,16407 +splashbunglingexpot,373,16407 +splashbungling2pot,373,16407 +splbunglingextendedpotion,373,16407 +splbunglingexpotion,373,16407 +splbungling2potion,373,16407 +splbunglingextendedpot,373,16407 +splbunglingexpot,373,16407 +splbungling2pot,373,16407 +splashsmoothpotion,373,16411 +splashsmoothpot,373,16411 +splsmoothpotion,373,16411 +splsmoothpot,373,16411 +splashsuavepotion,373,16413 +splashsuavepot,373,16413 +splsuavepotion,373,16413 +splsuavepot,373,16413 +splashdebonairpotion,373,16414 +splashdebonairpot,373,16414 +spldebonairpotion,373,16414 +spldebonairpot,373,16414 +splashdebonairextendedpotion,373,16415 +splashdebonairexpotion,373,16415 +splashdebonair2potion,373,16415 +splashdebonairextendedpot,373,16415 +splashdebonairexpot,373,16415 +splashdebonair2pot,373,16415 +spldebonairextendedpotion,373,16415 +spldebonairexpotion,373,16415 +spldebonair2potion,373,16415 +spldebonairextendedpot,373,16415 +spldebonairexpot,373,16415 +spldebonair2pot,373,16415 +splashthickpotion,373,16416 +splashthickpot,373,16416 +splthickpotion,373,16416 +splthickpot,373,16416 +splashregenerationleveliipotion,373,16417 +splashregenerateleveliipotion,373,16417 +splashregenleveliipotion,373,16417 +splashregenerationlevel2potion,373,16417 +splashregeneratelevel2potion,373,16417 +splashregenlevel2potion,373,16417 +splashregenerationiipotion,373,16417 +splashregenerateiipotion,373,16417 +splashregeniipotion,373,16417 +splashregenerationleveliipot,373,16417 +splashregenerateleveliipot,373,16417 +splashregenleveliipot,373,16417 +splashregenerationlevel2pot,373,16417 +splashregeneratelevel2pot,373,16417 +splashregenlevel2pot,373,16417 +splashregenerationiipot,373,16417 +splashregenerateiipot,373,16417 +splashregeniipot,373,16417 +splregenerationleveliipotion,373,16417 +splregenerateleveliipotion,373,16417 +splregenleveliipotion,373,16417 +splregenerationlevel2potion,373,16417 +splregeneratelevel2potion,373,16417 +splregenlevel2potion,373,16417 +splregenerationiipotion,373,16417 +splregenerateiipotion,373,16417 +splregeniipotion,373,16417 +splregenerationleveliipot,373,16417 +splregenerateleveliipot,373,16417 +splregenleveliipot,373,16417 +splregenerationlevel2pot,373,16417 +splregeneratelevel2pot,373,16417 +splregenlevel2pot,373,16417 +splregenerationiipot,373,16417 +splregenerateiipot,373,16417 +splregeniipot,373,16417 +spr2pot,373,16417 +splashswiftnessleveliipotion,373,16418 +splashswiftleveliipotion,373,16418 +splashspeedleveliipotion,373,16418 +splashswiftnesslevel2potion,373,16418 +splashswiftlevel2potion,373,16418 +splashspeedlevel2potion,373,16418 +splashswiftnessiipotion,373,16418 +splashswiftiipotion,373,16418 +splashspeediipotion,373,16418 +splashswiftnessleveliipot,373,16418 +splashswiftleveliipot,373,16418 +splashspeedleveliipot,373,16418 +splashswiftnesslevel2pot,373,16418 +splashswiftlevel2pot,373,16418 +splashspeedlevel2pot,373,16418 +splashswiftnessiipot,373,16418 +splashswiftiipot,373,16418 +splashspeediipot,373,16418 +splswiftnessleveliipotion,373,16418 +splswiftleveliipotion,373,16418 +splspeedleveliipotion,373,16418 +splswiftnesslevel2potion,373,16418 +splswiftlevel2potion,373,16418 +splspeedlevel2potion,373,16418 +splswiftnessiipotion,373,16418 +splswiftiipotion,373,16418 +splspeediipotion,373,16418 +splswiftnessleveliipot,373,16418 +splswiftleveliipot,373,16418 +splspeedleveliipot,373,16418 +splswiftnesslevel2pot,373,16418 +splswiftlevel2pot,373,16418 +splspeedlevel2pot,373,16418 +splswiftnessiipot,373,16418 +splswiftiipot,373,16418 +splspeediipot,373,16418 +spsw2pot,373,16418 +splashpoisonleveliipotion,373,16420 +splashacidleveliipotion,373,16420 +splashpoisonlevel2potion,373,16420 +splashacidlevel2potion,373,16420 +splashpoisoniipotion,373,16420 +splashacidiipotion,373,16420 +splashpoisonleveliipot,373,16420 +splashacidleveliipot,373,16420 +splashpoisonlevel2pot,373,16420 +splashacidlevel2pot,373,16420 +splashpoisoniipot,373,16420 +splashacidiipot,373,16420 +splpoisonleveliipotion,373,16420 +splacidleveliipotion,373,16420 +splpoisonlevel2potion,373,16420 +splcidlevel2potion,373,16420 +splpoisoniipotion,373,16420 +splacidiipotion,373,16420 +splpoisonleveliipot,373,16420 +splacidleveliipot,373,16420 +splpoisonlevel2pot,373,16420 +splacidlevel2pot,373,16420 +splpoisoniipot,373,16420 +splacidiipot,373,16420 +spp2pot,373,16420 +splashhealingleveliipotion,373,16421 +splashhealleveliipotion,373,16421 +splashhealinglevel2potion,373,16421 +splashheallevel2potion,373,16421 +splashhealingiipotion,373,16421 +splashhealiipotion,373,16421 +splashhealingleveliipot,373,16421 +splashhealleveliipot,373,16421 +splashhealinglevel2pot,373,16421 +splashheallevel2pot,373,16421 +splashhealingiipot,373,16421 +splashhealiipot,373,16421 +splhealingleveliipotion,373,16421 +splhealleveliipotion,373,16421 +splhealinglevel2potion,373,16421 +splheallevel2potion,373,16421 +splhealingiipotion,373,16421 +splhealiipotion,373,16421 +splhealingleveliipot,373,16421 +splhealleveliipot,373,16421 +splhealinglevel2pot,373,16421 +splheallevel2pot,373,16421 +splhealingiipot,373,16421 +splhealiipot,373,16421 +sph2pot,373,16421 +splashcharmingpotion,373,16422 +splashcharmingpot,373,16422 +splcharmingpotion,373,16422 +splcharmingpot,373,16422 +splashcharmingextendedpotion,373,16423 +splashcharmingexpotion,373,16423 +splashcharming2potion,373,16423 +splashcharmingextendedpot,373,16423 +splashcharmingexpot,373,16423 +splashcharming2pot,373,16423 +splcharmingextendedpotion,373,16423 +splcharmingexpotion,373,16423 +splcharming2potion,373,16423 +splcharmingextendedpot,373,16423 +splcharmingexpot,373,16423 +splcharming2pot,373,16423 +splashstrengthleveliipotion,373,16425 +splashstrongleveliipotion,373,16425 +splashstrleveliipotion,373,16425 +splashstrengthlevel2potion,373,16425 +splashstronglevel2potion,373,16425 +splashstrlevel2potion,373,16425 +splashstrengthiipotion,373,16425 +splashstrongiipotion,373,16425 +splashstriipotion,373,16425 +splashstrengthleveliipot,373,16425 +splashstrongleveliipot,373,16425 +splashstrleveliipot,373,16425 +splashstrengthlevel2pot,373,16425 +splashstronglevel2pot,373,16425 +splashstrlevel2pot,373,16425 +splashstrengthiipot,373,16425 +splashstrongiipot,373,16425 +splashstriipot,373,16425 +splstrengthleveliipotion,373,16425 +splstrongleveliipotion,373,16425 +splstrleveliipotion,373,16425 +splstrengthlevel2potion,373,16425 +splstronglevel2potion,373,16425 +splstrlevel2potion,373,16425 +splstrengthiipotion,373,16425 +splstrongiipotion,373,16425 +splstriipotion,373,16425 +splstrengthleveliipot,373,16425 +splstrongleveliipot,373,16425 +splstrleveliipot,373,16425 +splstrengthlevel2pot,373,16425 +splstronglevel2pot,373,16425 +splstrlevel2pot,373,16425 +splstrengthiipot,373,16425 +splstrongiipot,373,16425 +splstriipot,373,16425 +spst2pot,373,16425 +splashrefinedpotion,373,16427 +splashrefinedpot,373,16427 +splrefinedpotion,373,16427 +splrefinedpot,373,16427 +splashharmingleveliipotion,373,16428 +splashdamageleveliipotion,373,16428 +splashdmgleveliipotion,373,16428 +splashharminglevel2potion,373,16428 +splashdamagelevel2potion,373,16428 +splashdmglevel2potion,373,16428 +splashharmingiipotion,373,16428 +splashdamageiipotion,373,16428 +splashdmgiipotion,373,16428 +splashharmingleveliipot,373,16428 +splashdamageleveliipot,373,16428 +splashdmgleveliipot,373,16428 +splashharminglevel2pot,373,16428 +splashdamagelevel2pot,373,16428 +splashdmglevel2pot,373,16428 +splashharmingiipot,373,16428 +splashdamageiipot,373,16428 +splashdmgiipot,373,16428 +splharmingleveliipotion,373,16428 +spldamageleveliipotion,373,16428 +spldmgleveliipotion,373,16428 +splharminglevel2potion,373,16428 +spldamagelevel2potion,373,16428 +spldmglevel2potion,373,16428 +splharmingiipotion,373,16428 +spldamageiipotion,373,16428 +spldmgiipotion,373,16428 +splharmingleveliipot,373,16428 +spldamageleveliipot,373,16428 +spldmgleveliipot,373,16428 +splharminglevel2pot,373,16428 +spldamagelevel2pot,373,16428 +spldmglevel2pot,373,16428 +splharmingiipot,373,16428 +spldamageiipot,373,16428 +spldmgiipot,373,16428 +spd2pot,373,16428 +splashcordialpotion,373,16429 +splashcordialpot,373,16429 +splcordialpotion,373,16429 +splcordialpot,373,16429 +splashsparklingpotion,373,16430 +splashsparklingpot,373,16430 +splsparklingpotion,373,16430 +splsparklingpot,373,16430 +splashsparklingextendedpotion,373,16431 +splashsparklingexpotion,373,16431 +splashsparkling2potion,373,16431 +splashsparklingextendedpot,373,16431 +splashsparklingexpot,373,16431 +splashsparkling2pot,373,16431 +splsparklingextendedpotion,373,16431 +splsparklingexpotion,373,16431 +splsparkling2potion,373,16431 +splsparklingextendedpot,373,16431 +splsparklingexpot,373,16431 +splsparkling2pot,373,16431 +splashpotentpotion,373,16432 +splashpotentpot,373,16432 +splpotentpotion,373,16432 +splpotentpot,373,16432 +splashrankpotion,373,16438 +splashrankpot,373,16438 +splrankpotion,373,16438 +splrankpot,373,16438 +splashrankextendedpotion,373,16439 +splashrankexpotion,373,16439 +splashrank2potion,373,16439 +splashrankextendedpot,373,16439 +splashrankexpot,373,16439 +splashrank2pot,373,16439 +splrankextendedpotion,373,16439 +splrankexpotion,373,16439 +splrank2potion,373,16439 +splrankextendedpot,373,16439 +splrankexpot,373,16439 +splrank2pot,373,16439 +splashacridpotion,373,16443 +splashacridpot,373,16443 +splacridpotion,373,16443 +splacridpot,373,16443 +splashgrosspotion,373,16445 +splashgrosspot,373,16445 +splgrosspotion,373,16445 +splgrosspot,373,16445 +splashstinkypotion,373,16446 +splashstinkypot,373,16446 +splstinkypotion,373,16446 +splstinkypot,373,16446 +splashstinkyextendedpotion,373,16447 +splashstinkyexpotion,373,16447 +splashstinky2potion,373,16447 +splashstinkyextendedpot,373,16447 +splashstinkyexpot,373,16447 +splashstinky2pot,373,16447 +splstinkyextendedpotion,373,16447 +splstinkyexpotion,373,16447 +splstinky2potion,373,16447 +splstinkyextendedpot,373,16447 +splstinkyexpot,373,16447 +splstinky2pot,373,16447 +splashmundaneextendedpotion,373,16448 +splashmundaneexpotion,373,16448 +splashmundane2potion,373,16448 +splashmundaneextendedpot,373,16448 +splashmundaneexpot,373,16448 +splashmundane2pot,373,16448 +splmundaneextendedpotion,373,16448 +splmundaneexpotion,373,16448 +splmundane2potion,373,16448 +splmundaneextendedpot,373,16448 +splmundaneexpot,373,16448 +splmundane2pot,373,16448 +splashregenerationextendedpotion,373,16449 +splashregenerateextendedpotion,373,16449 +splashregenextendepotion,373,16449 +splashregenerationexpotion,373,16449 +splashregenerateexpotion,373,16449 +splashregenexpotion,373,16449 +splashregenerationextendedpot,373,16449 +splashregenerateextendedpot,373,16449 +splashregenextendepot,373,16449 +splashregenerationexpot,373,16449 +splashregenerateexpot,373,16449 +splashregenexpot,373,16449 +splregenerationextendedpotion,373,16449 +splregenerateextendedpotion,373,16449 +splregenextendepotion,373,16449 +splregenerationexpotion,373,16449 +splregenerateexpotion,373,16449 +splregenexpotion,373,16449 +splregenerationextendedpot,373,16449 +splregenerateextendedpot,373,16449 +splregenextendepot,373,16449 +splregenerationexpot,373,16449 +splregenerateexpot,373,16449 +splregenexpot,373,16449 +sprepot,373,16449 +splashswiftnessextendedpotion,373,16450 +splashswiftextendedpotion,373,16450 +splashspeedextendedpotion,373,16450 +splashswiftnessexpotion,373,16450 +splashswiftexpotion,373,16450 +splashspeedexpotion,373,16450 +splashswiftnessextendedpot,373,16450 +splashswiftextendedpot,373,16450 +splashspeedextendedpot,373,16450 +splashswiftnessexpot,373,16450 +splashswiftexpot,373,16450 +splashspeedexpot,373,16450 +splswiftnessextendedpotion,373,16450 +splswiftextendedpotion,373,16450 +splspeedextendedpotion,373,16450 +splswiftnessexpotion,373,16450 +splswiftexpotion,373,16450 +splspeedexpotion,373,16450 +splswiftnessextendedpot,373,16450 +splswiftextendedpot,373,16450 +splspeedextendedpot,373,16450 +splswiftnessexpot,373,16450 +splswiftexpot,373,16450 +splspeedexpot,373,16450 +spswepot,373,16450 +splashfireresistanceextendedpotion,373,16451 +splashfireresistextendedpotion,373,16451 +splashfireresextendedpotion,373,16451 +splashfireresistanceexpotion,373,16451 +splashfireresistexpotion,373,16451 +splashfireresexpotion,373,16451 +splashfireresistanceextendedpot,373,16451 +splashfireresistextendedpot,373,16451 +splashfireresextendedpot,373,16451 +splashfireresistanceexpot,373,16451 +splashfireresistexpot,373,16451 +splashfireresexpot,373,16451 +splfireresistanceextendedpotion,373,16451 +splfireresistextendedpotion,373,16451 +splfireresextendedpotion,373,16451 +splfireresistanceexpotion,373,16451 +splfireresistexpotion,373,16451 +splfireresexpotion,373,16451 +splfireresistanceextendedpot,373,16451 +splfireresistextendedpot,373,16451 +splfireresextendedpot,373,16451 +splfireresistanceexpot,373,16451 +splfireresistexpot,373,16451 +splfireresexpot,373,16451 +spfepot,373,16451 +splashpoisonextendedpotion,373,16452 +splashacidextendedpotion,373,16452 +splashpoisonexpotion,373,16452 +splashacidexpotion,373,16452 +splashpoisonextendedpot,373,16452 +splashacidextendedpot,373,16452 +splashpoisonexpot,373,16452 +splashacidexpot,373,16452 +splpoisonextendedpotion,373,16452 +splacidextendedpotion,373,16452 +splpoisonexpotion,373,16452 +splacidexpotion,373,16452 +splpoisonextendedpot,373,16452 +splacidextendedpot,373,16452 +splpoisonexpot,373,16452 +splacidexpot,373,16452 +sppepot,373,16452 +splashnightvisionextendedpotion,373,16454 +splashnvisionextendedpotion,373,16454 +splashnightvextendedpotion,373,16454 +splashdarkvisionextendedpotion,373,16454 +splashdvisionextendedpotion,373,16454 +splashdarkvextendedpotion,373,16454 +splashnightvisionextendedpot,373,16454 +splashnvisionextendedpot,373,16454 +splashnightvextendedpot,373,16454 +splashdarkvisionextendedpot,373,16454 +splashdvisionextendedpot,373,16454 +splashdarkvextendedpot,373,16454 +splashnightvisionexpotion,373,16454 +splashnvisionexpotion,373,16454 +splashnightvexpotion,373,16454 +splashdarkvisionexpotion,373,16454 +splashdvisionexpotion,373,16454 +splashdarkvexpotion,373,16454 +splashnightvisionexpot,373,16454 +splashnvisionexpot,373,16454 +splashnightvexpot,373,16454 +splashdarkvisionexpot,373,16454 +splashdvisionexpot,373,16454 +splashdarkvexpot,373,16454 +splnightvisionextendedpotion,373,16454 +splnvisionextendedpotion,373,16454 +splnightvextendedpotion,373,16454 +spldarkvisionextendedpotion,373,16454 +spldvisionextendedpotion,373,16454 +spldarkvextendedpotion,373,16454 +splnightvisionextendedpot,373,16454 +splnvisionextendedpot,373,16454 +splnightvextendedpot,373,16454 +spldarkvisionextendedpot,373,16454 +spldvisionextendedpot,373,16454 +spldarkvextendedpot,373,16454 +splnightvisionexpotion,373,16454 +splnvisionexpotion,373,16454 +splnightvexpotion,373,16454 +spldarkvisionexpotion,373,16454 +spldvisionexpotion,373,16454 +spldarkvexpotion,373,16454 +splnightvisionexpot,373,16454 +splnvisionexpot,373,16454 +splnightvexpot,373,16454 +spldarkvisionexpot,373,16454 +spldvisionexpot,373,16454 +spldarkvexpot,373,16454 +spnepot,373,16454 +splashweaknessextendedpotion,373,16456 +splashweakextendedpotion,373,16456 +splashweaknessexpotion,373,16456 +splashweakexpotion,373,16456 +splashweaknessextendedpot,373,16456 +splashweakextendedpot,373,16456 +splashweaknessexpot,373,16456 +splashweakexpot,373,16456 +splweaknessextendedpotion,373,16456 +sphweakextendedpotion,373,16456 +splweaknessexpotion,373,16456 +splweakexpotion,373,16456 +splweaknessextendedpot,373,16456 +splweakextendedpot,373,16456 +splweaknessexpot,373,16456 +splweakexpot,373,16456 +spwepot,373,16456 +splashstrengthextendedpotion,373,16457 +splashstrongextendedpotion,373,16457 +splashstrextendedpotion,373,16457 +splashstrengthexpotion,373,16457 +splashstrongexpotion,373,16457 +splashstrexpotion,373,16457 +splashstrengthextendedpot,373,16457 +splashstrongextendedpot,373,16457 +splashstrextendedpot,373,16457 +splashstrengthexpot,373,16457 +splashstrongexpot,373,16457 +splashstrexpot,373,16457 +splstrengthextendedpotion,373,16457 +splstrongextendedpotion,373,16457 +splstrextendedpotion,373,16457 +splstrengthexpotion,373,16457 +splstrongexpotion,373,16457 +splstrexpotion,373,16457 +splstrengthextendedpot,373,16457 +splstrongextendedpot,373,16457 +splstrextendedpot,373,16457 +splstrengthexpot,373,16457 +splstrongexpot,373,16457 +splstrexpot,373,16457 +spstepot,373,16457 +splashslownessextendedpotion,373,16458 +splashslowextenedpotion,373,16458 +splashslownessexpotion,373,16458 +splashslowexpotion,373,16458 +splashslownessextendedpot,373,16458 +splashslowextenedpot,373,16458 +splashslownessexpot,373,16458 +splashslowexpot,373,16458 +splslownessextendedpotion,373,16458 +splslowextenedpotion,373,16458 +splslownessexpotion,373,16458 +splslowexpotion,373,16458 +splslownessextendedpot,373,16458 +splslowextenedpot,373,16458 +splslownessexpot,373,16458 +splslowexpot,373,16458 +spslepot,373,16458 +splashwaterbreathingextendedpotion,373,16461 +splashwaterbreathextendedpotion,373,16461 +splashbreathingextendedpotion,373,16461 +splashbreathextendedpotion,373,16461 +splashwaterbreathingextendedpot,373,16461 +splashwaterbreathextendedpot,373,16461 +splashbreathingextendedpot,373,16461 +splashbreathextendedpot,373,16461 +splwaterbreathingextendedpotion,373,16461 +splwaterbreathextendedpotion,373,16461 +splbreathingextendedpotion,373,16461 +splbreathextendedpotion,373,16461 +splwaterbreathingextendedpot,373,16461 +splwaterbreathextendedpot,373,16461 +splbreathingextendedpot,373,16461 +splbreathextendedpot,373,16461 +splashwaterbreathingexpotion,373,16461 +splashwaterbreathexpotion,373,16461 +splashbreathingexpotion,373,16461 +splashbreathexpotion,373,16461 +splashwaterbreathingexpot,373,16461 +splashwaterbreathexpot,373,16461 +splashbreathingexpot,373,16461 +splashbreathexpot,373,16461 +splwaterbreathingexpotion,373,16461 +splwaterbreathexpotion,373,16461 +splbreathingexpotion,373,16461 +splbreathexpotion,373,16461 +splwaterbreathingexpot,373,16461 +splwaterbreathexpot,373,16461 +splbreathingexpot,373,16461 +splbreathexpot,373,16461 +spwbepot,373,16461 +splashinvisibilityextendedpotion,373,16462 +splashinvisibleextendedpotion,373,16462 +splashinvextendedpotion,373,16462 +splashinvisibilityextendedpot,373,16462 +splashinvisibleextendedpot,373,16462 +splashinvextendedpot,373,16462 +splashinvisibilityexpotion,373,16462 +splashinvisibleexpotion,373,16462 +splashinvexpotion,373,16462 +splashinvisibilityexpot,373,16462 +splashinvisibleexpot,373,16462 +splashinvexpot,373,16462 +splinvisibilityextendedpotion,373,16462 +splinvisibleextendedpotion,373,16462 +splinvextendedpotion,373,16462 +splinvisibilityextendedpot,373,16462 +splinvisibleextendedpot,373,16462 +splinvextendedpot,373,16462 +splinvisibilityexpotion,373,16462 +splinvisibleexpotion,373,16462 +splinvexpotion,373,16462 +splinvisibilityexpot,373,16462 +splinvisibleexpot,373,16462 +splinvexpot,373,16462 +spiepot,373,16462 +splashregenerationdualbitpotion,373,16481 +splashregeneratedualbitpotion,373,16481 +splashregendualbitpotion,373,16481 +splashregenerationdualbitpot,373,16481 +splashregeneratedualbitpot,373,16481 +splashregendualbitpot,373,16481 +splregenerationdualbitpotion,373,16481 +splregeneratedualbitpotion,373,16481 +splregendualbitpotion,373,16481 +splregenerationdualbitpot,373,16481 +splregeneratedualbitpot,373,16481 +splregendualbitpot,373,16481 +splashregenerationdbpotion,373,16481 +splashregeneratedbpotion,373,16481 +splashregendbpotion,373,16481 +splashregenerationdbpot,373,16481 +splashregeneratedbpot,373,16481 +splashregendbpot,373,16481 +splregenerationdbpotion,373,16481 +splregeneratedbpotion,373,16481 +splregendbpotion,373,16481 +splregenerationdbpot,373,16481 +splregeneratedbpot,373,16481 +splregendbpot,373,16481 +sprdbpot,373,16481 +splashswiftnessdualbitpotion,373,16482 +splashswiftdualbitpotion,373,16482 +splashspeeddualbitpotion,373,16482 +splashswiftnessdualbitpot,373,16482 +splashswiftdualbitpot,373,16482 +splashspeeddualbitpot,373,16482 +splswiftnessdualbitpotion,373,16482 +splswiftdualbitpotion,373,16482 +splspeeddualbitpotion,373,16482 +splswiftnessdualbitpot,373,16482 +splswiftdualbitpot,373,16482 +splspeeddualbitpot,373,16482 +splashswiftnessdbpotion,373,16482 +splashswiftdbpotion,373,16482 +splashspeeddbpotion,373,16482 +splashswiftnessdbpot,373,16482 +splashswiftdbpot,373,16482 +splashspeeddbpot,373,16482 +splswiftnessdbpotion,373,16482 +splswiftdbpotion,373,16482 +splspeeddbpotion,373,16482 +splswiftnessdbpot,373,16482 +splswiftdbpot,373,16482 +splspeeddbpot,373,16482 +spswdbpot,373,16482 +splashpoisondualbitpotion,373,16484 +splashaciddualbitpotion,373,16484 +splashpoisondualbitpot,373,16484 +splashaciddualbitpot,373,16484 +splpoisondualbitpotion,373,16484 +splaciddualbitpotion,373,16484 +splpoisondualbitpot,373,16484 +splaciddualbitpot,373,16484 +splashpoisondbpotion,373,16484 +splashaciddbpotion,373,16484 +splashpoisondbpot,373,16484 +splashaciddbpot,373,16484 +splpoisondbpotion,373,16484 +splaciddbpotion,373,16484 +splpoisondbpot,373,16484 +splaciddbpot,373,16484 +sppdbpot,373,16484 +splashstrengthdualbitpotion,373,16489 +splashstrongdualbitpotion,373,16489 +splashstrdualbitpotion,373,16489 +splashstrengthdualbitpot,373,16489 +splashstrongdualbitpot,373,16489 +splashstrdualbitpot,373,16489 +splstrengthdualbitpotion,373,16489 +splstrongdualbitpotion,373,16489 +splstrdualbitpotion,373,16489 +splstrengthdualbitpot,373,16489 +splstrongdualbitpot,373,16489 +splstrdualbitpot,373,16489 +splashstrengthdbpotion,373,16489 +splashstrongdbpotion,373,16489 +splashstrdbpotion,373,16489 +splashstrengthdbpot,373,16489 +splashstrongdbpot,373,16489 +splashstrdbpot,373,16489 +splstrengthdbpotion,373,16489 +splstrongdbpotion,373,16489 +splstrdbpotion,373,16489 +splstrengthdbpot,373,16489 +splstrongdbpot,373,16489 +splstrdbpot,373,16489 +spstdbpot,373,16489 +glassbottle,374,0 +bottle,374,0 +gbottle,374,0 +gvase,374,0 +vase,374,0 +glassvase,374,0 +emptyglassbottle,374,0 +emptybottle,374,0 +emptygbottle,374,0 +emptygvase,374,0 +emptyvase,374,0 +emptyglassvase,374,0 +eglassbottle,374,0 +ebottle,374,0 +egbottle,374,0 +egvase,374,0 +evase,374,0 +eglassvase,374,0 +spidereye,375,0 +eyeofspider,375,0 +seye,375,0 +fermentedspidereye,376,0 +craftedspidereye,376,0 +fspidereye,376,0 +cspidereye,376,0 +fermentedeyeofspider,376,0 +craftedeyeofspider,376,0 +feyeofspider,376,0 +ceyeofspider,376,0 +fermentedseye,376,0 +craftedseye,376,0 +fseye,376,0 +cseye,376,0 +blazepowder,377,0 +blazedust,377,0 +goldpowder,377,0 +golddust,377,0 +gdust,377,0 +gpowder,377,0 +bpowder,377,0 +bdust,377,0 +magmacream,378,0 +goldcream,378,0 +blazecream,378,0 +mcream,378,0 +gcream,378,0 +bcream,378,0 +combinedcream,378,0 +ccream,378,0 +bstand,379,0 +pstand,379,0 +brewingstand,379,0 +potionstand,379,0 +cauldron,380,0 +steelcauldron,380,0 +ironcauldron,380,0 +icauldron,380,0 +scauldron,380,0 +potioncauldron,380,0 +pcauldron,380,0 +eyeofender,381,0 +endereye,381,0 +endeye,381,0 +evilendereye,381,0 +evileyeofender,381,0 +evilenderpearl,381,0 +eeye,381,0 +eofender,381,0 +glisteringmelon,382,0 +speckledmelon,382,0 +goldmelon,382,0 +sparklymelon,382,0 +shiningmelon,382,0 +gmelon,382,0 +smelon,382,0 +creeperegg,383,50 +eggcreeper,383,50 +skeletonegg,383,51 +eggskeleton,383,51 +spideregg,383,52 +eggspider,383,52 +giantegg,383,53 +egggiant,383,53 +zombieegg,383,54 +eggzombie,383,54 +slimeegg,383,55 +eggslime,383,55 +ghastegg,383,56 +eggghast,383,56 +zombiepigmanegg,383,57 +zpigmanegg,383,57 +pigmanegg,383,57 +zombiepmanegg,383,57 +zpmanegg,383,57 +zombiepigmegg,383,57 +zpigmegg,383,57 +zombiepigegg,383,57 +zpigegg,383,57 +zombiepmegg,383,57 +zombiepegg,383,57 +eggzombiepigman,383,57 +eggzpigman,383,57 +eggpigman,383,57 +eggzombiepman,383,57 +eggzpman,383,57 +eggzombiepigm,383,57 +eggzpigm,383,57 +eggzombiepig,383,57 +eggzpig,383,57 +eggzombiepm,383,57 +eggzombiep,383,57 +endermanegg,383,58 +eggenderman,383,58 +eggcavespider,383,59 +cavespideregg,383,59 +silverfishegg,383,60 +eggsilverfish,383,60 +blazeegg,383,61 +eggblaze,383,61 +lavaslimeegg,383,62 +lavacubeegg,383,62 +magmacubeegg,383,62 +magmaslimeegg,383,62 +egglavaslime,383,62 +egglavacube,383,62 +eggmagmacube,383,62 +eggmagmaslime,383,62 +bategg,383,65 +eggbat,383,65 +witchegg,383,66 +eggwitch,383,66 +pigegg,383,90 +eggpig,383,90 +sheepegg,383,91 +eggsheep,383,91 +cowegg,383,92 +eggcow,383,92 +chickenegg,383,93 +eggchicken,383,93 +squidegg,383,94 +eggsquid,383,94 +wolfegg,383,95 +eggwolf,383,95 +mooshroomegg,383,96 +mushroomcowegg,383,96 +eggmooshroom,383,96 +eggmushroomcow,383,96 +snowgolemegg,383,97 +sgolemegg,383,97 +eggsnowgolem,383,97 +eggsgolem,383,97 +ocelotegg,383,98 +eggocelot,383,98 +irongolemegg,383,99 +igolemegg,383,99 +eggirongolem,383,99 +eggigolem,383,99 +egghorse,383,100 +horseegg,383,100 +villageregg,383,120 +eggvillager,383,120 +bottleofenchanting,384,0 +enchantingbottle,384,0 +expbottle,384,0 +xpbottle,384,0 +bottleexp,384,0 +bottlexp,384,0 +enchantbottle,384,0 +bottleenchanting,384,0 +bottleenchant,384,0 +bottleoenchanting,384,0 +firecharge,385,0 +fireball,385,0 +grenade,385,0 +bookandquill,386,0 +booknquill,386,0 +bookandfeather,386,0 +booknfeather,386,0 +writeablebook,386,0 +writtenbook,387,0 +readablebook,387,0 +sealedbook,387,0 +diary,387,0 +ownedbook,387,0 +emerald,388,0 +itemframe,389,0 +pictureframe,389,0 +iframe,389,0 +pframe,389,0 +flowerpot,390,0 +pot,390,0 +carrot,391,0 +potato,392,0 +rawpotato,392,0 +bakedpotato,393,0 +roastedpotato,393,0 +cookedpotato,393,0 +bakepotato,393,0 +roastpotato,393,0 +cookpotato,393,0 +bpotato,393,0 +rpotato,393,0 +cpotato,393,0 +poisonouspotato,394,0 +poisonpotato,394,0 +ppotato,394,0 +emptymap,395,0 +map,395,0 +goldencarrot,396,0 +goldcarrot,396,0 +gcarrot,396,0 +head,397,0 +skull,397,0 +skeletonhead,397,0 +headskeleton,397,0 +skeletonskull,397,0 +skullskeleton,397,0 +witherhead,397,1 +witherskeletonhead,397,1 +wskeletionhead,397,1 +headwither,397,1 +headwitherskeleton,397,1 +headwskeletion,397,1 +witherskull,397,1 +witherskeletonskull,397,1 +wskeletionskull,397,1 +skullwither,397,1 +skullwitherskeleton,397,1 +skullwskeletion,397,1 +zombiehead,397,2 +headzombie,397,2 +zombieskull,397,2 +skullzombie,397,2 +playerhead,397,3 +humanhead,397,3 +stevehead,397,3 +headplayer,397,3 +headhuman,397,3 +headsteve,397,3 +playerskull,397,3 +humanskull,397,3 +steveskull,397,3 +skullplayer,397,3 +skullhuman,397,3 +skullsteve,397,3 +creeperhead,397,4 +headcreeper,397,4 +creeperskull,397,4 +skullcreeper,397,4 +carrotonastick,398,0 +carrotonstick,398,0 +netherstar,399,0 +hellstar,399,0 +nstar,399,0 +hstar,399,0 +star,399,0 +pumpkinpie,400,0 +pumpkincake,400,0 +ppie,400,0 +pcake,400,0 +pie,400,0 +fireworkrocket,401,0 +fireworkmissle,401,0 +firework,401,0 +fworkrocket,401,0 +fworkmissle,401,0 +fwork,401,0 +fwrocket,401,0 +fwmissle,401,0 +fireworkstar,402,0 +fworkstar,402,0 +fwstar,402,0 +fireworkball,402,0 +fworkball,402,0 +fwball,402,0 +fireworkpowder,402,0 +fworkpowder,402,0 +fwpowder,402,0 +fireworkcharge,402,0 +fworkcharge,402,0 +fwcharge,402,0 +enchantedbook,403,0 +enchantmentbook,403,0 +enchantingbook,403,0 +enchantbook,403,0 +magicalbook,403,0 +magicbook,403,0 +ebook,403,0 +mbook,403,0 +redstonecomparator,404,0 +redstonecomparer,404,0 +redstonecompare,404,0 +rstonecomparator,404,0 +rstonecomparer,404,0 +rstonecompare,404,0 +redscomparator,404,0 +redscomparer,404,0 +redscompare,404,0 +rscomparator,404,0 +rscomparer,404,0 +rscompare,404,0 +comparator,404,0 +comparer,404,0 +compare,404,0 +netherbrick,405,0 +nbrick,405,0 +hellbrick,405,0 +deathbrick,405,0 +dbrick,405,0 +hbrick,405,0 +netherquartz,406,0 +deathquartz,406,0 +hellquartz,406,0 +nquartz,406,0 +dquartz,406,0 +hquartz,406,0 +quartz,406,0 +tntminecart,407,0 +dynamiteminecart,407,0 +dynamitemcart,407,0 +dynamitecart,407,0 +bombminecart,407,0 +bombmcart,407,0 +bombcart,407,0 +tntmcart,407,0 +tntcart,407,0 +dminecart,407,0 +dmcart,407,0 +dcart,407,0 +bminecart,407,0 +bmcart,407,0 +bcart,407,0 +tminecart,407,0 +tmcart,407,0 +tcart,407,0 +hopperminecart,408,0 +hoppermcart,408,0 +hoppercart,408,0 +hopminecart,408,0 +hopmcart,408,0 +hopcart,408,0 +hminecart,408,0 +hmcart,408,0 +hcart,408,0 +ironhorsearmor,417,0 +ironharmor,417,0 +ironarmor,417,0 +ihorsearmor,417,0 +iharmor,417,0 +iarmor,417,0 +steelhorsearmor,417,0 +steelharmor,417,0 +steelarmor,417,0 +shorsearmor,417,0 +sharmor,417,0 +sarmor,417,0 +goldenhorsearmor,418,0 +goldenharmor,418,0 +goldenarmor,418,0 +goldhorsearmor,418,0 +goldharmor,418,0 +goldarmor,418,0 +ghorsearmor,418,0 +gharmor,418,0 +garmor,418,0 +diamondhorsearmor,419,0 +diamondharmor,419,0 +diamondarmor,419,0 +dhorsearmor,419,0 +dharmor,419,0 +darmor,419,0 +crystalhorsearmor,419,0 +crystalharmor,419,0 +crystalarmor,419,0 +chorsearmor,419,0 +charmor,419,0 +carmor,419,0 +lead,420,0 +leash,420,0 +rope,420,0 +nametag,421,0 +tag,421,0 +commandblockminecart,422,0 +cmdblockminecart,422,0 +cblockminecart,422,0 +commandminecart,422,0 +cmdminecart,422,0 +cbminecart,422,0 +commandblockcart,422,0 +cmdblockcart,422,0 +cblockcart,422,0 +commandcart,422,0 +cmdcart,422,0 +cbcart,422,0 +13disc,2256,0 +goldmusicrecord,2256,0 +goldmusicdisk,2256,0 +goldmusicdisc,2256,0 +goldmusiccd,2256,0 +13musicrecord,2256,0 +13musicdisk,2256,0 +13musicdisc,2256,0 +13musiccd,2256,0 +gomusicrecord,2256,0 +gomusicdisk,2256,0 +gomusicdisc,2256,0 +gomusiccd,2256,0 +goldmrecord,2256,0 +goldmdisk,2256,0 +goldmdisc,2256,0 +goldmcd,2256,0 +13mrecord,2256,0 +13mdisk,2256,0 +13mdisc,2256,0 +13mcd,2256,0 +gomrecord,2256,0 +gomdisk,2256,0 +gomdisc,2256,0 +gomcd,2256,0 +goldrecord,2256,0 +golddisk,2256,0 +golddisc,2256,0 +goldcd,2256,0 +13record,2256,0 +13disk,2256,0 +13cd,2256,0 +gorecord,2256,0 +godisk,2256,0 +godisc,2256,0 +gocd,2256,0 +record1,2256,0 +disk1,2256,0 +disc1,2256,0 +cd1,2256,0 +1record,2256,0 +1disk,2256,0 +1disc,2256,0 +1cd,2256,0 +catdisc,2257,0 +greenmusicrecord,2257,0 +greenmusicdisk,2257,0 +greenmusicdisc,2257,0 +greenmusiccd,2257,0 +catmusicrecord,2257,0 +catmusicdisk,2257,0 +catmusicdisc,2257,0 +catmusiccd,2257,0 +grmusicrecord,2257,0 +grmusicdisk,2257,0 +grmusicdisc,2257,0 +grmusiccd,2257,0 +greenmrecord,2257,0 +greenmdisk,2257,0 +greenmdisc,2257,0 +greenmcd,2257,0 +catmrecord,2257,0 +catmdisk,2257,0 +catmdisc,2257,0 +catmcd,2257,0 +grmrecord,2257,0 +grmdisk,2257,0 +grmdisc,2257,0 +grmcd,2257,0 +greenrecord,2257,0 +greendisk,2257,0 +greendisc,2257,0 +greencd,2257,0 +catrecord,2257,0 +catdisk,2257,0 +catcd,2257,0 +grrecord,2257,0 +grdisk,2257,0 +grdisc,2257,0 +grcd,2257,0 +record2,2257,0 +disk2,2257,0 +disc2,2257,0 +cd2,2257,0 +2record,2257,0 +2disk,2257,0 +2disc,2257,0 +2cd,2257,0 +blocksdisc,2258,0 +orangemusicrecord,2258,0 +orangemusicdisk,2258,0 +orangemusicdisc,2258,0 +orangemusiccd,2258,0 +blocksmusicrecord,2258,0 +blocksmusicdisk,2258,0 +blocksmusicdisc,2258,0 +blocksmusiccd,2258,0 +ormusicrecord,2258,0 +ormusicdisk,2258,0 +ormusicdisc,2258,0 +ormusiccd,2258,0 +orangemrecord,2258,0 +orangemdisk,2258,0 +orangemdisc,2258,0 +orangemcd,2258,0 +blocksmrecord,2258,0 +blocksmdisk,2258,0 +blocksmdisc,2258,0 +blocksmcd,2258,0 +ormrecord,2258,0 +ormdisk,2258,0 +ormdisc,2258,0 +ormcd,2258,0 +orangerecord,2258,0 +orangedisk,2258,0 +orangedisc,2258,0 +orangecd,2258,0 +blocksrecord,2258,0 +blocksdisk,2258,0 +blockscd,2258,0 +orrecord,2258,0 +ordisk,2258,0 +ordisc,2258,0 +orcd,2258,0 +record3,2258,0 +disk3,2258,0 +disc3,2258,0 +cd3,2258,0 +3record,2258,0 +3disk,2258,0 +3disc,2258,0 +3cd,2258,0 +chirpdisc,2259,0 +redmusicrecord,2259,0 +redmusicdisk,2259,0 +redmusicdisc,2259,0 +redmusiccd,2259,0 +chirpmusicrecord,2259,0 +chirpmusicdisk,2259,0 +chirpmusicdisc,2259,0 +chirpmusiccd,2259,0 +remusicrecord,2259,0 +remusicdisk,2259,0 +remusicdisc,2259,0 +remusiccd,2259,0 +redmrecord,2259,0 +redmdisk,2259,0 +redmdisc,2259,0 +redmcd,2259,0 +chirpmrecord,2259,0 +chirpmdisk,2259,0 +chirpmdisc,2259,0 +chirpmcd,2259,0 +remrecord,2259,0 +remdisk,2259,0 +remdisc,2259,0 +remcd,2259,0 +redrecord,2259,0 +reddisk,2259,0 +reddisc,2259,0 +redcd,2259,0 +chirprecord,2259,0 +chirpdisk,2259,0 +chirpcd,2259,0 +rerecord,2259,0 +redisk,2259,0 +redisc,2259,0 +recd,2259,0 +record4,2259,0 +disk4,2259,0 +disc4,2259,0 +cd4,2259,0 +4record,2259,0 +4disk,2259,0 +4disc,2259,0 +4cd,2259,0 +fardisc,2260,0 +lightgreenmusicrecord,2260,0 +lightgreenmusicdisk,2260,0 +lightgreenmusicdisc,2260,0 +lightgreenmusiccd,2260,0 +lgreenmusicrecord,2260,0 +lgreenmusicdisk,2260,0 +lgreenmusicdisc,2260,0 +lgreenmusiccd,2260,0 +lightgrmusicrecord,2260,0 +lightgrmusicdisk,2260,0 +lightgrmusicdisc,2260,0 +lightgrmusiccd,2260,0 +farmusicrecord,2260,0 +farmusicdisk,2260,0 +farmusicdisc,2260,0 +farmusiccd,2260,0 +lgrmusicrecord,2260,0 +lgrmusicdisk,2260,0 +lgrmusicdisc,2260,0 +lgrmusiccd,2260,0 +lightgreenmrecord,2260,0 +lightgreenmdisk,2260,0 +lightgreenmdisc,2260,0 +lightgreenmcd,2260,0 +lgreenmrecord,2260,0 +lgreenmdisk,2260,0 +lgreenmdisc,2260,0 +lgreenmcd,2260,0 +lightgrmrecord,2260,0 +lightgrmdisk,2260,0 +lightgrmdisc,2260,0 +lightgrmcd,2260,0 +farmrecord,2260,0 +farmdisk,2260,0 +farmdisc,2260,0 +farmcd,2260,0 +lgrmrecord,2260,0 +lgrmdisk,2260,0 +lgrmdisc,2260,0 +lgrmcd,2260,0 +lightgreenrecord,2260,0 +lightgreendisk,2260,0 +lightgreendisc,2260,0 +lightgreencd,2260,0 +lgreenrecord,2260,0 +lgreendisk,2260,0 +lgreendisc,2260,0 +lgreencd,2260,0 +lightgrrecord,2260,0 +lightgrdisk,2260,0 +lightgrdisc,2260,0 +lightgrcd,2260,0 +farrecord,2260,0 +fardisk,2260,0 +farcd,2260,0 +lgrrecord,2260,0 +lgrdisk,2260,0 +lgrdisc,2260,0 +lgrcd,2260,0 +record5,2260,0 +disk5,2260,0 +disc5,2260,0 +cd5,2260,0 +5record,2260,0 +5disk,2260,0 +5disc,2260,0 +5cd,2260,0 +malldisc,2261,0 +purplemusicrecord,2261,0 +purplemusicdisk,2261,0 +purplemusicdisc,2261,0 +purplemusiccd,2261,0 +mallmusicrecord,2261,0 +mallmusicdisk,2261,0 +mallmusicdisc,2261,0 +mallmusiccd,2261,0 +pumusicrecord,2261,0 +pumusicdisk,2261,0 +pumusicdisc,2261,0 +pumusiccd,2261,0 +purplemrecord,2261,0 +purplemdisk,2261,0 +purplemdisc,2261,0 +purplemcd,2261,0 +mallmrecord,2261,0 +mallmdisk,2261,0 +mallmdisc,2261,0 +mallmcd,2261,0 +pumrecord,2261,0 +pumdisk,2261,0 +pumdisc,2261,0 +pumcd,2261,0 +purplerecord,2261,0 +purpledisk,2261,0 +purpledisc,2261,0 +purplecd,2261,0 +mallrecord,2261,0 +malldisk,2261,0 +mallcd,2261,0 +purecord,2261,0 +pudisk,2261,0 +pudisc,2261,0 +pucd,2261,0 +record6,2261,0 +disk6,2261,0 +disc6,2261,0 +cd6,2261,0 +6record,2261,0 +6disk,2261,0 +6disc,2261,0 +6cd,2261,0 +mellohidisc,2262,0 +pinkmusicrecord,2262,0 +pinkmusicdisk,2262,0 +pinkmusicdisc,2262,0 +pinkmusiccd,2262,0 +mellohimusicrecord,2262,0 +mellohimusicdisk,2262,0 +mellohimusicdisc,2262,0 +mellohimusiccd,2262,0 +pimusicrecord,2262,0 +pimusicdisk,2262,0 +pimusicdisc,2262,0 +pimusiccd,2262,0 +pinkmrecord,2262,0 +pinkmdisk,2262,0 +pinkmdisc,2262,0 +pinkmcd,2262,0 +mellohimrecord,2262,0 +mellohimdisk,2262,0 +mellohimdisc,2262,0 +mellohimcd,2262,0 +pimrecord,2262,0 +pimdisk,2262,0 +pimdisc,2262,0 +pimcd,2262,0 +pinkrecord,2262,0 +pinkdisk,2262,0 +pinkdisc,2262,0 +pinkcd,2262,0 +mellohirecord,2262,0 +mellohidisk,2262,0 +mellohicd,2262,0 +pirecord,2262,0 +pidisk,2262,0 +pidisc,2262,0 +picd,2262,0 +record7,2262,0 +disk7,2262,0 +disc7,2262,0 +cd7,2262,0 +7record,2262,0 +7disk,2262,0 +7disc,2262,0 +7cd,2262,0 +staldisc,2263,0 +blackmusicrecord,2263,0 +blackmusicdisk,2263,0 +blackmusicdisc,2263,0 +blackmusiccd,2263,0 +stalmusicrecord,2263,0 +stalmusicdisk,2263,0 +stalmusicdisc,2263,0 +stalmusiccd,2263,0 +blmusicrecord,2263,0 +blmusicdisk,2263,0 +blmusicdisc,2263,0 +blmusiccd,2263,0 +blackmrecord,2263,0 +blackmdisk,2263,0 +blackmdisc,2263,0 +blackmcd,2263,0 +stalmrecord,2263,0 +stalmdisk,2263,0 +stalmdisc,2263,0 +stalmcd,2263,0 +blmrecord,2263,0 +blmdisk,2263,0 +blmdisc,2263,0 +blmcd,2263,0 +blackrecord,2263,0 +blackdisk,2263,0 +blackdisc,2263,0 +blackcd,2263,0 +stalrecord,2263,0 +staldisk,2263,0 +stalcd,2263,0 +blrecord,2263,0 +bldisk,2263,0 +bldisc,2263,0 +blcd,2263,0 +record8,2263,0 +disk8,2263,0 +disc8,2263,0 +cd8,2263,0 +8record,2263,0 +8disk,2263,0 +8disc,2263,0 +8cd,2263,0 +straddisc,2264,0 +whitemusicrecord,2264,0 +whitemusicdisk,2264,0 +whitemusicdisc,2264,0 +whitemusiccd,2264,0 +stradmusicrecord,2264,0 +stradmusicdisk,2264,0 +stradmusicdisc,2264,0 +stradmusiccd,2264,0 +whmusicrecord,2264,0 +whmusicdisk,2264,0 +whmusicdisc,2264,0 +whmusiccd,2264,0 +whitemrecord,2264,0 +whitemdisk,2264,0 +whitemdisc,2264,0 +whitemcd,2264,0 +stradmrecord,2264,0 +stradmdisk,2264,0 +stradmdisc,2264,0 +stradmcd,2264,0 +whmrecord,2264,0 +whmdisk,2264,0 +whmdisc,2264,0 +whmcd,2264,0 +whiterecord,2264,0 +whitedisk,2264,0 +whitedisc,2264,0 +whitecd,2264,0 +stradrecord,2264,0 +straddisk,2264,0 +stradcd,2264,0 +whrecord,2264,0 +whdisk,2264,0 +whdisc,2264,0 +whcd,2264,0 +record9,2264,0 +disk9,2264,0 +disc9,2264,0 +cd9,2264,0 +9record,2264,0 +9disk,2264,0 +9disc,2264,0 +9cd,2264,0 +warddisc,2265,0 +darkgreenmusicrecord,2265,0 +darkgreenmusicdisk,2265,0 +darkgreenmusicdisc,2265,0 +darkgreenmusiccd,2265,0 +dgreenmusicrecord,2265,0 +dgreenmusicdisk,2265,0 +dgreenmusicdisc,2265,0 +dgreenmusiccd,2265,0 +darkgrmusicrecord,2265,0 +darkgrmusicdisk,2265,0 +darkgrmusicdisc,2265,0 +darkgrmusiccd,2265,0 +wardmusicrecord,2265,0 +wardmusicdisk,2265,0 +wardmusicdisc,2265,0 +wardmusiccd,2265,0 +dgrmusicrecord,2265,0 +dgrmusicdisk,2265,0 +dgrmusicdisc,2265,0 +dgrmusiccd,2265,0 +darkgreenmrecord,2265,0 +darkgreenmdisk,2265,0 +darkgreenmdisc,2265,0 +darkgreenmcd,2265,0 +dgreenmrecord,2265,0 +dgreenmdisk,2265,0 +dgreenmdisc,2265,0 +dgreenmcd,2265,0 +darkgrmrecord,2265,0 +darkgrmdisk,2265,0 +darkgrmdisc,2265,0 +darkgrmcd,2265,0 +wardmrecord,2265,0 +wardmdisk,2265,0 +wardmdisc,2265,0 +wardmcd,2265,0 +dgrmrecord,2265,0 +dgrmdisk,2265,0 +dgrmdisc,2265,0 +dgrmcd,2265,0 +darkgreenrecord,2265,0 +darkgreendisk,2265,0 +darkgreendisc,2265,0 +darkgreencd,2265,0 +dgreenrecord,2265,0 +dgreendisk,2265,0 +dgreendisc,2265,0 +dgreencd,2265,0 +darkgrrecord,2265,0 +darkgrdisk,2265,0 +darkgrdisc,2265,0 +darkgrcd,2265,0 +wardrecord,2265,0 +warddisk,2265,0 +wardcd,2265,0 +dgrrecord,2265,0 +dgrdisk,2265,0 +dgrdisc,2265,0 +dgrcd,2265,0 +record10,2265,0 +disk10,2265,0 +disc10,2265,0 +cd10,2265,0 +10record,2265,0 +10disk,2265,0 +10disc,2265,0 +10cd,2265,0 +11disc,2266,0 +crackedmusicrecord,2266,0 +crackedmusicdisk,2266,0 +crackedmusicdisc,2266,0 +crackedmusiccd,2266,0 +crackmusicrecord,2266,0 +crackmusicdisk,2266,0 +crackmusicdisc,2266,0 +crackmusiccd,2266,0 +11musicrecord,2266,0 +11musicdisk,2266,0 +11musicdisc,2266,0 +11musiccd,2266,0 +cmusicrecord,2266,0 +cmusicdisk,2266,0 +cmusicdisc,2266,0 +cmusiccd,2266,0 +crackedmrecord,2266,0 +crackedmdisk,2266,0 +crackedmdisc,2266,0 +crackedmcd,2266,0 +crackmrecord,2266,0 +crackmdisk,2266,0 +crackmdisc,2266,0 +crackmcd,2266,0 +11mrecord,2266,0 +11mdisk,2266,0 +11mdisc,2266,0 +11mcd,2266,0 +cmrecord,2266,0 +cmdisk,2266,0 +cmdisc,2266,0 +cmcd,2266,0 +crackedrecord,2266,0 +crackeddisk,2266,0 +crackeddisc,2266,0 +crackedcd,2266,0 +crackrecord,2266,0 +crackdisk,2266,0 +crackdisc,2266,0 +crackcd,2266,0 +crecord,2266,0 +cdisk,2266,0 +cdisc,2266,0 +ccd,2266,0 +record11,2266,0 +disk11,2266,0 +disc11,2266,0 +cd11,2266,0 +11record,2266,0 +11disk,2266,0 +11cd,2266,0 +waitdisc,2267,0 +waitmusicrecord,2267,0 +waitmusicdisk,2267,0 +waitmusicdisc,2267,0 +waitmusiccd,2267,0 +bluemusicrecord,2267,0 +bluemusicdisk,2267,0 +bluemusicdisc,2267,0 +bluemusiccd,2267,0 +12musicrecord,2267,0 +12musicdisk,2267,0 +12musicdisc,2267,0 +12musiccd,2267,0 +cyanmusicrecord,2267,0 +cyanmusicdisk,2267,0 +cyanmusicdisc,2267,0 +cyanmusiccd,2267,0 +waitmrecord,2267,0 +waitmdisk,2267,0 +waitmdisc,2267,0 +waitmcd,2267,0 +bluemrecord,2267,0 +bluemdisk,2267,0 +bluemdisc,2267,0 +bluemcd,2267,0 +12mrecord,2267,0 +12mdisk,2267,0 +12mdisc,2267,0 +12mcd,2267,0 +cyanmrecord,2267,0 +cyanmdisk,2267,0 +cyanmdisc,2267,0 +cyanmcd,2267,0 +waitrecord,2267,0 +waitdisk,2267,0 +waitcd,2267,0 +bluerecord,2267,0 +bluedisk,2267,0 +bluedisc,2267,0 +bluecd,2267,0 +cyanrecord,2267,0 +cyandisk,2267,0 +cyandisc,2267,0 +cyancd,2267,0 +record12,2267,0 +disk12,2267,0 +disc12,2267,0 +cd12,2267,0 +12record,2267,0 +12disk,2267,0 +12disc,2267,0 +12cd,2267,0 +#9024e88d64262f1c5ea92df8399fa658 \ No newline at end of file diff --git a/bin/lives.yml b/bin/lives.yml new file mode 100644 index 0000000..04ec367 --- /dev/null +++ b/bin/lives.yml @@ -0,0 +1 @@ +lives: {} diff --git a/bin/locale.yml b/bin/locale.yml new file mode 100644 index 0000000..619f9fe --- /dev/null +++ b/bin/locale.yml @@ -0,0 +1,107 @@ +player_only: "&cOnly players may use that!" +no_permission: "&cNo permission." +player_unfound: "&e{0}&4 could not be found" +enabled: "&aEnabled" +disabled: "&cDisabled" +able: "&aAble" +unable: "&cUnable" +inventoryFull: "&cYou must clear your inventory first!" +notNumber: "&e{0} is not a number!" +angle_message: "&e{0} yaw&f, &e{1} pitch" +revive_cooldown: "&4You may not revive a player for another &e{0}4." +not_dead: "&e{0} &eis not deathbanned" +revived: "&aYou have revived &e{0}&a!" +revive_player: "&cYou revived {0}!" +revive_broadcast: "&c{0} revived {1}!" +selectEndPortal: "&cYou must select an end portal frame!" +locationSuccess: "&aSet location {0}" +firstLocationUnset: "&cYou must set the first location!" +portalTooBig: "&cYou cannot create a portal that big!" +portalElevation: "&cMake sure the portal is on the same elevation!" +portalSuccess: "&aCreated portal." +portalWandGive: "&aSelect 2 points to make an end portal" +noCooldown: "&4You do not have a Gopple cooldown active." +activeCooldown: "&eYour Gopple cooldown expires in {0}" +helpMenu: + - "&aThis is" + - "&aThe help menu" +userLocation: "&e{0}&a is in the area of {1} at coordinates: {2},{3},{4}" +logoutActive: "&aYour logout timer is already active!" +logoutStart: "&aYour logout timer is now active!" +pvpTimerNotActive: "&cYour {0} timer is currently not active." +pvpTimerDeactivate: "&cYour {0} timer has now been deactivated!" +pvpTimerActive: "&aYour {0} timer is still active for another {1}" +notInFaction: "&cYou are not in a faction!" +fullDTR: "&aYour faction has full DTR." +frozenDTR: "&aYour faction DTR is frozen for another {0}" +regeneratingDTR: "&aYour faction currently has {0} DTR and is regenerating at a rate of {1} every {2}. Estimated time until full DTR is {3}." +serverTime: "&aThe server time is {0}" +cannonOnlyOverworld: "&aYou can only " +toggleCapZoneMessages: "&eYou are now {0} to see cap zone entry messages" +toggleFDMessages: "&e{0} &ahas toggled &bFound Diamond Alerts" +toggleLSMessages: "&eYou will now be {0} to see Lightning Strikes on player deaths" + +# Scoreboard toggle +toggleScoreboard: "&eYou have now {0} your scoreboard" + +# Lives and deathban messages +noLivesInDB: "&eThere are no lives in the database!" +eotwDeathBanJoin: "&cYou are deathbanned for the rest of the map due to EOTW." +deathbanTimer: "&cYou are still deathbanned for {0}" +lifeUsed: "&aYou have used a life! You now have {0} lives." +noLives: "&cYou have no lives!" +deathbanWithLives: "&cYou are still deathbanned with {0} remaining! You can use a life by joining within {1}" +deathbanBypass: "&aYou would be deathbanned, but you have permission to bypass." +playerLifeCheck: "&e{0} currently has {1} lives" +notDeathbanned: "&e{0} is not deathbanned!" +deathbanReason: + - "&eDeathban caused by {0}" + - "&eTime: {1}" + - "&eDuration: {2}" +deathbanLocation: "&eLocation: ({0},{1},{2})" +deathbanReason: "&eReason: [{0}]" +clearDeathbanMessaage: "&eAll deathbans have been cleared" +livesMustBePositive: "&cThe amount of lives must be positive" +livesGiftFailure: "&cYou could not give {0} {1} live(s) because you only have {2}." +livesGiftSuccess: "&aYou gifted {0} with {1} live(s)" +livesGiftSuccessPlayer: "&e{0} gifted you with {1} live(s)" +livesReviveKitmap: "&eYou cannot revive players during kitmap!" +livesReviveEOTW: "&eYou cannot revive players during EOTW!" +lifeUsedOnOther: "&eYou have used a life to revive {0}" +livesConsoleRevive: "&eYou have revived {0}" +livesSet: "&e{0} now has {1} lives." +deathbanDurationError: "&cInvalid duration! Use format &o1h 2m" +deathbanDurationSet: "&eDeathban time has now been set to {0}!" +topLivesTitle: "&eTop {0} lives:" +topLivesFormat: "&e{0} {1}: {2}" +ecoGiveAll: "&e{0} gave all players ${1}" +ecoBalance: "&eYour balance: {0}" +ecoBalanceOther: "&e{0}'s balance: {1}" +ecoAdded: "&eAdded {0} to {1}'s balance. Their new balance is {2}" +ecoTaken: "&eTaken {0} from {1}'s balance. Their new balance is {2}" +ecoSet: "&eSet balance of {0} to {1}" +ecoNotPositive: "&cYou must send money in positive amounts." +ecoSendFailure: "&cYou tried to pay {0}, but you only have {1} in your account." +ecoSendSuccess: "&aYou have sent {0} to {1}" +ecoSendSuccessPlayer: "&a{0} sent you {1}" +notPlayerFaction: "&cThat faction could not be found or is not a player faction." +noEvents: "&cThere are no running events!" +eventCancelled: "&c{0} has cancelled the event {1}" +eventCreateNameUsed: "&cThere is already an event faction named {0}" +eventCreateSuccess: "&aCreated event faction {0} with event type {1}!" +eventDeleteNameUnused: "&cThere is no such event faction called {0}" +eventDeleteSuccess: "&aDeleted event faction {0}!" +eventRenameSuccess: "&aRenamed event {0} to {1}" +noWorldEdit: "&cYou need WorldEdit installed to use this feature!" +requireWorldEditSelection: "&cPlease make a WorldEdit selection!" +areaTooSmall: "&cRegion selection must be {0} x {0}" +eventAreaSuccess: "&aUpdated the claim area for event {0}" +eventStarted: "&aEvent has been started!" +eventUptime: "&aEvent &e({0})&a has been live for &e{1}&a and started at &e{2}" +conquestSetPointsError: "&cMaximum points for Conquest is {0}" +conquestSetPoints: "&aSet points for {0} to {1}" +noKeyFound: "&cNo key type named {0}" +keyOnlyPositive: "&cYou can only give keys in positive quantities" +keyMaximumAllowed: "&cYou cannot give keys in more than {0}'s" +keyGiven: "&cGiven {0}x {1} key to {2}" +crateClosedDuring: "&aYou closed your crate reward inventory, dropping your items on the ground!" \ No newline at end of file diff --git a/bin/plugin.yml b/bin/plugin.yml new file mode 100644 index 0000000..67eb09f --- /dev/null +++ b/bin/plugin.yml @@ -0,0 +1,130 @@ +name: Zorex +version: 1.0 +description: HCF CORE +author: bruceboy +main: me.bruce.factions.LorexHCF +softdepend: [ProtocolLib] +commands: + hcf: + rawcast: + wb: + nv: + stats: + setnpc: + staffguide: + tablistgui: + aliases: [tabgui] + coords: + pots: + vanish: + aliases: [v] + staffgui: + author: + aliases: [dev,developer,best,bestdev] + gamemode: + aliases: [gm] + setprefix: + slowchat: + disablechat: + tp: + here: + fly: + fix: + invsee: + randomtp: + panic: + tl: + baller: + rules: + vip: + zorex: + spawn: + lff: + pro: + prefix: + keysale: + sp: + fr: + reboot: + rank: + broadcast: + aliases: [bc] + buy: + tablist: + aliases: [pot] + settings: + refund: + aliases: [inv, restore, invrestore] + ping: + freeze: + aliases: [ss] + enderdragon: + hub: + this: + playtime: + aliases: [pt] + cobble: + crowgive: + aliases: [crowbar, crowbargive] + Amethyst: + hcfhelp: + aliases: [help, ehelp, pl, ?] + conquest: + description: Command used to handle Conquest events. + economy: + aliases: [$, bal, money, eco, econ] + description: Command used to modify the economy. + eotw: + aliases: [endoftheworld] + description: Sets if the server is in End of the World mode. + event: + description: Command used to manage minigame events. + faction: + aliases: [f, fac] + description: Faction related commands. + gopple: + description: Command to check remaining OP apple cooldown time. + aliases: [opple, goppletimer, goppletime, oppletimer, oppletime] + hcf: + aliases: [hardcorefactions, hcfactions] + koth: + description: Make or delete KotH arenas. + lives: + description: Management of lives or deathbans. + location: + aliases: [loc] + description: Check the faction location of a player. + logout: + aliases: [disconnect] + description: Command to safely logout without an NPC spawning. + mapkit: + aliases: [viewkit] + description: Used to check the current map restrictions. + pay: + aliases: [p2p] + description: Allow players to pay money. + pvptimer: + aliases: [pvp] + description: Command to enable or disable pvp timer protection. + regen: + description: Check ETA until a faction is able to regenerate DTR. + sotw: + aliases: [startoftheworld] + description: Command used to manage start of the world. + staffrevive: + aliases: [revive] + description: Command used by staff to revive players. + timer: + description: Command to manage timers. + togglecapzoneentry: + aliases: [togglecapentry] + description: Command used to hide or show capture zone entry messages. + togglelightning: + aliases: [lightningtoggle, togglestrikes] + description: Toggles the lightning strikes for when a player dies. + rename: + ores: + description: See ores mined. + aliases: [stats, mined] + glowstonemountain: + aliases: [reset] \ No newline at end of file diff --git a/bin/settings.yml b/bin/settings.yml new file mode 100644 index 0000000..4bb0deb --- /dev/null +++ b/bin/settings.yml @@ -0,0 +1,75 @@ +disable_obsidian_generators: true +server_time_zone: EST +warzone_radius: 650 +donate_url: store.Vengeful.us +spawn_buffer: 128 +map_number: 1 +disallowed_faction_names: +- Venge +- Vengeful +enchantment_limits: + PROTECTION_ENVIRONMENTAL: 2 + DAMAGE_ALL: 1 + ARROW_KNOCKBACK: 0 + KNOCKBACK: 0 + FIRE_ASPECT: 0 + THORNS: 0 + ARROW_FIRE: 1 + ARROW_DAMAGE: 3 +potion_limits: + STRENGTH: 1 + WEAKNESS: 0 + SLOWNESS: 0 + INVISIBILITY: 0 + POISON: 0 +road_lengths: + NORMAL: 4000 + NETHER: 4000 +border_sizes: + NORMAL: 2000 + NETHER: 2000 + THE_END: 1500 +spawn_radius_map: + NORMAL: 50 + NETHER: 25 + THE_END: 15 +diamond_ore_alerts: false +subclaim_name_characters_min: 3 +subclaim_name_characters_max: 16 +faction_name_characters_min: 3 +faction_name_characters_max: 16 +max_members_per_faction: 8 +road_distance: 2500 +road_min_height: 0 +road_max_height: 256 +end_portal_radius: 20 +end_portal_center: 750 +default_deathban_duration: 3600000 +kit_map: true +#Tablist is currently weird for 1.8 users use if you want +tablist: false +teammate_colour: DARK_GREEN +ally_colour: LIGHT_PURPLE +enemy_colour: RED +safezone_colour: AQUA +road_colour: GOLD +warzone_colour: RED +wilderness_colour: GREEN +scoreboard_title: '(Speed)' +max_allies_per_faction: 0 +max_claims_per_faction: 8 +allow_claiming_besides_roads: false +dtr_millis_between_updates: 45000 +dtr_increment_between_updates: 0.1 +maximum_dtr: 6.0 +exp_multiplier_general: 2.0 +exp_multiplier_fishing: 2.0 +exp_multiplier_smelting: 2.0 +exp_multiplier_looting_per_level: 6.0 +exp_multiplier_luck_per_level: 1.5 +exp_multiplier_fortune_per_level: 1.5 +conquest_point_loss_per_death: 30 +conquest_required_win_points: 300 +found_diamonds_alerts: true +combat_log_despawn_ticks: 600 +combat_log_prevention_enabled: true diff --git a/bin/timers.yml b/bin/timers.yml new file mode 100644 index 0000000..e69de29 diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..65a5faf --- /dev/null +++ b/config.yml @@ -0,0 +1,87 @@ +death-signs: true +diamond-ore-notifications: true +death-lightning: true +map-number: 1 +kit-map: true +prevent-ally-damage: true +exp-multiplier: + global: 2.0 + fishing: 2.0 + smelting: 2.0 + looting-per-level: 1.5 + luck-per-level: 1.5 + fortune-per-level: 1.5 +roads: + allow-claims-besides: true +scoreboard: + sidebar: + title: "" + enabled: true + nametags: + enabled: true +combatlog: + enabled: true + despawn-delay-ticks: 600 +conquest: + point-loss-per-death: 20 + victory-points: 300 + allow-negative-points: true +warzone: + radius: 1000 +factions: + disallowed-faction-names: + - EOTW + min-name-characters: 3 + max-name-characters: 16 + max-members: 25 + max-allies: 1 +subclaims: + min-name-characters: 3 + max-name-characters: 16 +relation-colours: + wilderness: DARK_GREEN + warzone: LIGHT_PURPLE + teammate: GREEN + ally: GOLD + enemy: RED + road: GOLD +deaths-till-raidable: + maximum: 6 + millis-between-updates: 45000 + increment-between-updates: 0.1 +deathban: + base-duration-minutes: 120 + respawn-screen-seconds-before-kick: 15 +enchantment-limits: + PROTECTION_ENVIRONMENTAL: 3 + PROTECTION_FIRE: 3 + SILK_TOUCH: 1 + DURABILITY: 3 + PROTECTION_EXPLOSIONS: 3 + LOOT_BONUS_BLOCKS: 3 + PROTECTION_PROJECTILE: 3 + OXYGEN: 3 + WATER_WORKER: 1 + THORNS: 0 + DAMAGE_ALL: 3 + ARROW_KNOCKBACK: 1 + KNOCKBACK: 1 + FIRE_ASPECT: 1 + LOOT_BONUS_MOBS: 3 + LUCK: 3 + LURE: 3 +end: + open: true + exit: world,0.5,75,0.5,0,0 +eotw: + chat-symbol-prefix: "" + chat-symbol-suffix: "" + last-map-cappers: [] +potion-limits: + STRENGTH: 0 + INVISIBILITY: 0 + REGEN: 0 + WEAKNESS: 0 + INSTANT_DAMAGE: 0 + SLOWNESS: 1 + POISON: 1 diff --git a/coords.txt b/coords.txt new file mode 100644 index 0000000..e69de29 diff --git a/enderdragon-art-old.png b/enderdragon-art-old.png new file mode 100644 index 0000000..e33ffd6 Binary files /dev/null and b/enderdragon-art-old.png differ diff --git a/enderdragon-art.png b/enderdragon-art.png new file mode 100644 index 0000000..31c18b3 Binary files /dev/null and b/enderdragon-art.png differ diff --git a/event-schedules.txt b/event-schedules.txt new file mode 100644 index 0000000..3ee09a6 --- /dev/null +++ b/event-schedules.txt @@ -0,0 +1,2 @@ +# year, month, day, hour, minute: eventName (24 hour clock) +# 2015,1,1,2,0:Example This would run event named 'Example' at 2AM on the 1st of January, 2015. diff --git a/faction-users.yml b/faction-users.yml new file mode 100644 index 0000000..bf82e98 --- /dev/null +++ b/faction-users.yml @@ -0,0 +1 @@ +users: {} diff --git a/factions.yml b/factions.yml new file mode 100644 index 0000000..10bc293 --- /dev/null +++ b/factions.yml @@ -0,0 +1 @@ +factions: {} diff --git a/gopple-art.png b/gopple-art.png new file mode 100644 index 0000000..08c061a Binary files /dev/null and b/gopple-art.png differ diff --git a/help.txt b/help.txt new file mode 100644 index 0000000..e69de29 diff --git a/items.csv b/items.csv new file mode 100644 index 0000000..49dd25c --- /dev/null +++ b/items.csv @@ -0,0 +1,7451 @@ +#This file belongs to Essentials. +#version: TeamCity +#If you change this file, it will not be automatically updated after the next release. +#item,id,metadata +stone,1,0 +sstone,1,0 +smoothstone,1,0 +rock,1,0 +grass,2,0 +greendirt,2,0 +greenearth,2,0 +greenland,2,0 +dirt,3,0 +earth,3,0 +land,3,0 +grasslessdirt,3,1 +grasslessearth,3,1 +grasslessland,3,1 +podzol,3,2 +cobblestone,4,0 +cstone,4,0 +cobble,4,0 +wood,5,0 +plank,5,0 +woodenplank,5,0 +woodplank,5,0 +wplank,5,0 +plankwooden,5,0 +plankwood,5,0 +plankw,5,0 +oakplank,5,0 +oakwoodenplank,5,0 +oakwoodplank,5,0 +oakwplank,5,0 +oakplankwooden,5,0 +oakplankwood,5,0 +oakplankw,5,0 +oplank,5,0 +owoodenplank,5,0 +owoodplank,5,0 +owplank,5,0 +oplankwooden,5,0 +oplankwood,5,0 +oplankw,5,0 +pineplank,5,1 +pinewoodenplank,5,1 +pinewoodplank,5,1 +pinewplank,5,1 +pineplankwooden,5,1 +pineplankwood,5,1 +pineplankw,5,1 +pplank,5,1 +pwoodenplank,5,1 +pwoodplank,5,1 +pwplank,5,1 +pplankwooden,5,1 +pplankwood,5,1 +pplankw,5,1 +darkplank,5,1 +darkwoodenplank,5,1 +darkwoodplank,5,1 +darkwplank,5,1 +darkplankwooden,5,1 +darkplankwood,5,1 +darkplankw,5,1 +dplank,5,1 +dwoodenplank,5,1 +dwoodplank,5,1 +dwplank,5,1 +dplankwooden,5,1 +dplankwood,5,1 +dplankw,5,1 +spruceplank,5,1 +sprucewoodenplank,5,1 +sprucewoodplank,5,1 +sprucewplank,5,1 +spruceplankwooden,5,1 +spruceplankwood,5,1 +spruceplankw,5,1 +splank,5,1 +swoodenplank,5,1 +swoodplank,5,1 +swplank,5,1 +splankwooden,5,1 +splankwood,5,1 +splankw,5,1 +birchplank,5,2 +birchwoodenplank,5,2 +birchwoodplank,5,2 +birchwplank,5,2 +birchplankwooden,5,2 +birchplankwood,5,2 +birchplankw,5,2 +bplank,5,2 +bwoodenplank,5,2 +bwoodplank,5,2 +bwplank,5,2 +bplankwooden,5,2 +bplankwood,5,2 +bplankw,5,2 +lightplank,5,2 +lightwoodenplank,5,2 +lightwoodplank,5,2 +lightwplank,5,2 +lightplankwooden,5,2 +lightplankwood,5,2 +lightplankw,5,2 +lplank,5,2 +lwoodenplank,5,2 +lwoodplank,5,2 +lwplank,5,2 +lplankwooden,5,2 +lplankwood,5,2 +lplankw,5,2 +whiteplank,5,2 +whitewoodenplank,5,2 +whitewoodplank,5,2 +whitewplank,5,2 +whiteplankwooden,5,2 +whiteplankwood,5,2 +whiteplankw,5,2 +wwoodenplank,5,2 +wwoodplank,5,2 +wwplank,5,2 +wplankwooden,5,2 +wplankwood,5,2 +wplankw,5,2 +jungleplank,5,3 +junglewoodenplank,5,3 +junglewoodplank,5,3 +junglewplank,5,3 +jungleplankwooden,5,3 +jungleplankwood,5,3 +jungleplankw,5,3 +jplank,5,3 +jwoodenplank,5,3 +jwoodplank,5,3 +jwplank,5,3 +jplankwooden,5,3 +jplankwood,5,3 +jplankw,5,3 +forestplank,5,3 +forestwoodenplank,5,3 +forestwoodplank,5,3 +forestwplank,5,3 +forestplankwooden,5,3 +forestplankwood,5,3 +forestplankw,5,3 +fplank,5,3 +fwoodenplank,5,3 +fwoodplank,5,3 +fwplank,5,3 +fplankwooden,5,3 +fplankwood,5,3 +fplankw,5,3 +acaciaplank,5,4 +acaciawoodenplank,5,4 +acaciawoodplank,5,4 +acaciawplank,5,4 +acaciaplankwooden,5,4 +acaciaplankwood,5,4 +acaciaplankw,5,4 +aplank,5,4 +awoodenplank,5,4 +awoodplank,5,4 +awplank,5,4 +aplankwooden,5,4 +aplankwood,5,4 +aplankw,5,4 +darkoakplank,5,5 +darkoakwoodenplank,5,5 +darkoakwoodplank,5,5 +darkoakwplank,5,5 +darkoakplankwooden,5,5 +darkoakplankwood,5,5 +darkoakplankw,5,5 +doakplank,5,5 +doakwoodenplank,5,5 +doakwoodplank,5,5 +doakwplank,5,5 +doakplankwooden,5,5 +doakplankwood,5,5 +doakplankw,5,5 +doplank,5,5 +dowoodenplank,5,5 +dowoodplank,5,5 +dowplank,5,5 +doplankwooden,5,5 +doplankwood,5,5 +doplankw,5,5 +sapling,6,0 +treesapling,6,0 +logsapling,6,0 +trunksapling,6,0 +woodsapling,6,0 +oaktreesapling,6,0 +oaklogsapling,6,0 +oaktrunksapling,6,0 +oakwoodsapling,6,0 +osapling,6,0 +otreesapling,6,0 +ologsapling,6,0 +otrunksapling,6,0 +owoodsapling,6,0 +darksapling,6,1 +darktreesapling,6,1 +darklogsapling,6,1 +darktrunksapling,6,1 +darkwoodsapling,6,1 +sprucesapling,6,1 +sprucetreesapling,6,1 +sprucelogsapling,6,1 +sprucetrunksapling,6,1 +sprucewoodsapling,6,1 +pinesapling,6,1 +pinetreesapling,6,1 +pinelogsapling,6,1 +pinetrunksapling,6,1 +pinewoodsapling,6,1 +dsapling,6,1 +dtreesapling,6,1 +dlogsapling,6,1 +dtrunksapling,6,1 +dwoodsapling,6,1 +ssapling,6,1 +streesapling,6,1 +slogsapling,6,1 +strunksapling,6,1 +swoodsapling,6,1 +psapling,6,1 +ptreesapling,6,1 +plogsapling,6,1 +ptrunksapling,6,1 +pwoodsapling,6,1 +birchsapling,6,2 +birchtreesapling,6,2 +birchlogsapling,6,2 +birchtrunksapling,6,2 +birchwoodsapling,6,2 +lightsapling,6,2 +lighttreesapling,6,2 +lightlogsapling,6,2 +lighttrunksapling,6,2 +lightwoodsapling,6,2 +whitesapling,6,2 +whitetreesapling,6,2 +whitelogsapling,6,2 +whitetrunksapling,6,2 +whitewoodsapling,6,2 +bsapling,6,2 +btreesapling,6,2 +blogsapling,6,2 +btrunksapling,6,2 +bwoodsapling,6,2 +lsapling,6,2 +ltreesapling,6,2 +llogsapling,6,2 +ltrunksapling,6,2 +lwoodsapling,6,2 +wsapling,6,2 +wtreesapling,6,2 +wlogsapling,6,2 +wtrunksapling,6,2 +wwoodsapling,6,2 +junglesapling,6,3 +jungletreesapling,6,3 +junglelogsapling,6,3 +jungletrunksapling,6,3 +junglewoodsapling,6,3 +forestsapling,6,3 +foresttreesapling,6,3 +forestlogsapling,6,3 +foresttrunksapling,6,3 +forestwoodsapling,6,3 +jsapling,6,3 +jtreesapling,6,3 +jlogsapling,6,3 +jtrunksapling,6,3 +jwoodsapling,6,3 +fsapling,6,3 +ftreesapling,6,3 +flogsapling,6,3 +ftrunksapling,6,3 +fwoodsapling,6,3 +acaciasapling,6,4 +acaciatreesapling,6,4 +acacialogsapling,6,4 +acaciatrunksapling,6,4 +acaciawoodsapling,6,4 +asapling,6,4 +atreesapling,6,4 +alogsapling,6,4 +atrunksapling,6,4 +awoodsapling,6,4 +darkoaksapling,6,5 +darkoaktreesapling,6,5 +darkoaklogsapling,6,5 +darkoaktrunksapling,6,5 +darkoakwoodsapling,6,5 +doaksapling,6,5 +doaktreesapling,6,5 +doaklogsapling,6,5 +doaktrunksapling,6,5 +dosapling,6,5 +dowoodsapling,6,5 +dotreesapling,6,5 +dologsapling,6,5 +dotrunksapling,6,5 +bedrock,7,0 +oprock,7,0 +opblock,7,0 +adminblock,7,0 +adminrock,7,0 +adminium,7,0 +water,8,0 +stationarywater,9,0 +stillwater,9,0 +swater,9,0 +lava,10,0 +stationarylava,11,0 +stilllava,11,0 +slava,11,0 +sand,12,0 +redsand,12,1 +rsand,12,1 +gravel,13,0 +goldore,14,0 +oregold,14,0 +gore,14,0 +oreg,14,0 +ogold,14,0 +goldo,14,0 +ironore,15,0 +oreiron,15,0 +irono,15,0 +oiron,15,0 +steelore,15,0 +oresteel,15,0 +steelo,15,0 +osteel,15,0 +iore,15,0 +orei,15,0 +sore,15,0 +ores,15,0 +coalore,16,0 +orecoal,16,0 +coalo,16,0 +ocoal,16,0 +core,16,0 +tree,17,0 +log,17,0 +trunk,17,0 +oak,17,0 +oaktree,17,0 +oaklog,17,0 +oaktrunk,17,0 +oakwood,17,0 +otree,17,0 +olog,17,0 +otrunk,17,0 +owood,17,0 +pine,17,1 +pinetree,17,1 +pinelog,17,1 +pinetrunk,17,1 +pinewood,17,1 +darktree,17,1 +darklog,17,1 +darktrunk,17,1 +darkwood,17,1 +spruce,17,1 +sprucetree,17,1 +sprucelog,17,1 +sprucetrunk,17,1 +sprucewood,17,1 +dtree,17,1 +dlog,17,1 +dtrunk,17,1 +dwood,17,1 +stree,17,1 +slog,17,1 +strunk,17,1 +swood,17,1 +ptree,17,1 +plog,17,1 +ptrunk,17,1 +pwood,17,1 +birch,17,2 +birchtree,17,2 +birchlog,17,2 +birchtrunk,17,2 +birchwood,17,2 +whitetree,17,2 +whitelog,17,2 +whitetrunk,17,2 +whitewood,17,2 +lighttree,17,2 +lightlog,17,2 +lighttrunk,17,2 +lightwood,17,2 +btree,17,2 +blog,17,2 +btrunk,17,2 +bwood,17,2 +wtree,17,2 +wlog,17,2 +wtrunk,17,2 +wwood,17,2 +ltree,17,2 +llog,17,2 +ltrunk,17,2 +lwood,17,2 +jungletree,17,3 +junglelog,17,3 +jungletrunk,17,3 +junglewood,17,3 +jungle,17,3 +forest,17,3 +foresttree,17,3 +forestlog,17,3 +foresttrunk,17,3 +forestwood,17,3 +jtree,17,3 +jlog,17,3 +jtrunk,17,3 +jwood,17,3 +ftree,17,3 +flog,17,3 +ftrunk,17,3 +fwood,17,3 +leaves,18,0 +leaf,18,0 +treeleaves,18,0 +logleaves,18,0 +trunkleaves,18,0 +woodleaves,18,0 +oakleaves,18,0 +oakleaf,18,0 +oleaves,18,0 +oleaf,18,0 +oaktreeleaves,18,0 +oaklogleaves,18,0 +oaktrunkleaves,18,0 +oakwoodleaves,18,0 +otreeleaves,18,0 +ologleaves,18,0 +otrunkleaves,18,0 +owoodleaves,18,0 +treeleaf,18,0 +logleaf,18,0 +trunkleaf,18,0 +woodleaf,18,0 +oaktreeleaf,18,0 +oaklogleaf,18,0 +oaktrunkleaf,18,0 +oakwoodleaf,18,0 +otreeleaf,18,0 +ologleaf,18,0 +otrunkleaf,18,0 +owoodleaf,18,0 +pineleaves,18,1 +pineleaf,18,1 +pleaves,18,1 +pleaf,18,1 +pinetreeleaves,18,1 +pinelogleaves,18,1 +pinetrunkleaves,18,1 +pinewoodleaves,18,1 +ptreeleaves,18,1 +plogleaves,18,1 +ptrunkleaves,18,1 +pwoodleaves,18,1 +spruceleaves,18,1 +spruceleaf,18,1 +sleaves,18,1 +sleaf,18,1 +sprucetreeleaves,18,1 +sprucelogleaves,18,1 +sprucetrunkleaves,18,1 +sprucewoodleaves,18,1 +streeleaves,18,1 +slogleaves,18,1 +strunkleaves,18,1 +swoodleaves,18,1 +darkleaves,18,1 +darkleaf,18,1 +dleaves,18,1 +dleaf,18,1 +darktreeleaves,18,1 +darklogleaves,18,1 +darktrunkleaves,18,1 +darkwoodleaves,18,1 +dtreeleaves,18,1 +dlogleaves,18,1 +dtrunkleaves,18,1 +dwoodleaves,18,1 +sprucetreeleaf,18,1 +sprucelogleaf,18,1 +sprucetrunkleaf,18,1 +sprucewoodleaf,18,1 +streeleaf,18,1 +slogleaf,18,1 +strunkleaf,18,1 +swoodleaf,18,1 +pinetreeleaf,18,1 +pinelogleaf,18,1 +pinetrunkleaf,18,1 +pinewoodleaf,18,1 +ptreeleaf,18,1 +plogleaf,18,1 +ptrunkleaf,18,1 +pwoodleaf,18,1 +darktreeleaf,18,1 +darklogleaf,18,1 +darktrunkleaf,18,1 +darkwoodleaf,18,1 +dtreeleaf,18,1 +dlogleaf,18,1 +dtrunkleaf,18,1 +dwoodleaf,18,1 +birchleaves,18,2 +birchleaf,18,2 +bleaves,18,2 +bleaf,18,2 +birchtreeleaves,18,2 +birchlogleaves,18,2 +birchtrunkleaves,18,2 +birchwoodleaves,18,2 +btreeleaves,18,2 +blogleaves,18,2 +btrunkleaves,18,2 +bwoodleaves,18,2 +lightleaves,18,2 +lightleaf,18,2 +lleaves,18,2 +lleaf,18,2 +lighttreeleaves,18,2 +lightlogleaves,18,2 +lighttrunkleaves,18,2 +lightwoodleaves,18,2 +ltreeleaves,18,2 +llogleaves,18,2 +ltrunkleaves,18,2 +lwoodleaves,18,2 +whiteleaves,18,2 +whiteleaf,18,2 +wleaves,18,2 +wleaf,18,2 +whitetreeleaves,18,2 +whitelogleaves,18,2 +whitetrunkleaves,18,2 +whitewoodleaves,18,2 +wtreeleaves,18,2 +wlogleaves,18,2 +wtrunkleaves,18,2 +wwoodleaves,18,2 +birchtreeleaf,18,2 +birchlogleaf,18,2 +birchtrunkleaf,18,2 +birchwoodleaf,18,2 +btreeleaf,18,2 +blogleaf,18,2 +btrunkleaf,18,2 +bwoodleaf,18,2 +lighttreeleaf,18,2 +lightlogleaf,18,2 +lighttrunkleaf,18,2 +lightwoodleaf,18,2 +ltreeleaf,18,2 +llogleaf,18,2 +ltrunkleaf,18,2 +lwoodleaf,18,2 +whitetreeleaf,18,2 +whitelogleaf,18,2 +whitetrunkleaf,18,2 +whitewoodleaf,18,2 +wtreeleaf,18,2 +wlogleaf,18,2 +wtrunkleaf,18,2 +wwoodleaf,18,2 +jungleleaves,18,3 +jungleleaf,18,3 +jleaves,18,3 +jleaf,18,3 +jungletreeleaves,18,3 +junglelogleaves,18,3 +jungletrunkleaves,18,3 +junglewoodleaves,18,3 +jtreeleaves,18,3 +jlogleaves,18,3 +jtrunkleaves,18,3 +jwoodleaves,18,3 +forestleaves,18,3 +forestleaf,18,3 +fleaves,18,3 +fleaf,18,3 +foresttreeleaves,18,3 +forestlogleaves,18,3 +foresttrunkleaves,18,3 +forestwoodleaves,18,3 +ftreeleaves,18,3 +flogleaves,18,3 +ftrunkleaves,18,3 +fwoodleaves,18,3 +jungletreeleaf,18,3 +junglelogleaf,18,3 +jungletrunkleaf,18,3 +junglewoodleaf,18,3 +jtreeleaf,18,3 +jlogleaf,18,3 +jtrunkleaf,18,3 +jwoodleaf,18,3 +foresttreeleaf,18,3 +forestlogleaf,18,3 +foresttrunkleaf,18,3 +forestwoodleaf,18,3 +ftreeleaf,18,3 +flogleaf,18,3 +ftrunkleaf,18,3 +fwoodleaf,18,3 +sponge,19,0 +glass,20,0 +blockglass,20,0 +glassblock,20,0 +lapislazuliore,21,0 +lapislazulio,21,0 +orelapislazuli,21,0 +olapislazuli,21,0 +lapisore,21,0 +lapiso,21,0 +orelapis,21,0 +olapis,21,0 +lore,21,0 +orel,21,0 +lapislazuliblock,22,0 +blocklapislazuli,22,0 +lapisblock,22,0 +blocklapis,22,0 +lblock,22,0 +blockl,22,0 +dispenser,23,0 +dispense,23,0 +sandstone,24,0 +sastone,24,0 +creepersandstone,24,1 +creepersastone,24,1 +creepsandstone,24,1 +creepsastone,24,1 +csandstone,24,1 +csastone,24,1 +hieroglyphicsandstone,24,1 +hieroglyphicsastone,24,1 +hieroglyphsandstone,24,1 +hieroglyphsastone,24,1 +hsandstone,24,1 +hsastone,24,1 +pyramidsandstone,24,1 +pyramidsastone,24,1 +psandstone,24,1 +psastone,24,1 +chiseledsandstone,24,1 +chiseledsastone,24,1 +chiselsandstone,24,1 +chiselsastone,24,1 +smoothsandstone,24,2 +smoothsastone,24,2 +ssandstone,24,2 +smsastone,24,2 +ssastone,24,2 +noteblock,25,0 +musicblock,25,0 +nblock,25,0 +mblock,25,0 +poweredtrack,27,0 +poweredrails,27,0 +poweredrail,27,0 +boostertrack,27,0 +boosterrails,27,0 +boosterrail,27,0 +powertrack,27,0 +powerrails,27,0 +powerrail,27,0 +boosttrack,27,0 +boostrails,27,0 +boostrail,27,0 +ptrack,27,0 +prails,27,0 +prail,27,0 +btrack,27,0 +brails,27,0 +brail,27,0 +detectortrack,28,0 +detectorrails,28,0 +detectorrail,28,0 +detectingtrack,28,0 +detectingrails,28,0 +detectingrail,28,0 +detecttrack,28,0 +detectrails,28,0 +detectrail,28,0 +dtrack,28,0 +drails,28,0 +drail,28,0 +stickypistonbase,29,0 +stickypiston,29,0 +stickpistonbase,29,0 +stickpiston,29,0 +stickyp,29,0 +spistonbase,29,0 +spiston,29,0 +pistonstickybase,29,0 +pistonsticky,29,0 +pistonstickbase,29,0 +pistonstick,29,0 +pistonsbase,29,0 +pistons,29,0 +psticky,29,0 +pstick,29,0 +spiderweb,30,0 +cobweb,30,0 +sweb,30,0 +cweb,30,0 +web,30,0 +longgrass,31,1 +tallgrass,31,1 +wildgrass,31,1 +grasslong,31,1 +grasstall,31,1 +grasswild,31,1 +lgrass,31,1 +tgrass,31,1 +wgrass,31,1 +fern,31,2 +bush,31,2 +deadshrub,32,0 +dshrub,32,0 +deadbush,32,0 +dbush,32,0 +deadsapling,32,0 +piston,33,0 +pistonbase,33,0 +pistonblock,33,0 +whitewool,35,0 +whitecloth,35,0 +whitecotton,35,0 +wcloth,35,0 +wwool,35,0 +wcotton,35,0 +cloth,35,0 +wool,35,0 +cotton,35,0 +orangewool,35,1 +orangecloth,35,1 +orangecotton,35,1 +ocloth,35,1 +owool,35,1 +ocotton,35,1 +magentawool,35,2 +magentacloth,35,2 +magentacotton,35,2 +mcloth,35,2 +mwool,35,2 +mcotton,35,2 +lightbluewool,35,3 +lightbluecloth,35,3 +lightbluecotton,35,3 +lbluecloth,35,3 +lbluewool,35,3 +lbluecotton,35,3 +lightblucloth,35,3 +lightbluwool,35,3 +lightblucotton,35,3 +lblucloth,35,3 +lbluwool,35,3 +lblucotton,35,3 +lbcloth,35,3 +lbwool,35,3 +lbcotton,35,3 +yellowwool,35,4 +yellowcloth,35,4 +yellowcotton,35,4 +ycloth,35,4 +ywool,35,4 +ycotton,35,4 +lightgreenwool,35,5 +lightgreencloth,35,5 +lightgreencotton,35,5 +lgreencloth,35,5 +lgreenwool,35,5 +lgreencotton,35,5 +lightgrecloth,35,5 +lightgrewool,35,5 +lightgrecotton,35,5 +lgrecloth,35,5 +lgrewool,35,5 +lgrecotton,35,5 +limecloth,35,5 +limewool,35,5 +limecotton,35,5 +lcloth,35,5 +lwool,35,5 +lcotton,35,5 +pinkwool,35,6 +pinkcloth,35,6 +pinkcotton,35,6 +picloth,35,6 +piwool,35,6 +picotton,35,6 +darkgraywool,35,7 +darkgraycloth,35,7 +darkgraycotton,35,7 +darkgreywool,35,7 +darkgreycloth,35,7 +darkgreycotton,35,7 +dgraycloth,35,7 +dgraywool,35,7 +dgraycotton,35,7 +dgreycloth,35,7 +dgreywool,35,7 +dgreycotton,35,7 +darkgracloth,35,7 +darkgrawool,35,7 +darkgracotton,35,7 +dgracloth,35,7 +dgrawool,35,7 +dgracotton,35,7 +graycloth,35,7 +graywool,35,7 +graycotton,35,7 +greycloth,35,7 +greywool,35,7 +greycotton,35,7 +gracloth,35,7 +grawool,35,7 +gracotton,35,7 +lightgraywool,35,8 +lightgraycloth,35,8 +lightgraycotton,35,8 +lgraycloth,35,8 +lgraywool,35,8 +lgraycotton,35,8 +lightgreywool,35,8 +lightgreycloth,35,8 +lightgreycotton,35,8 +lgreycloth,35,8 +lgreywool,35,8 +lgreycotton,35,8 +lightgracloth,35,8 +lightgrawool,35,8 +lightgracotton,35,8 +lgracloth,35,8 +lgrawool,35,8 +lgracotton,35,8 +silvercloth,35,8 +silverwool,35,8 +silvercotton,35,8 +sicloth,35,8 +siawool,35,8 +siacotton,35,8 +cyanwool,35,9 +cyancloth,35,9 +cyancotton,35,9 +ccloth,35,9 +cwool,35,9 +ccotton,35,9 +purplewool,35,10 +purplecloth,35,10 +purplecotton,35,10 +pucloth,35,10 +puwool,35,10 +pucotton,35,10 +bluewool,35,11 +bluecloth,35,11 +bluecotton,35,11 +blucloth,35,11 +bluwool,35,11 +blucotton,35,11 +brownwool,35,12 +browncloth,35,12 +browncotton,35,12 +brocloth,35,12 +browool,35,12 +brocotton,35,12 +darkgreenwool,35,13 +darkgreencloth,35,13 +darkgreencotton,35,13 +dgreencloth,35,13 +dgreenwool,35,13 +dgreencotton,35,13 +greencloth,35,13 +greenwool,35,13 +greencotton,35,13 +darkgrecloth,35,13 +darkgrewool,35,13 +darkgrecotton,35,13 +dgrecloth,35,13 +dgrewool,35,13 +dgrecotton,35,13 +grecloth,35,13 +grewool,35,13 +grecotton,35,13 +redwool,35,14 +redcloth,35,14 +redcotton,35,14 +rcloth,35,14 +rwool,35,14 +rcotton,35,14 +blackwool,35,15 +blackcloth,35,15 +blackcotton,35,15 +blacloth,35,15 +blawool,35,15 +blacotton,35,15 +dandelion,37,0 +yellowdandelion,37,0 +ydandelion,37,0 +yellowflower,37,0 +yflower,37,0 +flower,37,0 +rose,38,0 +redrose,38,0 +rrose,38,0 +redflower,38,0 +rflower,38,0 +poppy,38,0 +redpoppy,38,0 +blueorchid,38,1 +cyanorchid,38,1 +lightblueorchid,38,1 +lblueorchid,38,1 +orchid,38,1 +allium,38,2 +magentaallium,38,2 +azurebluet,38,3 +whiteazurebluet,38,3 +abluet,38,3 +azureb,38,3 +houstonia,38,3 +redtulip,38,4 +tulipred,38,4 +rtulip,38,4 +tulipr,38,4 +orangetulip,38,5 +tuliporange,38,5 +otulip,38,5 +tulipo,38,5 +whitetulip,38,6 +tulipwhite,38,6 +wtulip,38,6 +tulipw,38,6 +pinktulip,38,7 +tulippink,38,7 +ptulip,38,7 +tulipp,38,7 +oxeye,38,8 +daisy,38,8 +oxeyedaisy,38,8 +daisyoxeye,38,8 +moondaisy,38,8 +daisymoon,38,8 +lightgrayoxeye,38,8 +lgrayoxeye,38,8 +lightgreyoxeye,38,8 +lgreyoxeye,38,8 +brownmushroom,39,0 +brownshroom,39,0 +brownmush,39,0 +bmushroom,39,0 +bshroom,39,0 +bmush,39,0 +redmushroom,40,0 +redshroom,40,0 +redmush,40,0 +rmushroom,40,0 +rshroom,40,0 +rmush,40,0 +goldblock,41,0 +blockgold,41,0 +gblock,41,0 +blockg,41,0 +ironblock,42,0 +steelblock,42,0 +blockiron,42,0 +blocksteel,42,0 +iblock,42,0 +stblock,42,0 +blocki,42,0 +blockst,42,0 +stonedoublestep,43,0 +stonedstep,43,0 +sdoublestep,43,0 +sdstep,43,0 +doublestonestep,43,0 +dstonestep,43,0 +doublesstep,43,0 +doublestep,43,0 +dstep,43,0 +stonedoubleslab,43,0 +stonedslab,43,0 +sdoubleslab,43,0 +sdslab,43,0 +doublestoneslab,43,0 +dstoneslab,43,0 +doublesslab,43,0 +doubleslab,43,0 +dslab,43,0 +stonedoublehalfblock,43,0 +stonedhalfblock,43,0 +sdoublehalfblock,43,0 +sdhalfblock,43,0 +doublestonehalfblock,43,0 +dstonehalfblock,43,0 +doubleshalfblock,43,0 +doublehalfblock,43,0 +dhalfblock,43,0 +sandstonedoublestep,43,1 +sandstonedstep,43,1 +sstonedoublestep,43,1 +sstonedstep,43,1 +ssdoublestep,43,1 +ssdstep,43,1 +doublesandstonestep,43,1 +dsandstonestep,43,1 +doublesstonestep,43,1 +dsstonestep,43,1 +doublessstep,43,1 +dsstep,43,1 +sandstonedoubleslab,43,1 +sandstonedslab,43,1 +sstonedoubleslab,43,1 +sstonedslab,43,1 +ssdoubleslab,43,1 +ssdslab,43,1 +doublesandstoneslab,43,1 +dsandstoneslab,43,1 +doublesstoneslab,43,1 +dsstoneslab,43,1 +doublessslab,43,1 +dsslab,43,1 +sandstonedoublehalfblock,43,1 +sandstonedhalfblock,43,1 +sstonedoublehalfblock,43,1 +sstonedhalfblock,43,1 +ssdoublehalfblock,43,1 +ssdhalfblock,43,1 +doublesandstonehalfblock,43,1 +dsandstonehalfblock,43,1 +doublesstonehalfblock,43,1 +dsstonehalfblock,43,1 +doublesshalfblock,43,1 +dsshalfblock,43,1 +plankstonedoublestep,43,2 +woodenstonedoublestep,43,2 +woodenstonedstep,43,2 +woodstonedoublestep,43,2 +woodstonedstep,43,2 +wstonedoublestep,43,2 +wstonedstep,43,2 +doublewoodenstonestep,43,2 +dwoodenstonestep,43,2 +doublewoodstonestep,43,2 +dwoodstonestep,43,2 +doublewstonestep,43,2 +dwstonestep,43,2 +woodenstonedoubleslab,43,2 +woodenstonedslab,43,2 +woodstonedoubleslab,43,2 +woodstonedslab,43,2 +wstonedoubleslab,43,2 +wstonedslab,43,2 +doublewoodenstoneslab,43,2 +dwoodenstoneslab,43,2 +doublewoodstoneslab,43,2 +dwoodstoneslab,43,2 +doublewstoneslab,43,2 +dwstoneslab,43,2 +woodenstonedoublehalfblock,43,2 +woodenstonedhalfblock,43,2 +woodstonedoublehalfblock,43,2 +woodstonedhalfblock,43,2 +wstonedoublehalfblock,43,2 +wstonedhalfblock,43,2 +doublewoodenstonehalfblock,43,2 +dwoodenstonehalfblock,43,2 +doublewoodstonehalfblock,43,2 +dwoodstonehalfblock,43,2 +doublewstonehalfblock,43,2 +dwstonehalfblock,43,2 +cobblestonedoublestep,43,3 +cobblestonedstep,43,3 +cobbledoublestep,43,3 +cobbledstep,43,3 +cstonedoublestep,43,3 +cstonedstep,43,3 +csdoublestep,43,3 +csdstep,43,3 +doublecobblestonestep,43,3 +dcobblestonestep,43,3 +doublecobblestep,43,3 +dcobblestep,43,3 +doublecstonestep,43,3 +dcstonestep,43,3 +doublecsstep,43,3 +dcsstep,43,3 +cobblestonedoubleslab,43,3 +cobblestonedslab,43,3 +cobbledoubleslab,43,3 +cobbledslab,43,3 +cstonedoubleslab,43,3 +cstonedslab,43,3 +csdoubleslab,43,3 +csdslab,43,3 +doublecobblestoneslab,43,3 +dcobblestoneslab,43,3 +doublecobbleslab,43,3 +dcobbleslab,43,3 +doublecstoneslab,43,3 +dcstoneslab,43,3 +doublecsslab,43,3 +dcsslab,43,3 +cobblestonedoublehalfblock,43,3 +cobblestonedhalfblock,43,3 +cobbledoublehalfblock,43,3 +cobbledhalfblock,43,3 +cstonedoublehalfblock,43,3 +cstonedhalfblock,43,3 +csdoublehalfblock,43,3 +csdhalfblock,43,3 +doublecobblestonehalfblock,43,3 +dcobblestonehalfblock,43,3 +doublecobblehalfblock,43,3 +dcobblehalfblock,43,3 +doublecstonehalfblock,43,3 +dcstonehalfblock,43,3 +doublecshalfblock,43,3 +dcshalfblock,43,3 +brickdoublestep,43,4 +brickdstep,43,4 +bdoublestep,43,4 +bdstep,43,4 +brickdoubleslab,43,4 +brickdslab,43,4 +bdoubleslab,43,4 +bdslab,43,4 +doublebrickstep,43,4 +dbrickstep,43,4 +doublebstep,43,4 +dbstep,43,4 +doublebrickslab,43,4 +dbrickslab,43,4 +doublebslab,43,4 +dbslab,43,4 +brickdoublehalfblock,43,4 +brickdhalfblock,43,4 +bdoublehalfblock,43,4 +bdhalfblock,43,4 +doublebrickhalfblock,43,4 +dbrickhalfblock,43,4 +doublebhalfblock,43,4 +dbhalfblock,43,4 +stonebrickdoublestep,43,5 +stonebrickdstep,43,5 +stonebdoublestep,43,5 +stonebdstep,43,5 +sbrickdoublestep,43,5 +sbrickdstep,43,5 +sbdoublestep,43,5 +sbdstep,43,5 +stonebrickdoubleslab,43,5 +stonebrickdslab,43,5 +stonebdoubleslab,43,5 +stonebdslab,43,5 +sbrickdoubleslab,43,5 +sbrickdslab,43,5 +sbdoubleslab,43,5 +sbdslab,43,5 +doublestonebrickstep,43,5 +dstonebrickstep,43,5 +doublestonebstep,43,5 +dstonebstep,43,5 +doublesbrickstep,43,5 +dsbrickstep,43,5 +doublesbstep,43,5 +dsbstep,43,5 +doublestonebrickslab,43,5 +dstonebrickslab,43,5 +doublestonebslab,43,5 +dstonebslab,43,5 +doublesbrickslab,43,5 +dsbrickdslab,43,5 +doublesbslab,43,5 +dsbslab,43,5 +stonebrickdoublehalfblock,43,5 +stonebrickdhalfblock,43,5 +stonebdoublehalfblock,43,5 +stonebdhalfblock,43,5 +sbrickdoublehalfblock,43,5 +sbrickdhalfblock,43,5 +sbdoublehalfblock,43,5 +sbdhalfblock,43,5 +doublestonebrickhalfblock,43,5 +dstonebrickhalfblock,43,5 +doublestonebhalfblock,43,5 +dstonebhalfblock,43,5 +doublesbrickhalfblock,43,5 +dsbrickhalfblock,43,5 +doublesbhalfblock,43,5 +dsbhalfblock,43,5 +netherbrickdoubleslab,43,6 +hellbrickdoubleslab,43,6 +nbrickdoubleslab,43,6 +hbrickdoubleslab,43,6 +netherdoubleslab,43,6 +helldoubleslab,43,6 +nbdoubleslab,43,6 +hbdoubleslab,43,6 +hdoubleslab,43,6 +ndoubleslab,43,6 +netherbrickdoublestep,43,6 +hellbrickdoublestep,43,6 +nbrickdoublestep,43,6 +hbrickdoublestep,43,6 +netherdoublestep,43,6 +helldoublestep,43,6 +nbdoublestep,43,6 +hbdoublestep,43,6 +ndoublestep,43,6 +hdoublestep,43,6 +netherbrickdoublehalfblock,43,6 +hellbrickdoublehalfblock,43,6 +nbrickdoublehalfblock,43,6 +hbrickdoublehalfblock,43,6 +netherdoublehalfblock,43,6 +helldoublehalfblock,43,6 +nbdoublehalfblock,43,6 +hbdoublehalfblock,43,6 +ndoublehalfblock,43,6 +hdoublehalfblock,43,6 +netherbrickdslab,43,6 +hellbrickdslab,43,6 +nbrickdslab,43,6 +hbrickdslab,43,6 +netherdslab,43,6 +helldslab,43,6 +nbdslab,43,6 +hbdslab,43,6 +hdslab,43,6 +ndslab,43,6 +netherbrickdstep,43,6 +hellbrickdstep,43,6 +nbrickdstep,43,6 +hbrickdstep,43,6 +netherdstep,43,6 +helldstep,43,6 +nbdstep,43,6 +hbdstep,43,6 +ndstep,43,6 +hdstep,43,6 +netherbrickdhalfblock,43,6 +hellbrickdhalfblock,43,6 +nbrickdhalfblock,43,6 +hbrickdhalfblock,43,6 +netherdhalfblock,43,6 +helldhalfblock,43,6 +nbdhalfblock,43,6 +hbdhalfblock,43,6 +ndhalfblock,43,6 +hdhalfblock,43,6 +doublenetherbrickslab,43,6 +doublehellbrickslab,43,6 +doublenbrickslab,43,6 +doublehbrickslab,43,6 +doublenetherslab,43,6 +doublehellslab,43,6 +doublenbslab,43,6 +doublehbslab,43,6 +doublehslab,43,6 +doublenslab,43,6 +doublenetherbrickstep,43,6 +doublehellbrickstep,43,6 +doublenbrickstep,43,6 +doublehbrickstep,43,6 +doublenetherstep,43,6 +doublehellstep,43,6 +doublenbstep,43,6 +doublehbstep,43,6 +doublenstep,43,6 +doublehstep,43,6 +doublenetherbrickhalfblock,43,6 +doublehellbrickhalfblock,43,6 +doublenbrickhalfblock,43,6 +doublehbrickhalfblock,43,6 +doublenetherhalfblock,43,6 +doublehellhalfblock,43,6 +doublenbhalfblock,43,6 +doublehbhalfblock,43,6 +doublenhalfblock,43,6 +doublehhalfblock,43,6 +dnetherbrickslab,43,6 +dhellbrickslab,43,6 +dnbrickslab,43,6 +dhbrickslab,43,6 +dnetherslab,43,6 +dhellslab,43,6 +dnbslab,43,6 +dhbslab,43,6 +dhslab,43,6 +dnslab,43,6 +dnetherbrickstep,43,6 +dhellbrickstep,43,6 +dnbrickstep,43,6 +dhbrickstep,43,6 +dnetherstep,43,6 +dhellstep,43,6 +dnbstep,43,6 +dhbstep,43,6 +dnstep,43,6 +dhstep,43,6 +dnetherbrickhalfblock,43,6 +dhellbrickhalfblock,43,6 +dnbrickhalfblock,43,6 +dhbrickhalfblock,43,6 +dnetherhalfblock,43,6 +dhellhalfblock,43,6 +dnbhalfblock,43,6 +dhbhalfblock,43,6 +dnhalfblock,43,6 +dhhalfblock,43,6 +netherquartzdoublestep,43,7 +hellquartzdoublestep,43,7 +deathquartzdoublestep,43,7 +nquartzdoublestep,43,7 +hquartzdoublestep,43,7 +dquartzdoublestep,43,7 +quartzdoublestep,43,7 +nqdoublestep,43,7 +hqdoublestep,43,7 +dqdoublestep,43,7 +qdoublestep,43,7 +netherquartzdoubleslab,43,7 +hellquartzdoubleslab,43,7 +deathquartzdoubleslab,43,7 +nquartzdoubleslab,43,7 +hquartzdoubleslab,43,7 +dquartzdoubleslab,43,7 +quartzdoubleslab,43,7 +nqdoubleslab,43,7 +hqdoubleslab,43,7 +dqdoubleslab,43,7 +qdoubleslab,43,7 +netherquartzdoublehalfblock,43,7 +hellquartzdoublehalfblock,43,7 +deathquartzdoublehalfblock,43,7 +nquartzdoublehalfblock,43,7 +hquartzdoublehalfblock,43,7 +dquartzdoublehalfblock,43,7 +quartzdoublehalfblock,43,7 +nqdoublehalfblock,43,7 +hqdoublehalfblock,43,7 +dqdoublehalfblock,43,7 +qdoublehalfblock,43,7 +netherquartzdslab,43,7 +hellquartzdslab,43,7 +deathquartzdslab,43,7 +nquartzdslab,43,7 +hquartzdslab,43,7 +dquartzdslab,43,7 +quartzdslab,43,7 +nqdslab,43,7 +hqdslab,43,7 +dqdslab,43,7 +qdslab,43,7 +netherquartzdstep,43,7 +hellquartzdstep,43,7 +deathquartzdstep,43,7 +nquartzdstep,43,7 +hquartzdstep,43,7 +dquartzdstep,43,7 +quartzdstep,43,7 +nqdstep,43,7 +hqdstep,43,7 +dqdstep,43,7 +qdstep,43,7 +netherquartzdhalfblock,43,7 +hellquartzdhalfblock,43,7 +deathquartzdhalfblock,43,7 +nquartzdhalfblock,43,7 +hquartzdhalfblock,43,7 +dquartzdhalfblock,43,7 +quartzdhalfblock,43,7 +nqdhalfblock,43,7 +hqdhalfblock,43,7 +dqdhalfblock,43,7 +qdhalfblock,43,7 +doublenetherquartzslab,43,7 +doublehellquartzslab,43,7 +doubledeathquartzslab,43,7 +doublenquartzslab,43,7 +doublehquartzslab,43,7 +doubledquartzslab,43,7 +doublequartzslab,43,7 +doublenqslab,43,7 +doublehqslab,43,7 +doubledqslab,43,7 +doubleqslab,43,7 +doublenetherquartzstep,43,7 +doublehellquartzstep,43,7 +doubledeathquartzstep,43,7 +doublenquartzstep,43,7 +doublehquartzstep,43,7 +doubledquartzstep,43,7 +doublequartzstep,43,7 +doublenqstep,43,7 +doublehqstep,43,7 +doubledqstep,43,7 +doubleqstep,43,7 +doublenetherquartzhalfblock,43,7 +doublehellquartzhalfblock,43,7 +doubledeathquartzhalfblock,43,7 +doublenquartzhalfblock,43,7 +doublehquartzhalfblock,43,7 +doubledquartzhalfblock,43,7 +doublequartzhalfblock,43,7 +doublenqhalfblock,43,7 +doublehqhalfblock,43,7 +doubledqhalfblock,43,7 +doubleqhalfblock,43,7 +dnetherquartzslab,43,7 +dhellquartzslab,43,7 +ddeathquartzslab,43,7 +dnquartzslab,43,7 +dhquartzslab,43,7 +ddquartzslab,43,7 +dnqslab,43,7 +dhqslab,43,7 +ddqslab,43,7 +dnetherquartzstep,43,7 +dhellquartzstep,43,7 +ddeathquartzstep,43,7 +dnquartzstep,43,7 +dhquartzstep,43,7 +ddquartzstep,43,7 +dnqstep,43,7 +dhqstep,43,7 +ddqstep,43,7 +dnetherquartzhalfblock,43,7 +dhellquartzhalfblock,43,7 +ddeathquartzhalfblock,43,7 +dnquartzhalfblock,43,7 +dhquartzhalfblock,43,7 +ddquartzhalfblock,43,7 +dnqhalfblock,43,7 +dhqhalfblock,43,7 +ddqhalfblock,43,7 +smoothstonedoubleslab,43,8 +smoothstonedoublestep,43,8 +smoothstonedoublehalfblock,43,8 +smoothstonedslab,43,8 +smoothstonedstep,43,8 +smoothstonedhalfblock,43,8 +doublesmoothstoneslab,43,8 +doublesmoothstonestep,43,8 +doublesmoothstonehalfblock,43,8 +dsmoothstoneslab,43,8 +dsmoothstonestep,43,8 +dsmoothstonehalfblock,43,8 +smoothsandstonedoubleslab,43,9 +ssandstonedoubleslab,43,9 +ssstonedoubleslab,43,9 +sssdoubleslab,43,9 +smoothsandstonedoublestep,43,9 +ssandstonedoublestep,43,9 +ssstonedoublestep,43,9 +sssdoublestep,43,9 +smoothsandstonedoublehalfblock,43,9 +ssandstonedoublehalfblock,43,9 +ssstonedoublehalfblock,43,9 +sssdoublehalfblock,43,9 +smoothsandstonedslab,43,9 +ssandstonedslab,43,9 +ssstonedslab,43,9 +sssdslab,43,9 +smoothsandstonedstep,43,9 +ssandstonedstep,43,9 +ssstonedstep,43,9 +sssdstep,43,9 +smoothsandstonedhalfblock,43,9 +ssandstonedhalfblock,43,9 +ssstonedhalfblock,43,9 +sssdhalfblock,43,9 +doublesmoothsandstoneslab,43,9 +doublessandstoneslab,43,9 +doublessstoneslab,43,9 +doublesssslab,43,9 +doublesmoothsandstonestep,43,9 +doublessandstonestep,43,9 +doublessstonestep,43,9 +doublesssstep,43,9 +doublesmoothsandstonehalfblock,43,9 +doublessandstonehalfblock,43,9 +doublessstonehalfblock,43,9 +doublessshalfblock,43,9 +dsmoothsandstoneslab,43,9 +dssandstoneslab,43,9 +dssstoneslab,43,9 +dsssslab,43,9 +dsmoothsandstonestep,43,9 +dssandstonestep,43,9 +dssstonestep,43,9 +dsssstep,43,9 +dsmoothsandstonehalfblock,43,9 +dssandstonehalfblock,43,9 +dssstonehalfblock,43,9 +dssshalfblock,43,9 +smoothstonestep,44,0 +stonestep,44,0 +sstep,44,0 +step,44,0 +smoothstoneslab,44,0 +stoneslab,44,0 +sslab,44,0 +slab,44,0 +smoothstonehalfblock,44,0 +stonehalfblock,44,0 +shalfblock,44,0 +halfblock,44,0 +sandstonestep,44,1 +sstonestep,44,1 +ssstep,44,1 +sandstoneslab,44,1 +sstoneslab,44,1 +ssslab,44,1 +sandstonehalfblock,44,1 +sstonehalfblock,44,1 +sshalfblock,44,1 +woodenstonestep,44,2 +woodstonestep,44,2 +wstonestep,44,2 +woodenstoneslab,44,2 +woodstoneslab,44,2 +wstoneslab,44,2 +woodenstonehalfblock,44,2 +woodstonehalfblock,44,2 +wstonehalfblock,44,2 +cobblestonestep,44,3 +cobblestep,44,3 +cstonestep,44,3 +csstep,44,3 +cobblestoneslab,44,3 +cobbleslab,44,3 +cstoneslab,44,3 +csslab,44,3 +cobblestonehalfblock,44,3 +cobblehalfblock,44,3 +cstonehalfblock,44,3 +cshalfblock,44,3 +brickstep,44,4 +bstep,44,4 +brickslab,44,4 +bslab,44,4 +brickhalfblock,44,4 +bhalfblock,44,4 +stonebrickstep,44,5 +stonebstep,44,5 +sbrickstep,44,5 +sbstep,44,5 +stonebrickslab,44,5 +stonebslab,44,5 +sbrickslab,44,5 +sbslab,44,5 +stonebrickhalfblock,44,5 +stonebhalfblock,44,5 +sbrickhalfblock,44,5 +sbhalfblock,44,5 +netherbrickslab,44,6 +hellbrickslab,44,6 +nbrickslab,44,6 +hbrickslab,44,6 +netherslab,44,6 +hellslab,44,6 +nbslab,44,6 +hbslab,44,6 +hslab,44,6 +nslab,44,6 +netherbrickstep,44,6 +hellbrickstep,44,6 +nbrickstep,44,6 +hbrickstep,44,6 +netherstep,44,6 +hellstep,44,6 +nbstep,44,6 +hbstep,44,6 +nstep,44,6 +hstep,44,6 +netherbrickhalfblock,44,6 +hellbrickhalfblock,44,6 +nbrickhalfblock,44,6 +hbrickhalfblock,44,6 +netherhalfblock,44,6 +hellhalfblock,44,6 +nbhalfblock,44,6 +hbhalfblock,44,6 +nhalfblock,44,6 +hhalfblock,44,6 +netherquartzstep,44,7 +hellquartzstep,44,7 +deathquartzstep,44,7 +nquartzstep,44,7 +hquartzstep,44,7 +dquartzstep,44,7 +quartzstep,44,7 +nqstep,44,7 +hqstep,44,7 +dqstep,44,7 +qstep,44,7 +netherquartzslab,44,7 +hellquartzslab,44,7 +deathquartzslab,44,7 +nquartzslab,44,7 +hquartzslab,44,7 +dquartzslab,44,7 +quartzslab,44,7 +nqslab,44,7 +hqslab,44,7 +dqslab,44,7 +qslab,44,7 +netherquartzhalfblock,44,7 +hellquartzhalfblock,44,7 +deathquartzhalfblock,44,7 +nquartzhalfblock,44,7 +hquartzhalfblock,44,7 +dquartzhalfblock,44,7 +quartzhalfblock,44,7 +nqhalfblock,44,7 +hqhalfblock,44,7 +dqhalfblock,44,7 +qhalfblock,44,7 +brickblock,45,0 +blockbrick,45,0 +bblock,45,0 +blockb,45,0 +tnt,46,0 +tntblock,46,0 +blocktnt,46,0 +bombblock,46,0 +blockbomb,46,0 +dynamiteblock,46,0 +blockdynamite,46,0 +bomb,46,0 +dynamite,46,0 +bookcase,47,0 +casebook,47,0 +bookshelf,47,0 +shelfbook,47,0 +bookblock,47,0 +blockbook,47,0 +mossycobblestone,48,0 +mosscobblestone,48,0 +mcobblestone,48,0 +mossycobble,48,0 +mosscobble,48,0 +mcobble,48,0 +mossstone,48,0 +mossystone,48,0 +mstone,48,0 +obsidian,49,0 +obsi,49,0 +obby,49,0 +torch,50,0 +burningstick,50,0 +burnstick,50,0 +fire,51,0 +flame,51,0 +flames,51,0 +mobspawner,52,0 +mobcage,52,0 +monsterspawner,52,0 +monstercage,52,0 +mspawner,52,0 +mcage,52,0 +spawner,52,0 +cage,52,0 +woodenstairs,53,0 +woodstairs,53,0 +wstairs,53,0 +woodenstair,53,0 +woodstair,53,0 +wstair,53,0 +chest,54,0 +container,54,0 +diamondore,56,0 +crystalore,56,0 +orediamond,56,0 +orecrystal,56,0 +dore,56,0 +ored,56,0 +diamondblock,57,0 +blockdiamond,57,0 +crystalblock,57,0 +blockcrystal,57,0 +dblock,57,0 +blockd,57,0 +workbench,58,0 +craftingbench,58,0 +crafterbench,58,0 +craftbench,58,0 +worktable,58,0 +craftingtable,58,0 +craftertable,58,0 +crafttable,58,0 +wbench,58,0 +cbench,58,0 +soil,60,0 +furnace,61,0 +litfurnace,62,0 +lfurnace,62,0 +burningfurnace,62,0 +burnfurnace,62,0 +bfurnace,62,0 +ladder,65,0 +minecarttrack,66,0 +minecartrails,66,0 +minecartrail,66,0 +mcarttrack,66,0 +mcartrails,66,0 +mcartrail,66,0 +mctrack,66,0 +mcrails,66,0 +mcrail,66,0 +track,66,0 +rails,66,0 +rail,66,0 +cobblestonestairs,67,0 +cstonestairs,67,0 +stonestairs,67,0 +cobblestairs,67,0 +csstairs,67,0 +sstairs,67,0 +cstairs,67,0 +cobblestonestair,67,0 +cstonestair,67,0 +stonestair,67,0 +cobblestair,67,0 +csstair,67,0 +sstair,67,0 +cstair,67,0 +lever,69,0 +stonepressureplate,70,0 +stonepressplate,70,0 +stonepplate,70,0 +stoneplate,70,0 +spressureplate,70,0 +spressplate,70,0 +spplate,70,0 +splate,70,0 +smoothstonepressureplate,70,0 +smoothstonepressplate,70,0 +smoothstonepplate,70,0 +smoothstoneplate,70,0 +sstonepressureplate,70,0 +sstonepressplate,70,0 +sstonepplate,70,0 +sstoneplate,70,0 +woodenpressureplate,72,0 +woodenpressplate,72,0 +woodenpplate,72,0 +woodenplate,72,0 +woodpressureplate,72,0 +woodpressplate,72,0 +woodpplate,72,0 +woodplate,72,0 +wpressureplate,72,0 +wpressplate,72,0 +wpplate,72,0 +wplate,72,0 +redstoneore,73,0 +redsore,73,0 +redore,73,0 +rstoneore,73,0 +rsore,73,0 +rore,73,0 +oreredstone,73,0 +orereds,73,0 +orered,73,0 +orerstone,73,0 +orers,73,0 +orer,73,0 +redstonetorch,76,0 +rstonetorch,76,0 +redstorch,76,0 +redtorch,76,0 +rstorch,76,0 +stonebutton,77,0 +smoothstonebutton,77,0 +sstonebutton,77,0 +sbutton,77,0 +button,77,0 +snowcover,78,0 +snowcovering,78,0 +scover,78,0 +ice,79,0 +frozenwater,79,0 +waterfrozen,79,0 +freezewater,79,0 +waterfreeze,79,0 +snowblock,80,0 +blocksnow,80,0 +sblock,80,0 +blocks,80,0 +cactus,81,0 +cactuses,81,0 +cacti,81,0 +clayblock,82,0 +blockclay,82,0 +cblock,82,0 +blockc,82,0 +jukebox,84,0 +jbox,84,0 +woodenfence,85,0 +fence,85,0 +woodfence,85,0 +wfence,85,0 +fencewooden,85,0 +fencewood,85,0 +fencew,85,0 +pumpkin,86,0 +netherrack,87,0 +netherrock,87,0 +netherstone,87,0 +hellrack,87,0 +hellrock,87,0 +hellstone,87,0 +deathrack,87,0 +deathrock,87,0 +deathstone,87,0 +nrack,87,0 +nrock,87,0 +nstone,87,0 +hrack,87,0 +hrock,87,0 +hstone,87,0 +drack,87,0 +drock,87,0 +dstone,87,0 +soulsand,88,0 +slowsand,88,0 +slowmud,88,0 +ssand,88,0 +smud,88,0 +mud,88,0 +glowstone,89,0 +glowingstoneblock,89,0 +lightstoneblock,89,0 +glowstoneblock,89,0 +blockglowingstone,89,0 +blocklightstone,89,0 +blockglowstone,89,0 +glowingstone,89,0 +lightstone,89,0 +glowingblock,89,0 +lightblock,89,0 +glowblock,89,0 +lstone,89,0 +gstone,89,0 +portal,90,0 +jackolantern,91,0 +pumpkinlantern,91,0 +glowingpumpkin,91,0 +lightpumpkin,91,0 +jpumpkin,91,0 +plantren,91,0 +glowpumpkin,91,0 +gpumpkin,91,0 +lpumpkin,91,0 +lockedchest,95,0 +lockchest,95,0 +jokechest,95,0 +whiteglass,95,0 +whitesglass,95,0 +whitestainedglass,95,0 +wglass,95,0 +wsglass,95,0 +wstainedglass,95,0 +sglass,95,0 +stainedglass,95,0 +orangeglass,95,1 +orangesglass,95,1 +orangestainedglass,95,1 +oglass,95,1 +osglass,95,1 +ostainedglass,95,1 +magentaglass,95,2 +magentasglass,95,2 +magentastainedglass,95,2 +mglass,95,2 +msglass,95,2 +mstainedglass,95,2 +lightblueglass,95,3 +lightbluesglass,95,3 +lightbluestainedglass,95,3 +lblueglass,95,3 +lbluesglass,95,3 +lbluestainedglass,95,3 +lightbluglass,95,3 +lightblusglass,95,3 +lightblustainedglass,95,3 +lbluglass,95,3 +lblusglass,95,3 +lblustainedglass,95,3 +lbglass,95,3 +lbsglass,95,3 +lbstainedglass,95,3 +yellowglass,95,4 +yellowsglass,95,4 +yellowstainedglass,95,4 +yglass,95,4 +ysglass,95,4 +ystainedglass,95,4 +lightgreenglass,95,5 +lightgreensglass,95,5 +lightgreenstainedglass,95,5 +lgreenglass,95,5 +lgreensglass,95,5 +lgreenstainedglass,95,5 +lightgreglass,95,5 +lightgresglass,95,5 +lightgrestainedglass,95,5 +lgreglass,95,5 +lgresglass,95,5 +lgrestainedglass,95,5 +limeglass,95,5 +limesglass,95,5 +limestainedglass,95,5 +lglass,95,5 +lsglass,95,5 +lstainedglass,95,5 +pinkglass,95,6 +pinksglass,95,6 +pinkstainedglass,95,6 +piglass,95,6 +pisglass,95,6 +pistainedglass,95,6 +darkgrayglass,95,7 +darkgraysglass,95,7 +darkgraystainedglass,95,7 +dgrayglass,95,7 +dgraysglass,95,7 +dgraystainedglass,95,7 +darkgreyglass,95,7 +darkgreysglass,95,7 +darkgreystainedglass,95,7 +dgreyglass,95,7 +dgreysglass,95,7 +dgreystainedglass,95,7 +darkgraglass,95,7 +darkgrasglass,95,7 +darkgrastainedglass,95,7 +dgraglass,95,7 +dgrasglass,95,7 +dgrastainedglass,95,7 +grayglass,95,7 +graysglass,95,7 +graystainedglass,95,7 +greyglass,95,7 +greysglass,95,7 +greystainedglass,95,7 +graglass,95,7 +grasglass,95,7 +grastainedglass,95,7 +lightgrayglass,95,8 +lightgraysglass,95,8 +lightgraystainedglass,95,8 +lgrayglass,95,8 +lgraysglass,95,8 +lgraystainedglass,95,8 +lightgreyglass,95,8 +lightgreysglass,95,8 +lightgreystainedglass,95,8 +lgreyglass,95,8 +lgreysglass,95,8 +lgreystainedglass,95,8 +lightgraglass,95,8 +lightgrasglass,95,8 +lightgrastainedglass,95,8 +lgraglass,95,8 +lgrasglass,95,8 +lgrastainedglass,95,8 +silverglass,95,8 +silversglass,95,8 +silverstainedglass,95,8 +siglass,95,8 +siasglass,95,8 +siastainedglass,95,8 +cyanglass,95,9 +cyansglass,95,9 +cyanstainedglass,95,9 +cglass,95,9 +csglass,95,9 +cstainedglass,95,9 +purpleglass,95,10 +purplesglass,95,10 +purplestainedglass,95,10 +puglass,95,10 +pusglass,95,10 +pustainedglass,95,10 +blueglass,95,11 +bluesglass,95,11 +bluestainedglass,95,11 +bluglass,95,11 +blusglass,95,11 +blustainedglass,95,11 +brownglass,95,12 +brownsglass,95,12 +brownstainedglass,95,12 +broglass,95,12 +brosglass,95,12 +brostainedglass,95,12 +darkgreenglass,95,13 +darkgreensglass,95,13 +darkgreenstainedglass,95,13 +dgreenglass,95,13 +dgreensglass,95,13 +dgreenstainedglass,95,13 +greenglass,95,13 +greensglass,95,13 +greenstainedglass,95,13 +darkgreglass,95,13 +darkgresglass,95,13 +darkgrestainedglass,95,13 +dgreglass,95,13 +dgresglass,95,13 +dgrestainedglass,95,13 +greglass,95,13 +gresglass,95,13 +grestainedglass,95,13 +redglass,95,14 +redsglass,95,14 +redstainedglass,95,14 +rglass,95,14 +rsglass,95,14 +rstainedglass,95,14 +blackglass,95,15 +blacksglass,95,15 +blackstainedglass,95,15 +blaglass,95,15 +blasglass,95,15 +blastainedglass,95,15 +trapdoor,96,0 +doortrap,96,0 +hatch,96,0 +tdoor,96,0 +doort,96,0 +trapd,96,0 +dtrap,96,0 +silverfish,97,0 +silverfishsmoothstone,97,0 +silverfishsstone,97,0 +sfishsmoothstone,97,0 +sfishsstone,97,0 +fishsmoothstone,97,0 +fishsstone,97,0 +sfsmoothstone,97,0 +sfsstone,97,0 +trapsmoothstone,97,0 +trapsstone,97,0 +monsteregg,97,0 +monstereggsmoothstone,97,0 +monstereggsstone,97,0 +meggsmoothstone,97,0 +meggsstone,97,0 +mesmoothstone,97,0 +messtone,97,0 +silverfishcobblestone,97,1 +silverfishcstone,97,1 +sfishcobblestone,97,1 +sfishcstone,97,1 +fishcobblestone,97,1 +fishcstone,97,1 +sfcobblestone,97,1 +sfcstone,97,1 +trapcobblestone,97,1 +trapcstone,97,1 +monstereggcobblestone,97,1 +monstereggcstone,97,1 +meggcobblestone,97,1 +meggcstone,97,1 +mecobblestone,97,1 +mecstone,97,1 +silverfishstonebrick,97,2 +silverfishsbrick,97,2 +sfishstonebrick,97,2 +sfishsbrick,97,2 +fishstonebrick,97,2 +fishsbrick,97,2 +sfstonebrick,97,2 +sfsbrick,97,2 +trapstonebrick,97,2 +trapsbrick,97,2 +monstereggstonebrick,97,2 +monstereggsbrick,97,2 +meggstonebrick,97,2 +meggsbrick,97,2 +mestonebrick,97,2 +mesbrick,97,2 +silverfishmossystonebrick,97,3 +silverfishmossstonebrick,97,3 +silverfishmstonebrick,97,3 +silverfishmsbrick,97,3 +sfishmossystonebrick,97,3 +sfishmossstonebrick,97,3 +sfishmstonebrick,97,3 +sfishmsbrick,97,3 +fishmossystonebrick,97,3 +fishmossstonebrick,97,3 +fishmstonebrick,97,3 +fishmsbrick,97,3 +sfmossystonebrick,97,3 +sfmossstonebrick,97,3 +sfmstonebrick,97,3 +sfmsbrick,97,3 +trapmossystonebrick,97,3 +trapmossstonebrick,97,3 +trapmstonebrick,97,3 +trapmsbrick,97,3 +monstereggmossystonebrick,97,3 +monstereggmossstonebrick,97,3 +monstereggmstonebrick,97,3 +monstereggmsbrick,97,3 +meggmossystonebrick,97,3 +meggmossstonebrick,97,3 +meggmstonebrick,97,3 +meggmsbrick,97,3 +memossystonebrick,97,3 +memossstonebrick,97,3 +memstonebrick,97,3 +memsbrick,97,3 +silverfishcrackedstonebrick,97,4 +silverfishcrackstonebrick,97,4 +silverfishcrstonebrick,97,4 +silverfishcrsbrick,97,4 +sfishcrackedstonebrick,97,4 +sfishcrackstonebrick,97,4 +sfishcrstonebrick,97,4 +sfishcrsbrick,97,4 +fishcrackedstonebrick,97,4 +fishcrackstonebrick,97,4 +fishcrstonebrick,97,4 +fishcrsbrick,97,4 +sfcrackedstonebrick,97,4 +sfcrackstonebrick,97,4 +sfcrstonebrick,97,4 +sfcrsbrick,97,4 +trapcrackedstonebrick,97,4 +trapcrackstonebrick,97,4 +trapcrstonebrick,97,4 +trapcrsbrick,97,4 +monstereggcrackedstonebrick,97,4 +monstereggcrackstonebrick,97,4 +monstereggcrstonebrick,97,4 +monstereggcrsbrick,97,4 +meggcrackedstonebrick,97,4 +meggcrackstonebrick,97,4 +meggcrstonebrick,97,4 +meggcrsbrick,97,4 +mecrackedstonebrick,97,4 +mecrackstonebrick,97,4 +mecrstonebrick,97,4 +mecrsbrick,97,4 +silverfishcirclestonebrick,97,5 +silverfishcistonebrick,97,5 +silverfishcisbrick,97,5 +sfishcirclestonebrick,97,5 +sfishcistonebrick,97,5 +sfishcisbrick,97,5 +fishcirclestonebrick,97,5 +fishcistonebrick,97,5 +fishcisbrick,97,5 +sfcirclestonebrick,97,5 +sfcistonebrick,97,5 +sfcisbrick,97,5 +trapcirclestonebrick,97,5 +trapcistonebrick,97,5 +trapcisbrick,97,5 +monstereggcirclestonebrick,97,5 +monstereggcistonebrick,97,5 +monstereggcisbrick,97,5 +meggcirclestonebrick,97,5 +meggcistonebrick,97,5 +meggcisbrick,97,5 +mecirclestonebrick,97,5 +mecistonebrick,97,5 +mecisbrick,97,5 +stonebrick,98,0 +stonebricks,98,0 +stonebrickblock,98,0 +stonebb,98,0 +sbrick,98,0 +mossystonebrick,98,1 +mossystonebricks,98,1 +mossystonebrickblock,98,1 +mossystonebb,98,1 +mossstonebrick,98,1 +mossstonebricks,98,1 +mossstonebrickblock,98,1 +mossstonebb,98,1 +mstonebrick,98,1 +mstonebricks,98,1 +mstonebrickblock,98,1 +mstonebb,98,1 +mosssbrick,98,1 +mosssbricks,98,1 +mosssbrickblock,98,1 +mosssbb,98,1 +msbrick,98,1 +msbricks,98,1 +msbrickblock,98,1 +crackedstone,98,2 +crackedstonebrick,98,2 +crackedstonebricks,98,2 +crackedstonebrickblock,98,2 +crackedstonebb,98,2 +crackstonebrick,98,2 +crackstonebricks,98,2 +crackstonebrickblock,98,2 +crackstonebb,98,2 +crstonebrick,98,2 +crstonebricks,98,2 +crstonebrickblock,98,2 +crstonebb,98,2 +cracksbrick,98,2 +cracksbricks,98,2 +cracksbrickblock,98,2 +cracksbb,98,2 +crsbrick,98,2 +crsbricks,98,2 +crsbrickblock,98,2 +circlestone,98,3 +circlestonebrick,98,3 +circlestonebricks,98,3 +circlestonebrickblock,98,3 +circlestonebb,98,3 +cistonebrick,98,3 +cistonebricks,98,3 +cistonebrickblock,98,3 +cistonebb,98,3 +circlesbrick,98,3 +circlesbricks,98,3 +circlesbrickblock,98,3 +circlesbb,98,3 +cisbrick,98,3 +cisbricks,98,3 +cisbrickblock,98,3 +giantredmushroom,99,0 +hugeredmushroom,99,0 +bigredmushroom,99,0 +gredmushroom,99,0 +hredmushroom,99,0 +bredmushroom,99,0 +giantrmushroom,99,0 +hugermushroom,99,0 +bigrmushroom,99,0 +grmushroom,99,0 +hrmushroom,99,0 +brmushroom,99,0 +giantredmush,99,0 +hugeredmush,99,0 +bigredmush,99,0 +gredmush,99,0 +hredmush,99,0 +bredmush,99,0 +giantrmush,99,0 +hugermush,99,0 +bigrmush,99,0 +grmush,99,0 +hrmush,99,0 +brmush,99,0 +giantbrownmushroom,100,0 +hugebrownmushroom,100,0 +bigbrownmushroom,100,0 +gbrownmushroom,100,0 +hbrownmushroom,100,0 +bbrownmushroom,100,0 +giantbmushroom,100,0 +hugebmushroom,100,0 +bigbmushroom,100,0 +gbmushroom,100,0 +hbmushroom,100,0 +bbmushroom,100,0 +giantbrownmush,100,0 +hugebrownmush,100,0 +bigbrownmush,100,0 +gbrownmush,100,0 +hbrownmush,100,0 +bbrownmush,100,0 +giantbmush,100,0 +hugebmush,100,0 +bigbmush,100,0 +gbmush,100,0 +hbmush,100,0 +bbmush,100,0 +ironbars,101,0 +ironbarsb,101,0 +ironbarsblock,101,0 +ironfence,101,0 +metalbars,101,0 +metalbarsb,101,0 +metalbarsblock,101,0 +metalfence,101,0 +jailbars,101,0 +jailbarsb,101,0 +jailbarsblock,101,0 +jailfence,101,0 +mbars,101,0 +mbarsb,101,0 +mbarsblock,101,0 +mfence,101,0 +jbars,101,0 +jbarsb,101,0 +jbarsblock,101,0 +jfence,101,0 +ibars,101,0 +ibarsb,101,0 +ibarsblock,101,0 +ifence,101,0 +glasspane,102,0 +glassp,102,0 +paneglass,102,0 +pglass,102,0 +flatglass,102,0 +fglass,102,0 +skinnyglass,102,0 +glassflat,102,0 +glassf,102,0 +glassskinny,102,0 +glasss,102,0 +melon,103,0 +watermelon,103,0 +greenmelon,103,0 +melongreen,103,0 +melonblock,103,0 +watermelonblock,103,0 +greenmelonblock,103,0 +vines,106,0 +vine,106,0 +greenvines,106,0 +greenvine,106,0 +gardenvines,106,0 +gardenvine,106,0 +vinesgreen,106,0 +vinegreen,106,0 +vinesgarden,106,0 +vinegarden,106,0 +vinesg,106,0 +vineg,106,0 +gvines,106,0 +gvine,106,0 +woodgate,107,0 +woodenfencegate,107,0 +wfencegate,107,0 +woodfencegate,107,0 +woodengate,107,0 +wgate,107,0 +gate,107,0 +gardengate,107,0 +ggate,107,0 +fencegate,107,0 +fgate,107,0 +brickstairs,108,0 +redbrickstairs,108,0 +redbstairs,108,0 +rbrickstairs,108,0 +bstairs,108,0 +redstairs,108,0 +brickstair,108,0 +redbrickstair,108,0 +redbstair,108,0 +rbrickstair,108,0 +bstair,108,0 +redstair,108,0 +stonebrickstairs,109,0 +stonebstairs,109,0 +sbstairs,109,0 +cementbrickstairs,109,0 +cementstairs,109,0 +cementbstairs,109,0 +cbstairs,109,0 +greybrickstairs,109,0 +greybstairs,109,0 +greystairs,109,0 +mycelium,110,0 +purplegrass,110,0 +pinkgrass,110,0 +mycel,110,0 +swampgrass,110,0 +sgrass,110,0 +mushroomgrass,110,0 +mushgrass,110,0 +lilypad,111,0 +waterlily,111,0 +lily,111,0 +swamppad,111,0 +lpad,111,0 +wlily,111,0 +netherbrickblock,112,0 +hellbrickblock,112,0 +deathbrickblock,112,0 +nbrickblock,112,0 +hbrickblock,112,0 +dbrickblock,112,0 +netherbblock,112,0 +hellbblock,112,0 +deathbblock,112,0 +nbblock,112,0 +hbblock,112,0 +dbblock,112,0 +netherbrickfence,113,0 +hellbrickfence,113,0 +nbrickfence,113,0 +hbrickfence,113,0 +netherbfence,113,0 +hellbfence,113,0 +netherfence,113,0 +hellfence,113,0 +nbfence,113,0 +hbfence,113,0 +nfence,113,0 +hfence,113,0 +netherbrickstairs,114,0 +hellbrickstairs,114,0 +nbrickstairs,114,0 +hbrickstairs,114,0 +netherbstairs,114,0 +hellbstairs,114,0 +netherstairs,114,0 +hellstairs,114,0 +nbstairs,114,0 +hbstairs,114,0 +nstairs,114,0 +hstairs,114,0 +netherbrickstair,114,0 +hellbrickstair,114,0 +nbrickstair,114,0 +hbrickstair,114,0 +netherbstair,114,0 +hellbstair,114,0 +netherstair,114,0 +hellstair,114,0 +nbstair,114,0 +hbstair,114,0 +nstair,114,0 +hstair,114,0 +enchantmenttable,116,0 +enchantingtable,116,0 +enchanttable,116,0 +etable,116,0 +magicaltable,116,0 +magictable,116,0 +mtable,116,0 +enchantmentdesk,116,0 +enchantingdesk,116,0 +enchantdesk,116,0 +edesk,116,0 +magicaldesk,116,0 +magicdesk,116,0 +mdesk,116,0 +booktable,116,0 +bookdesk,116,0 +btable,116,0 +bdesk,116,0 +enderportal,119,0 +endergoo,119,0 +endgoo,119,0 +endportal,119,0 +egoo,119,0 +eportal,119,0 +enderportalframe,120,0 +endportalframe,120,0 +endgooframe,120,0 +endergooframe,120,0 +egooframe,120,0 +eportalframe,120,0 +enderframe,120,0 +endframe,120,0 +enderstone,121,0 +endstone,121,0 +endrock,121,0 +enderrock,121,0 +erock,121,0 +estone,121,0 +enderdragonegg,122,0 +endegg,122,0 +dragonegg,122,0 +degg,122,0 +bossegg,122,0 +begg,122,0 +redstonelamp,123,0 +redlamp,123,0 +rslamp,123,0 +woodendoublestep,125,0 +woodendstep,125,0 +wooddoublestep,125,0 +wooddstep,125,0 +wdoublestep,125,0 +wdstep,125,0 +doublewoodenstep,125,0 +dwoodenstep,125,0 +doublewoodstep,125,0 +dwoodstep,125,0 +doublewstep,125,0 +dwstep,125,0 +woodendoubleslab,125,0 +woodendslab,125,0 +wooddoubleslab,125,0 +wooddslab,125,0 +wdoubleslab,125,0 +wdslab,125,0 +doublewoodenslab,125,0 +dwoodenslab,125,0 +doublewoodslab,125,0 +dwoodslab,125,0 +doublewslab,125,0 +dwslab,125,0 +woodendoublehalfblock,125,0 +woodendhalfblock,125,0 +wooddoublehalfblock,125,0 +wooddhalfblock,125,0 +wdoublehalfblock,125,0 +wdhalfblock,125,0 +doublewoodenhalfblock,125,0 +dwoodenhalfblock,125,0 +doublewoodhalfblock,125,0 +dwoodhalfblock,125,0 +doublewhalfblock,125,0 +dwhalfblock,125,0 +oakwoodendoublehalfblock,125,0 +oakwoodendhalfblock,125,0 +oakwooddoublehalfblock,125,0 +oakwooddhalfblock,125,0 +oakwdoublehalfblock,125,0 +oakwdhalfblock,125,0 +oakdoublewoodenhalfblock,125,0 +oakdwoodenhalfblock,125,0 +oakdoublewoodhalfblock,125,0 +oakdwoodhalfblock,125,0 +oakdoublewhalfblock,125,0 +oakdwhalfblock,125,0 +oakdoublehalfblock,125,0 +oakdhalfblock,125,0 +odhalfblock,125,0 +oakwoodendoublestep,125,0 +oakwoodendstep,125,0 +oakwooddoublestep,125,0 +oakwooddstep,125,0 +oakwdoublestep,125,0 +oakwdstep,125,0 +oakdoublewoodenstep,125,0 +oakdwoodenstep,125,0 +oakdoublewoodstep,125,0 +oakdwoodstep,125,0 +oakdoublewstep,125,0 +oakdwstep,125,0 +oakdoublestep,125,0 +oakdstep,125,0 +odstep,125,0 +oakwoodendoubleslab,125,0 +oakwoodendslab,125,0 +oakwooddoubleslab,125,0 +oakwooddslab,125,0 +oakwdoubleslab,125,0 +oakwdslab,125,0 +oakdoublewoodenslab,125,0 +oakdwoodenslab,125,0 +oakdoublewoodslab,125,0 +oakdwoodslab,125,0 +oakdoublewslab,125,0 +oakdwslab,125,0 +oakdoubleslab,125,0 +oakdslab,125,0 +odslab,125,0 +sprucewoodendoublestep,125,1 +sprucewoodendstep,125,1 +sprucewooddoublestep,125,1 +sprucewooddstep,125,1 +sprucewdoublestep,125,1 +sprucewdstep,125,1 +sprucedoublewoodenstep,125,1 +sprucedwoodenstep,125,1 +sprucedoublewoodstep,125,1 +sprucedwoodstep,125,1 +sprucedoublewstep,125,1 +sprucedwstep,125,1 +sprucedoublestep,125,1 +sprucedstep,125,1 +sprucewoodendoubleslab,125,1 +sprucewoodendslab,125,1 +sprucewooddoubleslab,125,1 +sprucewooddslab,125,1 +sprucewdoubleslab,125,1 +sprucewdslab,125,1 +sprucedoublewoodenslab,125,1 +sprucedwoodenslab,125,1 +sprucedoublewoodslab,125,1 +sprucedwoodslab,125,1 +sprucedoublewslab,125,1 +sprucedwslab,125,1 +sprucedoubleslab,125,1 +sprucedslab,125,1 +sprucewoodendoublehalfblock,125,1 +sprucewoodendhalfblock,125,1 +sprucewooddoublehalfblock,125,1 +sprucewooddhalfblock,125,1 +sprucewdoublehalfblock,125,1 +sprucewdhalfblock,125,1 +sprucedoublewoodenhalfblock,125,1 +sprucedwoodenhalfblock,125,1 +sprucedoublewoodhalfblock,125,1 +sprucedwoodhalfblock,125,1 +sprucedoublewhalfblock,125,1 +sprucedwhalfblock,125,1 +sprucedoublehalfblock,125,1 +sprucedhalfblock,125,1 +darkwoodendoublestep,125,1 +darkwoodendstep,125,1 +darkwooddoublestep,125,1 +darkwooddstep,125,1 +darkwdoublestep,125,1 +darkwdstep,125,1 +darkdoublewoodenstep,125,1 +darkdwoodenstep,125,1 +darkdoublewoodstep,125,1 +darkdwoodstep,125,1 +darkdoublewstep,125,1 +darkdwstep,125,1 +darkdoublestep,125,1 +darkdstep,125,1 +ddstep,125,1 +darkwoodendoubleslab,125,1 +darkwoodendslab,125,1 +darkwooddoubleslab,125,1 +darkwooddslab,125,1 +darkwdoubleslab,125,1 +darkwdslab,125,1 +darkdoublewoodenslab,125,1 +darkdwoodenslab,125,1 +darkdoublewoodslab,125,1 +darkdwoodslab,125,1 +darkdoublewslab,125,1 +darkdwslab,125,1 +darkdoubleslab,125,1 +darkdslab,125,1 +ddslab,125,1 +darkwoodendoublehalfblock,125,1 +darkwoodendhalfblock,125,1 +darkwooddoublehalfblock,125,1 +darkwooddhalfblock,125,1 +darkwdoublehalfblock,125,1 +darkwdhalfblock,125,1 +darkdoublewoodenhalfblock,125,1 +darkdwoodenhalfblock,125,1 +darkdoublewoodhalfblock,125,1 +darkdwoodhalfblock,125,1 +darkdoublewhalfblock,125,1 +darkdwhalfblock,125,1 +darkdoublehalfblock,125,1 +darkdhalfblock,125,1 +ddhalfblock,125,1 +birchwoodendoublestep,125,2 +birchwoodendstep,125,2 +birchwooddoublestep,125,2 +birchwooddstep,125,2 +birchwdoublestep,125,2 +birchwdstep,125,2 +birchdoublewoodenstep,125,2 +birchdwoodenstep,125,2 +birchdoublewoodstep,125,2 +birchdwoodstep,125,2 +birchdoublewstep,125,2 +birchdwstep,125,2 +birchdoublestep,125,2 +birchdstep,125,2 +birchwoodendoubleslab,125,2 +birchwoodendslab,125,2 +birchwooddoubleslab,125,2 +birchwooddslab,125,2 +birchwdoubleslab,125,2 +birchwdslab,125,2 +birchdoublewoodenslab,125,2 +birchdwoodenslab,125,2 +birchdoublewoodslab,125,2 +birchdwoodslab,125,2 +birchdoublewslab,125,2 +birchdwslab,125,2 +birchdoubleslab,125,2 +birchdslab,125,2 +birchwoodendoublehalfblock,125,2 +birchwoodendhalfblock,125,2 +birchwooddoublehalfblock,125,2 +birchwooddhalfblock,125,2 +birchwdoublehalfblock,125,2 +birchwdhalfblock,125,2 +birchdoublewoodenhalfblock,125,2 +birchdwoodenhalfblock,125,2 +birchdoublewoodhalfblock,125,2 +birchdwoodhalfblock,125,2 +birchdoublewhalfblock,125,2 +birchdwhalfblock,125,2 +birchdoublehalfblock,125,2 +birchdhalfblock,125,2 +lightwoodendoublehalfblock,125,2 +lightwoodendhalfblock,125,2 +lightwooddoublehalfblock,125,2 +lightwooddhalfblock,125,2 +lightwdoublehalfblock,125,2 +lightwdhalfblock,125,2 +lightdoublewoodenhalfblock,125,2 +lightdwoodenhalfblock,125,2 +lightdoublewoodhalfblock,125,2 +lightdwoodhalfblock,125,2 +lightdoublewhalfblock,125,2 +lightdwhalfblock,125,2 +lightdoublehalfblock,125,2 +lightdhalfblock,125,2 +ldhalfblock,125,2 +lightwoodendoublestep,125,2 +lightwoodendstep,125,2 +lightwooddoublestep,125,2 +lightwooddstep,125,2 +lightwdoublestep,125,2 +lightwdstep,125,2 +lightdoublewoodenstep,125,2 +lightdwoodenstep,125,2 +lightdoublewoodstep,125,2 +lightdwoodstep,125,2 +lightdoublewstep,125,2 +lightdwstep,125,2 +lightdoublestep,125,2 +lightdstep,125,2 +ldstep,125,2 +lightwoodendoubleslab,125,2 +lightwoodendslab,125,2 +lightwooddoubleslab,125,2 +lightwooddslab,125,2 +lightwdoubleslab,125,2 +lightwdslab,125,2 +lightdoublewoodenslab,125,2 +lightdwoodenslab,125,2 +lightdoublewoodslab,125,2 +lightdwoodslab,125,2 +lightdoublewslab,125,2 +lightdwslab,125,2 +lightdoubleslab,125,2 +lightdslab,125,2 +ldslab,125,2 +junglewoodendoublestep,125,3 +junglewoodendstep,125,3 +junglewooddoublestep,125,3 +junglewooddstep,125,3 +junglewdoublestep,125,3 +junglewdstep,125,3 +jungledoublewoodenstep,125,3 +jungledwoodenstep,125,3 +jungledoublewoodstep,125,3 +jungledwoodstep,125,3 +jungledoublewstep,125,3 +jungledwstep,125,3 +jungledoublestep,125,3 +jungledstep,125,3 +jdstep,125,3 +junglewoodendoubleslab,125,3 +junglewoodendslab,125,3 +junglewooddoubleslab,125,3 +junglewooddslab,125,3 +junglewdoubleslab,125,3 +junglewdslab,125,3 +jungledoublewoodenslab,125,3 +jungledwoodenslab,125,3 +jungledoublewoodslab,125,3 +jungledwoodslab,125,3 +jungledoublewslab,125,3 +jungledwslab,125,3 +jungledoubleslab,125,3 +jungledslab,125,3 +jdslab,125,3 +junglewoodendoublehalfblock,125,3 +junglewoodendhalfblock,125,3 +junglewooddoublehalfblock,125,3 +junglewooddhalfblock,125,3 +junglewdoublehalfblock,125,3 +junglewdhalfblock,125,3 +jungledoublewoodenhalfblock,125,3 +jungledwoodenhalfblock,125,3 +jungledoublewoodhalfblock,125,3 +jungledwoodhalfblock,125,3 +jungledoublewhalfblock,125,3 +jungledwhalfblock,125,3 +jungledoublehalfblock,125,3 +jungledhalfblock,125,3 +jdhalfblock,125,3 +forestwoodendoublehalfblock,125,3 +forestwoodendhalfblock,125,3 +forestwooddoublehalfblock,125,3 +forestwooddhalfblock,125,3 +forestwdoublehalfblock,125,3 +forestwdhalfblock,125,3 +forestdoublewoodenhalfblock,125,3 +forestdwoodenhalfblock,125,3 +forestdoublewoodhalfblock,125,3 +forestdwoodhalfblock,125,3 +forestdoublewhalfblock,125,3 +forestdwhalfblock,125,3 +forestdoublehalfblock,125,3 +forestdhalfblock,125,3 +fdhalfblock,125,3 +forestwoodendoublestep,125,3 +forestwoodendstep,125,3 +forestwooddoublestep,125,3 +forestwooddstep,125,3 +forestwdoublestep,125,3 +forestwdstep,125,3 +forestdoublewoodenstep,125,3 +forestdwoodenstep,125,3 +forestdoublewoodstep,125,3 +forestdwoodstep,125,3 +forestdoublewstep,125,3 +forestdwstep,125,3 +forestdoublestep,125,3 +forestdstep,125,3 +fdstep,125,3 +forestwoodendoubleslab,125,3 +forestwoodendslab,125,3 +forestwooddoubleslab,125,3 +forestwooddslab,125,3 +forestwdoubleslab,125,3 +forestwdslab,125,3 +forestdoublewoodenslab,125,3 +forestdwoodenslab,125,3 +forestdoublewoodslab,125,3 +forestdwoodslab,125,3 +forestdoublewslab,125,3 +forestdwslab,125,3 +forestdoubleslab,125,3 +forestdslab,125,3 +fdslab,125,3 +acaciawoodendoublestep,125,4 +acaciawoodendstep,125,4 +acaciawooddoublestep,125,4 +acaciawooddstep,125,4 +acaciawdoublestep,125,4 +acaciawdstep,125,4 +acaciadoublewoodenstep,125,4 +acaciadwoodenstep,125,4 +acaciadoublewoodstep,125,4 +acaciadwoodstep,125,4 +acaciadoublewstep,125,4 +acaciadwstep,125,4 +acaciadoublestep,125,4 +acaciadstep,125,4 +adstep,125,4 +acaciawoodendoubleslab,125,4 +acaciawoodendslab,125,4 +acaciawooddoubleslab,125,4 +acaciawooddslab,125,4 +acaciawdoubleslab,125,4 +acaciawdslab,125,4 +acaciadoublewoodenslab,125,4 +acaciadwoodenslab,125,4 +acaciadoublewoodslab,125,4 +acaciadwoodslab,125,4 +acaciadoublewslab,125,4 +acaciadwslab,125,4 +acaciadoubleslab,125,4 +acaciadslab,125,4 +adslab,125,4 +acaciawoodendoublehalfblock,125,4 +acaciawoodendhalfblock,125,4 +acaciawooddoublehalfblock,125,4 +acaciawooddhalfblock,125,4 +acaciawdoublehalfblock,125,4 +acaciawdhalfblock,125,4 +acaciadoublewoodenhalfblock,125,4 +acaciadwoodenhalfblock,125,4 +acaciadoublewoodhalfblock,125,4 +acaciadwoodhalfblock,125,4 +acaciadoublewhalfblock,125,4 +acaciadwhalfblock,125,4 +acaciadoublehalfblock,125,4 +acaciadhalfblock,125,4 +adhalfblock,125,4 +darkoakwoodendoublehalfblock,125,5 +darkoakwoodendhalfblock,125,5 +darkoakwooddoublehalfblock,125,5 +darkoakwooddhalfblock,125,5 +darkoakwdoublehalfblock,125,5 +darkoakwdhalfblock,125,5 +darkoakdoublewoodenhalfblock,125,5 +darkoakdwoodenhalfblock,125,5 +darkoakdoublewoodhalfblock,125,5 +darkoakdwoodhalfblock,125,5 +darkoakdoublewhalfblock,125,5 +darkoakdwhalfblock,125,5 +darkoakdoublehalfblock,125,5 +darkoakdhalfblock,125,5 +dodhalfblock,125,5 +darkoakwoodendoublestep,125,5 +darkoakwoodendstep,125,5 +darkoakwooddoublestep,125,5 +darkoakwooddstep,125,5 +darkoakwdoublestep,125,5 +darkoakwdstep,125,5 +darkoakdoublewoodenstep,125,5 +darkoakdwoodenstep,125,5 +darkoakdoublewoodstep,125,5 +darkoakdwoodstep,125,5 +darkoakdoublewstep,125,5 +darkoakdwstep,125,5 +darkoakdoublestep,125,5 +darkoakdstep,125,5 +dodstep,125,5 +darkoakwoodendoubleslab,125,5 +darkoakwoodendslab,125,5 +darkoakwooddoubleslab,125,5 +darkoakwooddslab,125,5 +darkoakwdoubleslab,125,5 +darkoakwdslab,125,5 +darkoakdoublewoodenslab,125,5 +darkoakdwoodenslab,125,5 +darkoakdoublewoodslab,125,5 +darkoakdwoodslab,125,5 +darkoakdoublewslab,125,5 +darkoakdwslab,125,5 +darkoakdoubleslab,125,5 +darkoakdslab,125,5 +dodslab,125,5 +woodenstep,126,0 +woodstep,126,0 +wstep,126,0 +woodenslab,126,0 +woodslab,126,0 +wslab,126,0 +woodenhalfblock,126,0 +woodhalfblock,126,0 +whalfblock,126,0 +oakwoodenstep,126,0 +oakwoodstep,126,0 +oakwstep,126,0 +oakstep,126,0 +ostep,126,0 +oakwoodenslab,126,0 +oakwoodslab,126,0 +oakwslab,126,0 +oakslab,126,0 +oslab,126,0 +oakwoodenhalfblock,126,0 +oakwoodhalfblock,126,0 +oakwhalfblock,126,0 +oakhalfblock,126,0 +ohalfblock,126,0 +sprucewoodenstep,126,1 +sprucewoodstep,126,1 +sprucewstep,126,1 +sprucestep,126,1 +sprucewoodenslab,126,1 +sprucewoodslab,126,1 +sprucewslab,126,1 +spruceslab,126,1 +sprucewoodenhalfblock,126,1 +sprucewoodhalfblock,126,1 +sprucewhalfblock,126,1 +sprucehalfblock,126,1 +darkwoodenstep,126,1 +darkwoodstep,126,1 +darkwstep,126,1 +darkstep,126,1 +darkwoodenslab,126,1 +darkwoodslab,126,1 +darkwslab,126,1 +darkslab,126,1 +darkwoodenhalfblock,126,1 +darkwoodhalfblock,126,1 +darkwhalfblock,126,1 +darkhalfblock,126,1 +birchwoodenstep,126,2 +birchwoodstep,126,2 +birchwstep,126,2 +birchstep,126,2 +birchwoodenslab,126,2 +birchwoodslab,126,2 +birchwslab,126,2 +birchslab,126,2 +birchwoodenhalfblock,126,2 +birchwoodhalfblock,126,2 +birchwhalfblock,126,2 +birchhalfblock,126,2 +lightwoodenstep,126,2 +lightwoodstep,126,2 +lightwstep,126,2 +lightstep,126,2 +lstep,126,2 +lightwoodenslab,126,2 +lightwoodslab,126,2 +lightwslab,126,2 +lightslab,126,2 +lslab,126,2 +lightwoodenhalfblock,126,2 +lightwoodhalfblock,126,2 +lightwhalfblock,126,2 +lighthalfblock,126,2 +lhalfblock,126,2 +junglewoodenstep,126,3 +junglewoodstep,126,3 +junglewstep,126,3 +junglestep,126,3 +jstep,126,3 +junglewoodenslab,126,3 +junglewoodslab,126,3 +junglewslab,126,3 +jungleslab,126,3 +jslab,126,3 +junglewoodenhalfblock,126,3 +junglewoodhalfblock,126,3 +junglewhalfblock,126,3 +junglehalfblock,126,3 +jhalfblock,126,3 +forestwoodenstep,126,3 +forestwoodstep,126,3 +forestwstep,126,3 +foreststep,126,3 +fstep,126,3 +forestwoodenslab,126,3 +forestwoodslab,126,3 +forestwslab,126,3 +forestslab,126,3 +fslab,126,3 +forestwoodenhalfblock,126,3 +forestwoodhalfblock,126,3 +forestwhalfblock,126,3 +foresthalfblock,126,3 +fhalfblock,126,3 +acaciawoodenstep,126,4 +acaciawoodstep,126,4 +acaciawstep,126,4 +acaciastep,126,4 +astep,126,4 +acaciawoodenslab,126,4 +acaciawoodslab,126,4 +acaciawslab,126,4 +acaciaslab,126,4 +aslab,126,4 +acaciawoodenhalfblock,126,4 +acaciawoodhalfblock,126,4 +acaciawhalfblock,126,4 +acaciahalfblock,126,4 +ahalfblock,126,4 +darkoakwoodenstep,126,5 +darkoakwoodstep,126,5 +darkoakwstep,126,5 +darkoakstep,126,5 +dostep,126,5 +darkoakwoodenslab,126,5 +darkoakwoodslab,126,5 +darkoakwslab,126,5 +darkoakslab,126,5 +doslab,126,5 +darkoakwoodenhalfblock,126,5 +darkoakwoodhalfblock,126,5 +darkoakwhalfblock,126,5 +darkoakhalfblock,126,5 +dohalfblock,126,5 +cocoaplant,127,0 +cocoplant,127,0 +cplant,127,0 +cocoafruit,127,0 +cocofruit,127,0 +cfruit,127,0 +cocoapod,127,0 +cocopod,127,0 +cpod,127,0 +sandstonestairs,128,0 +sandstairs,128,0 +sandsstairs,128,0 +sstonestairs,128,0 +ssstairs,128,0 +sandstair,128,0 +sandstonestair,128,0 +sandsstair,128,0 +sstonestair,128,0 +ssstair,128,0 +emeraldore,129,0 +eore,129,0 +oreemerald,129,0 +oree,129,0 +enderchest,130,0 +endchest,130,0 +echest,130,0 +chestender,130,0 +chestend,130,0 +cheste,130,0 +endercontainer,130,0 +endcontainer,130,0 +econtainer,130,0 +tripwirehook,131,0 +tripwire,131,0 +trip,131,0 +tripwirelever,131,0 +triphook,131,0 +emeraldblock,133,0 +blockemerald,133,0 +eblock,133,0 +blocke,133,0 +sprucewoodenstairs,134,0 +sprucewoodstairs,134,0 +sprucewstairs,134,0 +sprucestairs,134,0 +darkwoodenstairs,134,0 +darkwoodstairs,134,0 +darkwstairs,134,0 +darkstairs,134,0 +dstairs,134,0 +sprucewoodenstair,134,0 +sprucewoodstair,134,0 +sprucewstair,134,0 +sprucestair,134,0 +darkwoodenstair,134,0 +darkwoodstair,134,0 +darkwstair,134,0 +darkstair,134,0 +dstair,134,0 +birchwoodenstairs,135,0 +birchwoodstairs,135,0 +birchwstairs,135,0 +birchstairs,135,0 +lightwoodenstairs,135,0 +lightwoodstairs,135,0 +lightwstairs,135,0 +lightstairs,135,0 +lstairs,135,0 +birchwoodenstair,135,0 +birchwoodstair,135,0 +birchwstair,135,0 +birchstair,135,0 +lightwoodenstair,135,0 +lightwoodstair,135,0 +lightwstair,135,0 +lightstair,135,0 +lstair,135,0 +junglewoodenstairs,136,0 +junglewoodstairs,136,0 +junglewstairs,136,0 +junglestairs,136,0 +jstairs,136,0 +forestwoodenstairs,136,0 +forestwoodstairs,136,0 +forestwstairs,136,0 +foreststairs,136,0 +fstairs,136,0 +junglewoodenstair,136,0 +junglewoodstair,136,0 +junglewstair,136,0 +junglestair,136,0 +jstair,136,0 +forestwoodenstair,136,0 +forestwoodstair,136,0 +forestwstair,136,0 +foreststair,136,0 +fstair,136,0 +commandblock,137,0 +blockcommand,137,0 +cmdblock,137,0 +blockcmd,137,0 +macroblock,137,0 +blockmacro,137,0 +beacon,138,0 +beaconblock,138,0 +cobblestonewall,139,0 +cstonewall,139,0 +cobblewall,139,0 +cobblestonefence,139,0 +cstonefence,139,0 +cobblefence,139,0 +cswall,139,0 +csfence,139,0 +cwall,139,0 +cfence,139,0 +mosscobblestonewall,139,1 +mosscstonewall,139,1 +mosscobblewall,139,1 +mcobblestonewall,139,1 +mcstonewall,139,1 +mcobblewall,139,1 +mosscobblestonefence,139,1 +mosscstonefence,139,1 +mosscobblefence,139,1 +mcobblestonefence,139,1 +mcstonefence,139,1 +mcobblefence,139,1 +mcswall,139,0 +mcsfence,139,0 +mcwall,139,0 +mcfence,139,0 +plantedcarrot,141,0 +plantcarrot,141,0 +carrots,141,0 +growingcarrot,141,0 +potatoplant,142,0 +potatoes,142,0 +plantedpotato,142,0 +plantpotato,142,0 +growingpotato,142,0 +woodenbutton,143,0 +woodenplankbutton,143,0 +woodplankbutton,143,0 +wplankbutton,143,0 +plankbutton,143,0 +woodbutton,143,0 +wbutton,143,0 +anvil,145,0 +slightlydamagedanvil,145,1 +slightdamageanvil,145,1 +damagedanvil,145,1 +verydamagedanvil,145,2 +trapchest,146,0 +trappedchest,146,0 +chesttrapped,146,0 +chesttrap,146,0 +goldpressureplate,147,0 +weightedgoldpressureplate,147,0 +weightgoldpressureplate,147,0 +wgoldpressureplate,147,0 +weightedgoldpressplate,147,0 +weightgoldpressplate,147,0 +wgoldpressplate,147,0 +goldpressplate,147,0 +weightedgoldpplate,147,0 +weightgoldpplate,147,0 +wgoldpplate,147,0 +goldpplate,147,0 +weightedgoldplate,147,0 +weightgoldplate,147,0 +wgoldplate,147,0 +goldplate,147,0 +weightedgpressureplate,147,0 +weightgpressureplate,147,0 +wgpressureplate,147,0 +gpressureplate,147,0 +weightedgpressplate,147,0 +weightgpressplate,147,0 +wgpressplate,147,0 +gpressplate,147,0 +weightedgpplate,147,0 +weightgpplate,147,0 +wgpplate,147,0 +gpplate,147,0 +weightedgplate,147,0 +weightgplate,147,0 +wgplate,147,0 +gplate,147,0 +ironpressureplate,148,0 +weightedironpressureplate,148,0 +weightironpressureplate,148,0 +wironpressureplate,148,0 +weightedironpressplate,148,0 +weightironpressplate,148,0 +wironpressplate,148,0 +ironpressplate,148,0 +weightedironpplate,148,0 +weightironpplate,148,0 +wironpplate,148,0 +ironpplate,148,0 +weightedironplate,148,0 +weightironplate,148,0 +wironplate,148,0 +ironplate,148,0 +weightedipressureplate,148,0 +weightipressureplate,148,0 +wipressureplate,148,0 +ipressureplate,148,0 +weightedipressplate,148,0 +weightipressplate,148,0 +wipressplate,148,0 +ipressplate,148,0 +weightedipplate,148,0 +weightipplate,148,0 +wipplate,148,0 +ipplate,148,0 +weightediplate,148,0 +weightiplate,148,0 +wiplate,148,0 +iplate,148,0 +daylightsensor,151,0 +daylightsense,151,0 +lightsensor,151,0 +lightsense,151,0 +daysensor,151,0 +daysense,151,0 +timesensor,151,0 +timesense,151,0 +redstoneblock,152,0 +rstoneblock,152,0 +redsblock,152,0 +rsblock,152,0 +blockredstone,152,0 +blockrstone,152,0 +blockreds,152,0 +blockrs,152,0 +netherquartzore,153,0 +hellquartzore,153,0 +deathquartzore,153,0 +nquartzore,153,0 +hquartzore,153,0 +dquartzore,153,0 +quartzore,153,0 +netherqore,153,0 +hellqore,153,0 +deathqore,153,0 +nqore,153,0 +hqore,153,0 +dqore,153,0 +qore,153,0 +hopper,154,0 +chestpuller,154,0 +chestpull,154,0 +cheststorer,154,0 +cheststore,154,0 +itempuller,154,0 +itempull,154,0 +itemstorer,154,0 +itemstore,154,0 +quartzblock,155,0 +netherquartzblock,155,0 +nqblock,155,0 +qblock,155,0 +chiseledquartzblock,155,1 +chiselquartzblock,155,1 +cquartzblock,155,1 +cqblock,155,1 +pillarquartzblock,155,2 +pquartzblock,155,2 +pqblock,155,2 +quartzstairs,156,0 +qstairs,156,0 +quartzstair,156,0 +qstair,156,0 +activatorrails,157,0 +activaterails,157,0 +triggerrails,157,0 +arails,157,0 +trails,157,0 +activatorrail,157,0 +activaterail,157,0 +triggerrail,157,0 +arail,157,0 +trail,157,0 +activatortrack,157,0 +activatetrack,157,0 +triggertrack,157,0 +atrack,157,0 +ttrack,157,0 +dropper,158,0 +drop,158,0 +chestdispenser,158,0 +chestdispense,158,0 +chestdropper,158,0 +chestdrop,158,0 +whiteclay,159,0 +whitesclay,159,0 +whitestainedclay,159,0 +wclay,159,0 +wsclay,159,0 +wstainedclay,159,0 +sclay,159,0 +stainedclay,159,0 +orangeclay,159,1 +orangesclay,159,1 +orangestainedclay,159,1 +oclay,159,1 +osclay,159,1 +ostainedclay,159,1 +magentaclay,159,2 +magentasclay,159,2 +magentastainedclay,159,2 +mclay,159,2 +msclay,159,2 +mstainedclay,159,2 +lightblueclay,159,3 +lightbluesclay,159,3 +lightbluestainedclay,159,3 +lblueclay,159,3 +lbluesclay,159,3 +lbluestainedclay,159,3 +lightbluclay,159,3 +lightblusclay,159,3 +lightblustainedclay,159,3 +lbluclay,159,3 +lblusclay,159,3 +lblustainedclay,159,3 +lbclay,159,3 +lbsclay,159,3 +lbstainedclay,159,3 +yellowclay,159,4 +yellowsclay,159,4 +yellowstainedclay,159,4 +yclay,159,4 +ysclay,159,4 +ystainedclay,159,4 +lightgreenclay,159,5 +lightgreensclay,159,5 +lightgreenstainedclay,159,5 +lgreenclay,159,5 +lgreensclay,159,5 +lgreenstainedclay,159,5 +lightgreclay,159,5 +lightgresclay,159,5 +lightgrestainedclay,159,5 +lgreclay,159,5 +lgresclay,159,5 +lgrestainedclay,159,5 +limeclay,159,5 +limesclay,159,5 +limestainedclay,159,5 +lclay,159,5 +lsclay,159,5 +lstainedclay,159,5 +pinkclay,159,6 +pinksclay,159,6 +pinkstainedclay,159,6 +piclay,159,6 +pisclay,159,6 +pistainedclay,159,6 +darkgrayclay,159,7 +darkgraysclay,159,7 +darkgraystainedclay,159,7 +dgrayclay,159,7 +dgraysclay,159,7 +dgraystainedclay,159,7 +darkgreyclay,159,7 +darkgreeysclay,159,7 +darkgreystainedclay,159,7 +dgreyclay,159,7 +dgreysclay,159,7 +dgreystainedclay,159,7 +darkgraclay,159,7 +darkgrasclay,159,7 +darkgrastainedclay,159,7 +dgraclay,159,7 +dgrasclay,159,7 +dgrastainedclay,159,7 +grayclay,159,7 +graysclay,159,7 +graystainedclay,159,7 +greyclay,159,7 +greysclay,159,7 +greystainedclay,159,7 +graclay,159,7 +grasclay,159,7 +grastainedclay,159,7 +lightgrayclay,159,8 +lightgraysclay,159,8 +lightgraystainedclay,159,8 +lgrayclay,159,8 +lgraysclay,159,8 +lgraystainedclay,159,8 +lightgreyclay,159,8 +lightgreysclay,159,8 +lightgreystainedclay,159,8 +lgreyclay,159,8 +lgreysclay,159,8 +lgreystainedclay,159,8 +lightgraclay,159,8 +lightgrasclay,159,8 +lightgrastainedclay,159,8 +lgraclay,159,8 +lgrasclay,159,8 +lgrastainedclay,159,8 +silverclay,159,8 +silversclay,159,8 +silverstainedclay,159,8 +siclay,159,8 +siasclay,159,8 +siastainedclay,159,8 +cyanclay,159,9 +cyansclay,159,9 +cyanstainedclay,159,9 +cclay,159,9 +csclay,159,9 +cstainedclay,159,9 +purpleclay,159,10 +purplesclay,159,10 +purplestainedclay,159,10 +puclay,159,10 +pusclay,159,10 +pustainedclay,159,10 +blueclay,159,11 +bluesclay,159,11 +bluestainedclay,159,11 +bluclay,159,11 +blusclay,159,11 +blustainedclay,159,11 +brownclay,159,12 +brownsclay,159,12 +brownstainedclay,159,12 +broclay,159,12 +brosclay,159,12 +brostainedclay,159,12 +darkgreenclay,159,13 +darkgreensclay,159,13 +darkgreenstainedclay,159,13 +dgreenclay,159,13 +dgreensclay,159,13 +dgreenstainedclay,159,13 +greenclay,159,13 +greensclay,159,13 +greenstainedclay,159,13 +darkgreclay,159,13 +darkgresclay,159,13 +darkgrestainedclay,159,13 +dgreclay,159,13 +dgresclay,159,13 +dgrestainedclay,159,13 +greclay,159,13 +gresclay,159,13 +grestainedclay,159,13 +redclay,159,14 +redsclay,159,14 +redstainedclay,159,14 +rclay,159,14 +rsclay,159,14 +rstainedclay,159,14 +blackclay,159,15 +blacksclay,159,15 +blackstainedclay,159,15 +blaclay,159,15 +blasclay,159,15 +blastainedclay,159,15 +whiteglasspane,160,0 +whitesglasspane,160,0 +whitestainedglasspane,160,0 +wglasspane,160,0 +wsglasspane,160,0 +wstainedglasspane,160,0 +sglasspane,160,0 +stainedglasspane,160,0 +orangeglasspane,160,1 +orangesglasspane,160,1 +orangestainedglasspane,160,1 +oglasspane,160,1 +osglasspane,160,1 +ostainedglasspane,160,1 +magentaglasspane,160,2 +magentasglasspane,160,2 +magentastainedglasspane,160,2 +mglasspane,160,2 +msglasspane,160,2 +mstainedglasspane,160,2 +lightblueglasspane,160,3 +lightbluesglasspane,160,3 +lightbluestainedglasspane,160,3 +lblueglasspane,160,3 +lbluesglasspane,160,3 +lbluestainedglasspane,160,3 +lightbluglasspane,160,3 +lightblusglasspane,160,3 +lightblustainedglasspane,160,3 +lbluglasspane,160,3 +lblusglasspane,160,3 +lblustainedglasspane,160,3 +lbglasspane,160,3 +lbsglasspane,160,3 +lbstainedglasspane,160,3 +yellowglasspane,160,4 +yellowsglasspane,160,4 +yellowstainedglasspane,160,4 +yglasspane,160,4 +ysglasspane,160,4 +ystainedglasspane,160,4 +lightgreenglasspane,160,5 +lightgreensglasspane,160,5 +lightgreenstainedglasspane,160,5 +lgreenglasspane,160,5 +lgreensglasspane,160,5 +lgreenstainedglasspane,160,5 +lightgreglasspane,160,5 +lightgresglasspane,160,5 +lightgrestainedglasspane,160,5 +lgreglasspane,160,5 +lgresglasspane,160,5 +lgrestainedglasspane,160,5 +limeglasspane,160,5 +limesglasspane,160,5 +limestainedglasspane,160,5 +lglasspane,160,5 +lsglasspane,160,5 +lstainedglasspane,160,5 +pinkglasspane,160,6 +pinksglasspane,160,6 +pinkstainedglasspane,160,6 +piglasspane,160,6 +pisglasspane,160,6 +pistainedglasspane,160,6 +darkgrayglasspane,160,7 +darkgraysglasspane,160,7 +darkgraystainedglasspane,160,7 +dgrayglasspane,160,7 +dgraysglasspane,160,7 +dgraystainedglasspane,160,7 +darkgreyglasspane,160,7 +darkgreysglasspane,160,7 +darkgreystainedglasspane,160,7 +dgreyglasspane,160,7 +dgreysglasspane,160,7 +dgreystainedglasspane,160,7 +darkgraglasspane,160,7 +darkgrasglasspane,160,7 +darkgrastainedglasspane,160,7 +dgraglasspane,160,7 +dgrasglasspane,160,7 +dgrastainedglasspane,160,7 +grayglasspane,160,7 +graysglasspane,160,7 +graystainedglasspane,160,7 +greyglasspane,160,7 +greysglasspane,160,7 +greystainedglasspane,160,7 +graglasspane,160,7 +grasglasspane,160,7 +grastainedglasspane,160,7 +lightgrayglasspane,160,8 +lightgraysglasspane,160,8 +lightgraystainedglasspane,160,8 +lgrayglasspane,160,8 +lgraysglasspane,160,8 +lgraystainedglasspane,160,8 +lightgreyglasspane,160,8 +lightgreysglasspane,160,8 +lightgreystainedglasspane,160,8 +lgreyglasspane,160,8 +lgreysglasspane,160,8 +lgreystainedglasspane,160,8 +lightgraglasspane,160,8 +lightgrasglasspane,160,8 +lightgrastainedglasspane,160,8 +lgraglasspane,160,8 +lgrasglasspane,160,8 +lgrastainedglasspane,160,8 +silverglasspane,160,8 +silversglasspane,160,8 +silverstainedglasspane,160,8 +siglasspane,160,8 +siasglasspane,160,8 +siastainedglasspane,160,8 +cyanglasspane,160,9 +cyansglasspane,160,9 +cyanstainedglasspane,160,9 +cglasspane,160,9 +csglasspane,160,9 +cstainedglasspane,160,9 +purpleglasspane,160,10 +purplesglasspane,160,10 +purplestainedglasspane,160,10 +puglasspane,160,10 +pusglasspane,160,10 +pustainedglasspane,160,10 +blueglasspane,160,11 +bluesglasspane,160,11 +bluestainedglasspane,160,11 +bluglasspane,160,11 +blusglasspane,160,11 +blustainedglasspane,160,11 +brownglasspane,160,12 +brownsglasspane,160,12 +brownstainedglasspane,160,12 +broglasspane,160,12 +brosglasspane,160,12 +brostainedglasspane,160,12 +darkgreenglasspane,160,13 +darkgreensglasspane,160,13 +darkgreenstainedglasspane,160,13 +dgreenglasspane,160,13 +dgreensglasspane,160,13 +dgreenstainedglasspane,160,13 +greenglasspane,160,13 +greensglasspane,160,13 +greenstainedglasspane,160,13 +darkgreglasspane,160,13 +darkgresglasspane,160,13 +darkgrestainedglasspane,160,13 +dgreglasspane,160,13 +dgresglasspane,160,13 +dgrestainedglasspane,160,13 +greglasspane,160,13 +gresglasspane,160,13 +grestainedglasspane,160,13 +redglasspane,160,14 +redsglasspane,160,14 +redstainedglasspane,160,14 +rglasspane,160,14 +rsglasspane,160,14 +rstainedglasspane,160,14 +blackglasspane,160,15 +blacksglasspane,160,15 +blackstainedglasspane,160,15 +blaglasspane,160,15 +blasglasspane,160,15 +blastainedglasspane,160,15 +acacialeaves,161,0 +acaciatreeleaves,161,0 +acacialogleaves,161,0 +acaciatrunkleaves,161,0 +acaciawoodleaves,161,0 +aleaves,161,0 +atreeleaves,161,0 +alogleaves,161,0 +atrunkleaves,161,0 +awoodleaves,161,0 +acacialeave,161,0 +acaciatreeleave,161,0 +acacialogleave,161,0 +acaciatrunkleave,161,0 +acaciawoodleave,161,0 +aleave,161,0 +atreeleave,161,0 +alogleave,161,0 +atrunkleave,161,0 +awoodleave,161,0 +acaciatreeleaf,161,0 +acacialogleaf,161,0 +acaciatrunkleaf,161,0 +acaciawoodleaf,161,0 +aleaf,161,0 +atreeleaf,161,0 +alogleaf,161,0 +atrunkleaf,161,0 +awoodleaf,161,0 +darkoakleaves,161,1 +darkoaktreeleaves,161,1 +darkoaklogleaves,161,1 +darkoaktrunkleaves,161,1 +darkoakwoodleaves,161,1 +doakleaves,161,1 +doaktreeleaves,161,1 +doaklogleaves,161,1 +doaktrunkleaves,161,1 +doakwoodleaves,161,1 +doleaves,161,1 +dotreeleaves,161,1 +dologleaves,161,1 +dotrunkleaves,161,1 +dowoodleaves,161,1 +darkoakleave,161,1 +darkoaktreeleave,161,1 +darkoaklogleave,161,1 +darkoaktrunkleave,161,1 +darkoakwoodleave,161,1 +doakleave,161,1 +doaktreeleave,161,1 +doaklogleave,161,1 +doaktrunkleave,161,1 +doakwoodleave,161,1 +doleave,161,1 +dotreeleave,161,1 +dologleave,161,1 +dotrunkleave,161,1 +dowoodleave,161,1 +darkoaktreeleaf,161,1 +darkoaklogleaf,161,1 +darkoaktrunkleaf,161,1 +darkoakwoodleaf,161,1 +doakleaf,161,1 +doaktreeleaf,161,1 +doaklogleaf,161,1 +doaktrunkleaf,161,1 +doakwoodleaf,161,1 +doleaf,161,1 +dotreeleaf,161,1 +dologleaf,161,1 +dotrunkleaf,161,1 +dowoodleaf,161,1 +acacia,162,0 +acaciatree,162,0 +acacialog,162,0 +acaciatrunk,162,0 +acaciawood,162,0 +atree,162,0 +alog,162,0 +atrunk,162,0 +awood,162,0 +darkoak,162,1 +darkoaktree,162,1 +darkoaklog,162,1 +darkoaktrunk,162,1 +darkoakwood,162,1 +doak,162,1 +doaktree,162,1 +doaklog,162,1 +doaktrunk,162,1 +doakwood,162,1 +dotree,162,1 +dolog,162,1 +dotrunk,162,1 +dowood,162,1 +acaciawoodenstairs,163,0 +acaciawoodstairs,163,0 +acaciawstairs,163,0 +acaciastairs,163,0 +awoodenstairs,163,0 +awoodstairs,163,0 +awstairs,163,0 +astairs,163,0 +acaciawoodenstair,163,0 +acaciawoodstair,163,0 +acaciawstair,163,0 +acaciastair,163,0 +awoodenstair,163,0 +awoodstair,163,0 +awstair,163,0 +astair,163,0 +darkoakwoodenstairs,164,0 +darkoakwoodstairs,164,0 +darkoakwstairs,164,0 +darkoakstairs,164,0 +doakwoodenstairs,164,0 +doakwoodstairs,164,0 +doakwstairs,164,0 +doakstairs,164,0 +dowoodenstairs,164,0 +dowoodstairs,164,0 +dowstairs,164,0 +dostairs,164,0 +darkoakwoodenstair,164,0 +darkoakwoodstair,164,0 +darkoakwstair,164,0 +darkoakstair,164,0 +doakwoodenstair,164,0 +doakwoodstair,164,0 +doakwstair,164,0 +doakstair,164,0 +dowoodenstair,164,0 +dowoodstair,164,0 +dowstair,164,0 +dostair,164,0 +hay,170,0 +hayblock,170,0 +haybale,170,0 +baleofhay,170,0 +hayofbale,170,0 +whitecarpet,171,0 +whitefloor,171,0 +wcarpet,171,0 +wfloor,171,0 +carpet,171,0 +floor,171,0 +orangecarpet,171,1 +orangefloor,171,1 +ocarpet,171,1 +ofloor,171,1 +magentacarpet,171,2 +magentafloor,171,2 +mcarpet,171,2 +mfloor,171,2 +lightbluecarpet,171,3 +lightbluefloor,171,3 +lbluecarpet,171,3 +lbluefloor,171,3 +lbcarpet,171,3 +lbfloor,171,3 +lightblucarpet,171,3 +lightblufloor,171,3 +lblucarpet,171,3 +lblufloor,171,3 +yellowcarpet,171,4 +yellowfloor,171,4 +ycarpet,171,4 +yfloor,171,4 +lightgreencarpet,171,5 +lightgreenfloor,171,5 +lgreencarpet,171,5 +lgreenfloor,171,5 +lightgrecarpet,171,5 +lightgrefloor,171,5 +lgrecarpet,171,5 +lgrefloor,171,5 +limecarpet,171,5 +limefloor,171,5 +lcarpet,171,5 +lfloor,171,5 +pinkcarpet,171,6 +pinkfloor,171,6 +picarpet,171,6 +pifloor,171,6 +darkgraycarpet,171,7 +darkgrayfloor,171,7 +dgraycarpet,171,7 +dgrayfloor,171,7 +darkgreycarpet,171,7 +darkgreyfloor,171,7 +dgreycarpet,171,7 +dgreyfloor,171,7 +darkgracarpet,171,7 +darkgrafloor,171,7 +dgracarpet,171,7 +dgrafloor,171,7 +graycarpet,171,7 +grayfloor,171,7 +greycarpet,171,7 +greyfloor,171,7 +gracarpet,171,7 +grafloor,171,7 +lightgraycarpet,171,8 +lightgrayfloor,171,8 +lgraycarpet,171,8 +lgrayfloor,171,8 +lightgreycarpet,171,8 +lightgreyfloor,171,8 +lgreycarpet,171,8 +lgreyfloor,171,8 +lightgracarpet,171,8 +lightgrafloor,171,8 +lgracarpet,171,8 +lgrafloor,171,8 +silvercarpet,171,8 +silverfloor,171,8 +sicarpet,171,8 +siafloor,171,8 +cyancarpet,171,9 +cyanfloor,171,9 +ccarpet,171,9 +cfloor,171,9 +purplecarpet,171,10 +purplefloor,171,10 +pucarpet,171,10 +pufloor,171,10 +bluecarpet,171,11 +bluefloor,171,11 +blucarpet,171,11 +blufloor,171,11 +browncarpet,171,12 +brownfloor,171,12 +brocarpet,171,12 +brofloor,171,12 +darkgreencarpet,171,13 +darkgreenfloor,171,13 +dgreencarpet,171,13 +dgreenfloor,171,13 +greencarpet,171,13 +greenfloor,171,13 +darkgrecarpet,171,13 +darkgrefloor,171,13 +dgrecarpet,171,13 +dgrefloor,171,13 +grecarpet,171,13 +grefloor,171,13 +redcarpet,171,14 +redfloor,171,14 +rcarpet,171,14 +rfloor,171,14 +blackcarpet,171,15 +blackfloor,171,15 +blacarpet,171,15 +blafloor,171,15 +hardenedclay,172,0 +hardclay,172,0 +hclay,172,0 +coalblock,173,0 +blockcoal,173,0 +coblock,173,0 +blockco,173,0 +coalb,173,0 +bcoal,173,0 +packedice,174,0 +packice,174,0 +solidice,174,0 +sunflower,175,0 +yellowsunflower,175,0 +lilac,175,1 +magentalilac,175,1 +syringa,175,1 +longtallgrass,175,2 +extratallgrass,175,2 +doubletallgrass,175,2 +largetallgrass,175,2 +longtgrass,175,2 +extratgrass,175,2 +doubletgrass,175,2 +largetgrass,175,2 +ltgrass,175,2 +etgrass,175,2 +dtgrass,175,2 +bigfern,175,3 +largefern,175,3 +doublefern,175,3 +bfern,175,3 +lfern,175,3 +dfern,175,3 +rosebush,175,4 +redrosebush,175,4 +peony,175,5 +pinkpeony,175,5 +paeonia,175,5 +ironshovel,256,0 +ironspade,256,0 +ishovel,256,0 +ispade,256,0 +steelshovel,256,0 +steelspade,256,0 +ironpickaxe,257,0 +ironpick,257,0 +steelpickaxe,257,0 +steelpick,257,0 +ipickaxe,257,0 +ipick,257,0 +ironaxe,258,0 +iaxe,258,0 +steelaxe,258,0 +flintandsteel,259,0 +flintandiron,259,0 +flintandtinder,259,0 +flintnsteel,259,0 +flintniron,259,0 +flintntinder,259,0 +flintsteel,259,0 +flintiron,259,0 +flinttinder,259,0 +lighter,259,0 +apple,260,0 +normalapple,260,0 +redapple,260,0 +bow,261,0 +arrow,262,0 +coal,263,0 +charcoal,263,1 +ccoal,263,1 +diamond,264,0 +crystal,264,0 +ironingot,265,0 +ironbar,265,0 +ironi,265,0 +steelingot,265,0 +steelbar,265,0 +steeli,265,0 +iingot,265,0 +ibar,265,0 +ingotiron,265,0 +bariron,265,0 +iiron,265,0 +ingotsteel,265,0 +barsteel,265,0 +isteel,265,0 +ingoti,265,0 +bari,265,0 +goldingot,266,0 +goldbar,266,0 +goldi,266,0 +gingot,266,0 +gbar,266,0 +ingotgold,266,0 +bargold,266,0 +igold,266,0 +ingotg,266,0 +barg,266,0 +ironsword,267,0 +steelsword,267,0 +isword,267,0 +woodensword,268,0 +woodsword,268,0 +wsword,268,0 +woodenshovel,269,0 +woodenspade,269,0 +woodshovel,269,0 +woodspade,269,0 +wshovel,269,0 +wspade,269,0 +woodenpickaxe,270,0 +woodenpick,270,0 +woodpickaxe,270,0 +woodpick,270,0 +wpickaxe,270,0 +wpick,270,0 +woodenaxe,271,0 +woodaxe,271,0 +waxe,271,0 +stonesword,272,0 +cobblestonesword,272,0 +cstonesword,272,0 +cssword,272,0 +ssword,272,0 +stoneshovel,273,0 +cobblestoneshovel,273,0 +cobblestonespade,273,0 +cstoneshovel,273,0 +cstonespade,273,0 +stonespade,273,0 +csshovel,273,0 +csspade,273,0 +sshovel,273,0 +sspade,273,0 +stonepickaxe,274,0 +cobblestonepickaxe,274,0 +cobblestonepick,274,0 +cstonepickaxe,274,0 +cstonepick,274,0 +stonepick,274,0 +cspickaxe,274,0 +cspick,274,0 +spickaxe,274,0 +spick,274,0 +stoneaxe,275,0 +cobblestoneaxe,275,0 +cstoneaxe,275,0 +csaxe,275,0 +saxe,275,0 +diamondsword,276,0 +crystalsword,276,0 +dsword,276,0 +diamondshovel,277,0 +diamondspade,277,0 +crystalshovel,277,0 +crystalspade,277,0 +dshovel,277,0 +dspade,277,0 +diamondpickaxe,278,0 +diamondpick,278,0 +crystalpickaxe,278,0 +crystalpick,278,0 +dpickaxe,278,0 +dpick,278,0 +diamondaxe,279,0 +crystalaxe,279,0 +daxe,279,0 +stick,280,0 +twig,280,0 +branch,280,0 +bowl,281,0 +woodenbowl,281,0 +woodbowl,281,0 +mushroomsoup,282,0 +mrsoup,282,0 +soup,282,0 +goldsword,283,0 +gsword,283,0 +goldshovel,284,0 +goldspade,284,0 +gshovel,284,0 +gspade,284,0 +goldpickaxe,285,0 +goldpick,285,0 +gpickaxe,285,0 +gpick,285,0 +goldaxe,286,0 +gaxe,286,0 +string,287,0 +thread,287,0 +feather,288,0 +gunpowder,289,0 +sulfur,289,0 +woodenhoe,290,0 +woodhoe,290,0 +whoe,290,0 +stonehoe,291,0 +cobblestonehoe,291,0 +cstonehoe,291,0 +cshoe,291,0 +shoe,291,0 +ironhoe,292,0 +steelhoe,292,0 +ihoe,292,0 +diamondhoe,293,0 +crystalhoe,293,0 +dhoe,293,0 +goldhoe,294,0 +ghoe,294,0 +seeds,295,0 +seed,295,0 +wheat,296,0 +crops,296,0 +crop,296,0 +bread,297,0 +leatherhelmet,298,0 +leatherhelm,298,0 +leatherhat,298,0 +leathercoif,298,0 +lhelmet,298,0 +lhelm,298,0 +lhat,298,0 +lcoif,298,0 +leatherchestplate,299,0 +leatherplatebody,299,0 +leatherplate,299,0 +leathershirt,299,0 +leathertunic,299,0 +lchestplate,299,0 +lplatebody,299,0 +lplate,299,0 +lshirt,299,0 +ltunic,299,0 +leatherleggings,300,0 +leatherlegs,300,0 +leatherpants,300,0 +lleggings,300,0 +llegs,300,0 +lpants,300,0 +leatherboots,301,0 +leathershoes,301,0 +lboots,301,0 +lshoes,301,0 +chainmailhelmet,302,0 +chainmailhelm,302,0 +chainmailhat,302,0 +chainmailcoif,302,0 +chainmhelmet,302,0 +chainmhelm,302,0 +chainmhat,302,0 +chainmcoif,302,0 +cmailhelmet,302,0 +cmailhelm,302,0 +cmailhat,302,0 +cmailcoif,302,0 +chainhelmet,302,0 +chainhelm,302,0 +chainhat,302,0 +chaincoif,302,0 +cmhelmet,302,0 +cmhelm,302,0 +cmhat,302,0 +cmcoif,302,0 +chainmailchestplate,303,0 +chainmailplatebody,303,0 +chainmailplate,303,0 +chainmailshirt,303,0 +chainmailtunic,303,0 +chainmchestplate,303,0 +chainmplatebody,303,0 +chainmplate,303,0 +chainmshirt,303,0 +chainmtunic,303,0 +cmailchestplate,303,0 +cmailplatebody,303,0 +cmailplate,303,0 +cmailshirt,303,0 +cmailtunic,303,0 +chainchestplate,303,0 +chainplatebody,303,0 +chainplate,303,0 +chainshirt,303,0 +chaintunic,303,0 +cmchestplate,303,0 +cmplatebody,303,0 +cmplate,303,0 +cmshirt,303,0 +cmtunic,303,0 +chainmailleggings,304,0 +chainmaillegs,304,0 +chainmailpants,304,0 +chainmleggings,304,0 +chainmlegs,304,0 +chainmpants,304,0 +cmailleggings,304,0 +cmaillegs,304,0 +cmailpants,304,0 +chainleggings,304,0 +chainlegs,304,0 +chainpants,304,0 +cmleggings,304,0 +cmlegs,304,0 +cmpants,304,0 +chainmailboots,305,0 +chainmailshoes,305,0 +chainmboots,305,0 +chainmshoes,305,0 +cmailboots,305,0 +cmailshoes,305,0 +chainboots,305,0 +chainshoes,305,0 +cmboots,305,0 +cmshoes,305,0 +ironhelmet,306,0 +ironhelm,306,0 +ironhat,306,0 +ironcoif,306,0 +ihelmet,306,0 +ihelm,306,0 +ihat,306,0 +icoif,306,0 +steelhelmet,306,0 +steelhelm,306,0 +steelhat,306,0 +steelcoif,306,0 +shelmet,306,0 +shelm,306,0 +shat,306,0 +scoif,306,0 +ironchestplate,307,0 +ironplatebody,307,0 +ironshirt,307,0 +irontunic,307,0 +ichestplate,307,0 +iplatebody,307,0 +ishirt,307,0 +itunic,307,0 +steelchestplate,307,0 +steelplatebody,307,0 +steelplate,307,0 +steelshirt,307,0 +steeltunic,307,0 +schestplate,307,0 +splatebody,307,0 +sshirt,307,0 +stunic,307,0 +ironleggings,308,0 +ironlegs,308,0 +ironpants,308,0 +ileggings,308,0 +ilegs,308,0 +ipants,308,0 +steelleggings,308,0 +steellegs,308,0 +steelpants,308,0 +sleggings,308,0 +slegs,308,0 +spants,308,0 +ironboots,309,0 +ironshoes,309,0 +iboots,309,0 +ishoes,309,0 +steelboots,309,0 +steelshoes,309,0 +sboots,309,0 +sshoes,309,0 +diamondhelmet,310,0 +diamondhelm,310,0 +diamondhat,310,0 +diamondcoif,310,0 +dhelmet,310,0 +dhelm,310,0 +dhat,310,0 +dcoif,310,0 +crystalhelmet,310,0 +crystalhelm,310,0 +crystalhat,310,0 +crystalcoif,310,0 +chelmet,310,0 +chelm,310,0 +chat,310,0 +ccoif,310,0 +diamondchestplate,311,0 +diamondplatebody,311,0 +diamondplate,311,0 +diamondshirt,311,0 +diamondtunic,311,0 +dchestplate,311,0 +dplatebody,311,0 +dplate,311,0 +dshirt,311,0 +dtunic,311,0 +crystalchestplate,311,0 +crystalplatebody,311,0 +crystalplate,311,0 +crystalshirt,311,0 +crystaltunic,311,0 +cchestplate,311,0 +cplatebody,311,0 +cplate,311,0 +cshirt,311,0 +ctunic,311,0 +diamondleggings,312,0 +diamondlegs,312,0 +diamondpants,312,0 +dleggings,312,0 +dlegs,312,0 +dpants,312,0 +crystalleggings,312,0 +crystallegs,312,0 +crystalpants,312,0 +cleggings,312,0 +clegs,312,0 +cpants,312,0 +diamondboots,313,0 +diamondshoes,313,0 +dboots,313,0 +dshoes,313,0 +crystalboots,313,0 +crystalshoes,313,0 +cboots,313,0 +cshoes,313,0 +goldhelmet,314,0 +goldhelm,314,0 +goldhat,314,0 +goldcoif,314,0 +ghelmet,314,0 +ghelm,314,0 +ghat,314,0 +gcoif,314,0 +goldchestplate,315,0 +goldplatebody,315,0 +goldshirt,315,0 +goldtunic,315,0 +gchestplate,315,0 +gplatebody,315,0 +gplateplate,315,0 +gshirt,315,0 +gtunic,315,0 +goldleggings,316,0 +goldlegs,316,0 +goldpants,316,0 +gleggings,316,0 +glegs,316,0 +gpants,316,0 +goldboots,317,0 +goldshoes,317,0 +gboots,317,0 +gshoes,317,0 +flint,318,0 +pork,319,0 +porkchop,319,0 +rawpork,319,0 +rpork,319,0 +rawporkchop,319,0 +rporkchop,319,0 +cookedpork,320,0 +grilledpork,320,0 +grillpork,320,0 +gpork,320,0 +cookpork,320,0 +cpork,320,0 +grilledporkchop,320,0 +grillporkchop,320,0 +gporkchop,320,0 +cookedporkchop,320,0 +cookporkchop,320,0 +cporkchop,320,0 +bacon,320,0 +painting,321,0 +picture,321,0 +goldenapple,322,0 +goldapple,322,0 +gapple,322,0 +enchantedgoldenapple,322,1 +enchantedgoldapple,322,1 +enchantedgapple,322,1 +supergoldenapple,322,1 +supergoldapple,322,1 +supergapple,322,1 +magicalgoldenapple,322,1 +magicalgoldapple,322,1 +magicalgapple,322,1 +magicgoldenapple,322,1 +magicgoldapple,322,1 +magicgapple,322,1 +egoldenapple,322,1 +egoldapple,322,1 +egapple,322,1 +sgoldenapple,322,1 +sgoldapple,322,1 +sgapple,322,1 +mgoldenapple,322,1 +mgoldapple,322,1 +mgapple,322,1 +sign,323,0 +woodendoor,324,0 +wooddoor,324,0 +wdoor,324,0 +door,324,0 +bucket,325,0 +bukkit,325,0 +waterbucket,326,0 +waterbukkit,326,0 +wbucket,326,0 +wbukkit,326,0 +magmabucket,327,0 +magmabukkit,327,0 +lavabucket,327,0 +lavabukkit,327,0 +lbucket,327,0 +lbukkit,327,0 +minecart,328,0 +mcart,328,0 +cart,328,0 +saddle,329,0 +irondoor,330,0 +idoor,330,0 +steeldoor,330,0 +sdoor,330,0 +dooriron,330,0 +doori,330,0 +doorsteel,330,0 +doors,330,0 +redstonedust,331,0 +redstone,331,0 +rstonedust,331,0 +rstone,331,0 +redsdust,331,0 +reddust,331,0 +rsdust,331,0 +rdust,331,0 +snow,332,0 +snowball,332,0 +snball,332,0 +sball,332,0 +boat,333,0 +leather,334,0 +cowhide,334,0 +hide,334,0 +milkbucket,335,0 +milkbukkit,335,0 +mbucket,335,0 +mbukkit,335,0 +claybrick,336,0 +brick,336,0 +redbrick,336,0 +rbrick,336,0 +clayball,337,0 +cball,337,0 +clay,337,0 +reeds,338,0 +reed,338,0 +sugarcane,338,0 +scane,338,0 +bamboo,338,0 +paper,339,0 +papyrus,339,0 +book,340,0 +slimeball,341,0 +slball,341,0 +chestminecart,342,0 +storageminecart,342,0 +storagemcart,342,0 +chestmcart,342,0 +storagecart,342,0 +chestcart,342,0 +sminecart,342,0 +cminecart,342,0 +smcart,342,0 +cmcart,342,0 +scart,342,0 +ccart,342,0 +furnaceminecart,343,0 +engineminecart,343,0 +poweredminecart,343,0 +powerminecart,343,0 +enginemcart,343,0 +poweredmcart,343,0 +powermcart,343,0 +furnacemcart,343,0 +enginecart,343,0 +poweredcart,343,0 +powercart,343,0 +furnacecart,343,0 +eminecart,343,0 +pminecart,343,0 +fminecart,343,0 +emcart,343,0 +pmcart,343,0 +fmcart,343,0 +ecart,343,0 +pcart,343,0 +fcart,343,0 +egg,344,0 +compass,345,0 +fishingrod,346,0 +fishrod,346,0 +frod,346,0 +rod,346,0 +watch,347,0 +goldwatch,347,0 +goldclock,347,0 +gwatch,347,0 +gclock,347,0 +clock,347,0 +glowstonedust,348,0 +glowingstonedust,348,0 +lightstonedust,348,0 +lbdust,348,0 +gbdust,348,0 +lsdust,348,0 +gsdust,348,0 +rawfish,349,0 +rafish,349,0 +fish,349,0 +rawsalmonfish,349,1 +rasalmonfish,349,1 +salmonfish,349,1 +rawsalmon,349,1 +rasalmon,349,1 +salmon,349,1 +sfish,349,1 +fishs,349,1 +rawclownfish,349,2 +raclownfish,349,2 +clownfish,349,2 +rawnemo,349,2 +ranemo,349,2 +nemo,349,2 +nemofish,349,2 +fishnemo,349,2 +clfish,349,2 +fishcl,349,2 +nfish,349,2 +fishn,349,2 +rawpufferfish,349,3 +rapufferfish,349,3 +pufferfish,349,3 +pufffish,349,3 +fishpuff,349,3 +pfish,349,3 +fishp,349,3 +cookedfish,350,0 +cookfish,350,0 +cfish,350,0 +grilledfish,350,0 +grillfish,350,0 +gfish,350,0 +roastedfish,350,0 +roastfish,350,0 +rofish,350,0 +cookedsalmonfish,350,1 +cooksalmonfish,350,1 +csalmonfish,350,1 +grilledsalmonfish,350,1 +grillsalmonfish,350,1 +gsalmonfish,350,1 +roastedsalmonfish,350,1 +roastsalmonfish,350,1 +rosalmonfish,350,1 +cookedsalmon,350,1 +cooksalmon,350,1 +csalmon,350,1 +grilledsalmon,350,1 +grillsalmon,350,1 +gsalmon,350,1 +roastedsalmon,350,1 +roastsalmon,350,1 +rosalmon,350,1 +dye,351,0 +inksack,351,0 +inksac,351,0 +isack,351,0 +isac,351,0 +sack,351,0 +sac,351,0 +blackinksack,351,0 +blackinksac,351,0 +blackisack,351,0 +blackisac,351,0 +blacksack,351,0 +blacksac,351,0 +inksackblack,351,0 +inksacblack,351,0 +isackblack,351,0 +isacblack,351,0 +sackblack,351,0 +sacblack,351,0 +blackinksackcolour,351,0 +blackinksaccolour,351,0 +blackisackcolour,351,0 +blackisaccolour,351,0 +blacksackcolour,351,0 +blacksaccolour,351,0 +inksackblackcolour,351,0 +inksacblackcolour,351,0 +isackblackcolour,351,0 +isacclackcolour,351,0 +sackblackcolour,351,0 +sacblackcolour,351,0 +blackinksackcolor,351,0 +blackinksaccolor,351,0 +blackisackcolor,351,0 +blackisaccolor,351,0 +blacksackcolor,351,0 +blacksaccolor,351,0 +inksackblackcolor,351,0 +inksacblackcolor,351,0 +isackblackcolor,351,0 +isacblackcolor,351,0 +sackblackcolor,351,0 +sacblackcolor,351,0 +blackinksackdye,351,0 +blackinksacdye,351,0 +blackisackdye,351,0 +blackisacdye,351,0 +blacksackdye,351,0 +blacksacdye,351,0 +inksackblackdye,351,0 +inksacblackdye,351,0 +isackblackdye,351,0 +isacclackdye,351,0 +sackblackdye,351,0 +sacblackdye,351,0 +blackcolor,351,0 +blackdye,351,0 +rosered,351,1 +roseredcolor,351,1 +roseredcolour,351,1 +rosereddye,351,1 +redrosecolor,351,1 +redrosecolour,351,1 +redrosedye,351,1 +redr,351,1 +redrcolor,351,1 +redrcolour,351,1 +redrdye,351,1 +redcolor,351,1 +redcolour,351,1 +reddye,351,1 +cactusgreen,351,2 +greencactus,351,2 +cactusgreencolour,351,2 +greencactuscolour,351,2 +cactusgreencolor,351,2 +greencactuscolor,351,2 +cactusgreendye,351,2 +greencactusdye,351,2 +greencolour,351,2 +greencolor,351,2 +greendye,351,2 +cocoabeans,351,3 +cocoabean,351,3 +cocobeans,351,3 +cocobean,351,3 +cbeans,351,3 +cbean,351,3 +beans,351,3 +bean,351,3 +browncocoabeans,351,3 +browncocoabean,351,3 +browncocobeans,351,3 +browncocobean,351,3 +browncbeans,351,3 +browncbean,351,3 +brownbeans,351,3 +brownbean,351,3 +brownb,351,3 +cocoabeanscolour,351,3 +cocoabeancolour,351,3 +cocobeanscolour,351,3 +cocobeancolour,351,3 +cbeanscolour,351,3 +cbeancolour,351,3 +beanscolour,351,3 +beancolour,351,3 +browncocoabeanscolour,351,3 +browncocoabeancolour,351,3 +browncocobeanscolour,351,3 +browncocobeancolour,351,3 +browncbeanscolour,351,3 +browncbeancolour,351,3 +brownbeanscolour,351,3 +brownbeancolour,351,3 +brownbcolour,351,3 +cocoabeanscolor,351,3 +cocoabeancolor,351,3 +cocobeanscolor,351,3 +cocobeancolor,351,3 +cbeanscolor,351,3 +cbeancolor,351,3 +beanscolor,351,3 +beancolor,351,3 +browncocoabeanscolor,351,3 +browncocoabeancolor,351,3 +browncocobeanscolor,351,3 +browncocobeancolor,351,3 +browncbeanscolor,351,3 +browncbeancolor,351,3 +brownbeanscolor,351,3 +brownbeancolor,351,3 +brownbcolor,351,3 +cocoabeansdye,351,3 +cocoabeandye,351,3 +cocobeansdye,351,3 +cocobeandye,351,3 +cbeansdye,351,3 +cbeandye,351,3 +beansdye,351,3 +beandye,351,3 +browncocoabeansdye,351,3 +browncocoabeandye,351,3 +browncocobeansdye,351,3 +browncocobeandye,351,3 +browncbeansdye,351,3 +browncbeandye,351,3 +brownbeansdye,351,3 +brownbeandye,351,3 +brownbdye,351,3 +browncolour,351,3 +browncolor,351,3 +browndye,351,3 +lapislazuli,351,4 +bluelapislazuli,351,4 +bluelapisl,351,4 +bluelapis,351,4 +bluel,351,4 +lapislazuliblue,351,4 +lapislblue,351,4 +lapisblue,351,4 +lapisl,351,4 +lapis,351,4 +bluelapislazulicolour,351,4 +bluelapislcolour,351,4 +bluelapiscolour,351,4 +lapislazulibluecolour,351,4 +lapislbluecolour,351,4 +lapisbluecolour,351,4 +lapislazulicolour,351,4 +lapislcolour,351,4 +lapiscolour,351,4 +bluelapislazulicolor,351,4 +bluelapislcolor,351,4 +bluelapiscolor,351,4 +lapislazulibluecolor,351,4 +lapislbluecolor,351,4 +lapisbluecolor,351,4 +lapislazulicolor,351,4 +lapislcolor,351,4 +lapiscolor,351,4 +bluelapislazulidye,351,4 +bluelapisldye,351,4 +bluelapisdye,351,4 +lapislazulibluedye,351,4 +lapislbluedye,351,4 +lapisbluedye,351,4 +lapislazulidye,351,4 +lapisldye,351,4 +lapisdye,351,4 +bluecolour,351,4 +bluecolor,351,4 +bluedye,351,4 +purpledye,351,5 +purplecolour,351,5 +purplecolor,351,5 +cyandye,351,6 +cyancolour,351,6 +cyancolor,351,6 +lightgraydye,351,7 +lightgraycolour,351,7 +lightgraycolor,351,7 +lgraycolour,351,7 +lgraycolor,351,7 +lgraydye,351,7 +lightgreydye,351,7 +lightgreycolour,351,7 +lightgreycolor,351,7 +lgreycolour,351,7 +lgreycolor,351,7 +lgreydye,351,7 +silvercolour,351,7 +silvercolor,351,7 +silverdye,351,7 +darkgraydye,351,8 +darkgraycolour,351,8 +darkgraycolor,351,8 +dgraycolour,351,8 +dgraycolor,351,8 +dgraydye,351,8 +graycolour,351,8 +graycolor,351,8 +graydye,351,8 +darkgreydye,351,8 +darkgreycolour,351,8 +darkgreycolor,351,8 +dgreycolour,351,8 +dgreycolor,351,8 +dgreydye,351,8 +greycolour,351,8 +greycolor,351,8 +greydye,351,8 +pinkdye,351,9 +pinkcolour,351,9 +pinkcolor,351,9 +limedye,351,10 +limecolour,351,10 +limecolor,351,10 +dandelionyellow,351,11 +dandelionyellowcolour,351,11 +dandelionyellowcolor,351,11 +dandelionyellowdye,351,11 +yellowdandelioncolour,351,11 +yellowdandelioncolor,351,11 +yellowdandeliondye,351,11 +yellowd,351,11 +yellowdcolour,351,11 +yellowdcolor,351,11 +yellowddye,351,11 +dyellow,351,11 +dyellowcolour,351,11 +dyellowcolor,351,11 +dyellowdye,351,11 +yellowcolour,351,11 +yellowcolor,351,11 +yellowdye,351,11 +lightbluecolour,351,12 +lightbluecolor,351,12 +lightbluedye,351,12 +lbluecolour,351,12 +lbluecolor,351,12 +lbluedye,351,12 +magentacolour,351,13 +magentacolor,351,13 +magentadye,351,13 +orangecolour,351,14 +orangecolor,351,14 +orangedye,351,14 +bonemeal,351,15 +whitebonemeal,351,15 +whitebonemealcolour,351,15 +whitebonemealcolor,351,15 +whitebonemealdye,351,15 +bonemealwhite,351,15 +bonemealwhitecolour,351,15 +bonemealwhitecolor,351,15 +bonemealwhitedye,351,15 +whitebonem,351,15 +whitebonemcolour,351,15 +whitebonemcolor,351,15 +whitebonemdye,351,15 +bonemwhite,351,15 +bonemwhitecolour,351,15 +bonemwhitecolor,351,15 +bonemwhitedye,351,15 +bonemealcolour,351,15 +bonemealcolor,351,15 +bonemealdye,351,15 +bonem,351,15 +bonemcolour,351,15 +bonemcolor,351,15 +bonemdye,351,15 +whitecolour,351,15 +whitecolor,351,15 +whitedye,351,15 +bone,352,0 +sugar,353,0 +whitedust,353,0 +cake,354,0 +bed,355,0 +redstonerepeater,356,0 +redstonerepeat,356,0 +redstonedelayer,356,0 +redstonedelay,356,0 +redstonedioder,356,0 +redstonediode,356,0 +rstonerepeater,356,0 +rstonerepeat,356,0 +rstonedelayer,356,0 +rstonedelay,356,0 +rstonedioder,356,0 +rstonediode,356,0 +redsrepeater,356,0 +redsrepeat,356,0 +redsdelayer,356,0 +redsdelay,356,0 +redsdioder,356,0 +redsdiode,356,0 +rsrepeater,356,0 +rsrepeat,356,0 +rsdelayer,356,0 +rsdelay,356,0 +rsdioder,356,0 +rsdiode,356,0 +repeater,356,0 +repeat,356,0 +delayer,356,0 +delay,356,0 +dioder,356,0 +diode,356,0 +cookie,357,0 +chart,358,0 +map0,358,0 +map1,358,1 +map2,358,2 +map3,358,3 +map4,358,4 +map5,358,5 +map6,358,6 +map7,358,7 +map8,358,8 +map9,358,9 +map10,358,10 +map11,358,11 +map12,358,12 +map13,358,13 +map14,358,14 +map15,358,15 +shears,359,0 +shear,359,0 +sheers,359,0 +sheer,359,0 +woolcutters,359,0 +woolcutter,359,0 +cutterswool,359,0 +cutterwool,359,0 +melonslice,360,0 +mslice,360,0 +slicemelon,360,0 +watermelonslice,360,0 +greenmelonslice,360,0 +melongreenslice,360,0 +pumpkinseeds,361,0 +pseeds,361,0 +seedsp,361,0 +seedspumpkin,361,0 +pumpseeds,361,0 +seedspump,361,0 +melonseeds,362,0 +mseeds,362,0 +watermelonseeds,362,0 +greenmelonseeds,362,0 +gmelonseeds,362,0 +seedsmelon,362,0 +seedswatermelon,362,0 +rawbeef,363,0 +rawsteak,363,0 +uncookedbeef,363,0 +uncookedsteak,363,0 +cowmeat,363,0 +plainbeef,363,0 +beef,364,0 +steak,364,0 +cookedbeef,364,0 +grilledbeef,364,0 +cookedsteak,364,0 +grilledsteak,364,0 +cookedcowmeat,364,0 +rawchicken,365,0 +uncookedchicken,365,0 +plainchicken,365,0 +chickenplain,365,0 +chickenuncooked,365,0 +chickenraw,365,0 +cookedchicken,366,0 +grilledchicken,366,0 +toastedchicken,366,0 +gchicken,366,0 +bbqchicken,366,0 +friedchicken,366,0 +cchicken,366,0 +rottenflesh,367,0 +zombieflesh,367,0 +rottenmeat,367,0 +zombiemeat,367,0 +badflesh,367,0 +poisonflesh,367,0 +zombieremains,367,0 +enderpearl,368,0 +endpearl,368,0 +pearl,368,0 +epearl,368,0 +bluepearl,368,0 +endergem,368,0 +blazerod,369,0 +goldenrod,369,0 +goldrod,369,0 +blazestick,369,0 +goldstick,369,0 +brod,369,0 +grod,369,0 +bstick,369,0 +gstick,369,0 +ghasttear,370,0 +ghastdrop,370,0 +ghosttear,370,0 +ghostdrop,370,0 +gtear,370,0 +gdrop,370,0 +tear,370,0 +goldnugget,371,0 +gnugget,371,0 +goldpebble,371,0 +gpebble,371,0 +goldball,371,0 +gball,371,0 +netherstalk,372,0 +deathstalk,372,0 +hellstalk,372,0 +nstalk,372,0 +dstalk,372,0 +hstalk,372,0 +netherwarts,372,0 +netherwart,372,0 +netherplant,372,0 +nethercrop,372,0 +hellwarts,372,0 +hellwart,372,0 +hellplant,372,0 +hellcrop,372,0 +deathwarts,372,0 +deathwart,372,0 +deathplant,372,0 +deathcrop,372,0 +nwarts,372,0 +nwart,372,0 +ncrop,372,0 +nplant,372,0 +hwarts,372,0 +hwart,372,0 +hplant,372,0 +hcrop,372,0 +dwarts,372,0 +dwart,372,0 +dplant,372,0 +dcrop,372,0 +potion,373,0 +mixture,373,0 +potions,373,0 +waterbottle,373,0 +fullbottle,373,0 +watervase,373,0 +fullvase,373,0 +clearpotion,373,6 +clearpot,373,6 +clearextendedpotion,373,7 +clearexpotion,373,7 +clear2potion,373,7 +clearextendedpot,373,7 +clearexpot,373,7 +clear2pot,373,7 +diffusepotion,373,11 +diffusepot,373,11 +artlesspotion,373,13 +artlesspot,373,13 +thinpotion,373,14 +thinpot,373,14 +thinextendedpotion,373,15 +thinexpotion,373,15 +thin2potion,373,15 +thinextendedpot,373,15 +thinexpot,373,15 +thin2pot,373,15 +awkwardpotion,373,16 +awkwardpot,373,16 +bunglingpotion,373,22 +bunglingpot,373,22 +bunglingextendedpotion,373,23 +bunglingexpotion,373,23 +bungling2potion,373,23 +bunglingextendedpot,373,23 +bunglingexpot,373,23 +bungling2pot,373,23 +smoothpotion,373,27 +smoothpot,373,27 +suavepotion,373,29 +suavepot,373,29 +debonairpotion,373,30 +debonairpot,373,30 +debonairextendedpotion,373,31 +debonairexpotion,373,31 +debonair2potion,373,31 +debonairextendedpot,373,31 +debonairexpot,373,31 +debonair2pot,373,31 +thickpotion,373,32 +thickpot,373,32 +charmingpotion,373,38 +charmingpot,373,38 +charmingextendedpotion,373,39 +charmingexpotion,373,39 +charming2potion,373,39 +charmingextendedpot,373,39 +charmingexpot,373,39 +charming2pot,373,39 +refinedpotion,373,43 +refinedpot,373,43 +cordialpotion,373,45 +cordialpot,373,45 +sparklingpotion,373,46 +sparklingpot,373,46 +sparklingextendedpotion,373,47 +sparklingexpotion,373,47 +sparkling2potion,373,47 +sparklingextendedpot,373,47 +sparklingexpot,373,47 +sparkling2pot,373,47 +potentpotion,373,48 +potentpot,373,48 +rankpotion,373,54 +rankpot,373,54 +rankextendedpotion,373,55 +rankexpotion,373,55 +rank2potion,373,55 +rankextendedpot,373,55 +rankexpot,373,55 +rank2pot,373,55 +acridpotion,373,59 +acridpot,373,59 +grosspotion,373,61 +grosspot,373,61 +stinkypotion,373,62 +stinkypot,373,62 +stinkyextendedpotion,373,63 +stinkyexpotion,373,63 +stinky2potion,373,63 +stinkyextendedpot,373,63 +stinkyexpot,373,63 +stinky2pot,373,63 +mundaneextendedpotion,373,64 +mundaneexpotion,373,64 +mundane2potion,373,64 +mundaneextendedpot,373,64 +mundaneexpot,373,64 +mundane2pot,373,64 +mundanepotion,373,8192 +mundanepot,373,8192 +regenerationpotion,373,8193 +regeneratepotion,373,8193 +regenpotion,373,8193 +regenerationpot,373,8193 +regeneratepot,373,8193 +regenpot,373,8193 +rpot,373,8193 +swiftnesspotion,373,8194 +swiftpotion,373,8194 +speedpotion,373,8194 +swiftnesspot,373,8194 +swiftpot,373,8194 +speedpot,373,8194 +swpot,373,8194 +fireresistancepotion,373,8195 +fireresistpotion,373,8195 +firerespotion,373,8195 +fireresistancepot,373,8195 +fireresistpot,373,8195 +firerespot,373,8195 +fpot,373,8195 +poisonpotion,373,8196 +acidpotion,373,8196 +poisonpot,373,8196 +acidpot,373,8196 +ppot,373,8196 +healingpotion,373,8197 +healpotion,373,8197 +lifepotion,373,8197 +healingpot,373,8197 +healpot,373,8197 +lifepot,373,8197 +hpot,373,8197 +nightvisionpotion,373,8198 +nvisionpotion,373,8198 +nightvpotion,373,8198 +darkvisionpotion,373,8198 +dvisionpotion,373,8198 +darkvpotion,373,8198 +nightvisionpot,373,8198 +nvisionpot,373,8198 +nightvpot,373,8198 +darkvisionpot,373,8198 +dvisionpot,373,8198 +darkvpot,373,8198 +npot,373,8198 +weaknesspotion,373,8200 +weakpotion,373,8200 +weaknesspot,373,8200 +weakpot,373,8200 +wpot,373,8200 +strengthpotion,373,8201 +strongpotion,373,8201 +strpotion,373,8201 +strengthpot,373,8201 +strongpot,373,8201 +strpot,373,8201 +stpot,373,8201 +slownesspotion,373,8202 +slowpotion,373,8202 +slownesspot,373,8202 +slowpot,373,8202 +slpot,373,8202 +harmingpotion,373,8204 +damagepotion,373,8204 +dmgpotion,373,8204 +harmingpot,373,8204 +damagepot,373,8204 +dmgpot,373,8204 +dpot,373,8204 +waterbreathingpotion,373,8205 +waterbreathpotion,373,8205 +breathingpotion,373,8205 +breathpotion,373,8205 +waterbreathingpot,373,8205 +waterbreathpot,373,8205 +breathingpot,373,8205 +breathpot,373,8205 +wbpot,373,8205 +invisibilitypotion,373,8206 +invisiblepotion,373,8206 +invpotion,373,8206 +invisibilitypot,373,8206 +invisiblepot,373,8206 +invpot,373,8206 +ipot,373,8206 +regenerationleveliipotion,373,8225 +regenerateleveliipotion,373,8225 +regenleveliipotion,373,8225 +regenerationlevel2potion,373,8225 +regeneratelevel2potion,373,8225 +regenlevel2potion,373,8225 +regenerationiipotion,373,8225 +regenerateiipotion,373,8225 +regeniipotion,373,8225 +regenerationleveliipot,373,8225 +regenerateleveliipot,373,8225 +regenleveliipot,373,8225 +regenerationlevel2pot,373,8225 +regeneratelevel2pot,373,8225 +regenlevel2pot,373,8225 +regenerationiipot,373,8225 +regenerateiipot,373,8225 +regeniipot,373,8225 +r2pot,373,8225 +swiftnessleveliipotion,373,8226 +swiftleveliipotion,373,8226 +speedleveliipotion,373,8226 +swiftnesslevel2potion,373,8226 +swiftlevel2potion,373,8226 +speedlevel2potion,373,8226 +swiftnessiipotion,373,8226 +swiftiipotion,373,8226 +speediipotion,373,8226 +swiftnessleveliipot,373,8226 +swiftleveliipot,373,8226 +speedleveliipot,373,8226 +swiftnesslevel2pot,373,8226 +swiftlevel2pot,373,8226 +speedlevel2pot,373,8226 +swiftnessiipot,373,8226 +swiftiipot,373,8226 +speediipot,373,8226 +sw2pot,373,8226 +poisonleveliipotion,373,8228 +acidleveliipotion,373,8228 +poisonlevel2potion,373,8228 +acidlevel2potion,373,8228 +poisoniipotion,373,8228 +acidiipotion,373,8228 +poisonleveliipot,373,8228 +acidleveliipot,373,8228 +poisonlevel2pot,373,8228 +acidlevel2pot,373,8228 +poisoniipot,373,8228 +acidiipot,373,8228 +p2pot,373,8228 +healingleveliipotion,373,8229 +healleveliipotion,373,8229 +healinglevel2potion,373,8229 +heallevel2potion,373,8229 +healingiipotion,373,8229 +healiipotion,373,8229 +healingleveliipot,373,8229 +healleveliipot,373,8229 +healinglevel2pot,373,8229 +heallevel2pot,373,8229 +healingiipot,373,8229 +healiipot,373,8229 +h2pot,373,8229 +strengthleveliipotion,373,8233 +strongleveliipotion,373,8233 +strleveliipotion,373,8233 +strengthlevel2potion,373,8233 +stronglevel2potion,373,8233 +strlevel2potion,373,8233 +strengthiipotion,373,8233 +strongiipotion,373,8233 +striipotion,373,8233 +strengthleveliipot,373,8233 +strongleveliipot,373,8233 +strleveliipot,373,8233 +strengthlevel2pot,373,8233 +stronglevel2pot,373,8233 +strlevel2pot,373,8233 +strengthiipot,373,8233 +strongiipot,373,8233 +striipot,373,8233 +st2pot,373,8233 +harmingleveliipotion,373,8236 +damageleveliipotion,373,8236 +dmgleveliipotion,373,8236 +harminglevel2potion,373,8236 +damagelevel2potion,373,8236 +dmglevel2potion,373,8236 +harmingiipotion,373,8236 +damageiipotion,373,8236 +dmgiipotion,373,8236 +harmingleveliipot,373,8236 +damageleveliipot,373,8236 +dmgleveliipot,373,8236 +harminglevel2pot,373,8236 +damagelevel2pot,373,8236 +dmglevel2pot,373,8236 +harmingiipot,373,8236 +damageiipot,373,8236 +dmgiipot,373,8236 +d2pot,373,8236 +regenerationextendedpotion,373,8257 +regenerateextendedpotion,373,8257 +regenextendepotion,373,8257 +regenerationexpotion,373,8257 +regenerateexpotion,373,8257 +regenexpotion,373,8257 +regenerationextendedpot,373,8257 +regenerateextendedpot,373,8257 +regenextendepot,373,8257 +regenerationexpot,373,8257 +regenerateexpot,373,8257 +regenexpot,373,8257 +repot,373,8257 +swiftnessextendedpotion,373,8258 +swiftextendedpotion,373,8258 +speedextendedpotion,373,8258 +swiftnessexpotion,373,8258 +swiftexpotion,373,8258 +speedexpotion,373,8258 +swiftnessextendedpot,373,8258 +swiftextendedpot,373,8258 +speedextendedpot,373,8258 +swiftnessexpot,373,8258 +swiftexpot,373,8258 +speedexpot,373,8258 +swepot,373,8258 +fireresistanceextendedpotion,373,8259 +fireresistextendedpotion,373,8259 +fireresextendedpotion,373,8259 +fireresistanceexpotion,373,8259 +fireresistexpotion,373,8259 +fireresexpotion,373,8259 +fireresistanceextendedpot,373,8259 +fireresistextendedpot,373,8259 +fireresextendedpot,373,8259 +fireresistanceexpot,373,8259 +fireresistexpot,373,8259 +fireresexpot,373,8259 +fepot,373,8259 +poisonextendedpotion,373,8260 +acidextendedpotion,373,8260 +poisonexpotion,373,8260 +acidexpotion,373,8260 +poisonextendedpot,373,8260 +acidextendedpot,373,8260 +poisonexpot,373,8260 +acidexpot,373,8260 +pepot,373,8260 +nightvisionextendedpotion,373,8262 +nvisionextendedpotion,373,8262 +nightvextendedpotion,373,8262 +darkvisionextendedpotion,373,8262 +dvisionextendedpotion,373,8262 +darkvextendedpotion,373,8262 +nightvisionexpotion,373,8262 +nvisionexpotion,373,8262 +nightvexpotion,373,8262 +darkvisionexpotion,373,8262 +dvisionexpotion,373,8262 +darkvexpotion,373,8262 +nightvisionextendedpot,373,8262 +nvisionextendedpot,373,8262 +nightvextendedpot,373,8262 +darkvisionextendedpot,373,8262 +dvisionextendedpot,373,8262 +darkvextendedpot,373,8262 +nightvisionexpot,373,8262 +nvisionexpot,373,8262 +nightvexpot,373,8262 +darkvisionexpot,373,8262 +dvisionexpot,373,8262 +darkvexpot,373,8262 +nepot,373,8262 +weaknessextendedpotion,373,8264 +weakextendedpotion,373,8264 +weaknessexpotion,373,8264 +weakexpotion,373,8264 +weaknessextendedpot,373,8264 +weakextendedpot,373,8264 +weaknessexpot,373,8264 +weakexpot,373,8264 +wepot,373,8264 +strengthextendedpotion,373,8265 +strongextendedpotion,373,8265 +strextendedpotion,373,8265 +strengthexpotion,373,8265 +strongexpotion,373,8265 +strexpotion,373,8265 +strengthextendedpot,373,8265 +strongextendedpot,373,8265 +strextendedpot,373,8265 +strengthexpot,373,8265 +strongexpot,373,8265 +strexpot,373,8265 +stepot,373,8265 +slownessextendedpotion,373,8266 +slowextenedpotion,373,8266 +slownessexpotion,373,8266 +slowexpotion,373,8266 +slownessextendedpot,373,8266 +slowextenedpot,373,8266 +slownessexpot,373,8266 +slowexpot,373,8266 +slepot,373,8266 +waterbreathingextendedpotion,373,8269 +waterbreathextendedpotion,373,8269 +breathingextendedpotion,373,8269 +breathextendedpotion,373,8269 +waterbreathingextendedpot,373,8269 +waterbreathextendedpot,373,8269 +breathingextendedpot,373,8269 +breathextendedpot,373,8269 +waterbreathingexpotion,373,8269 +waterbreathexpotion,373,8269 +breathingexpotion,373,8269 +breathexpotion,373,8269 +waterbreathingexpot,373,8269 +waterbreathexpot,373,8269 +breathingexpot,373,8269 +breathexpot,373,8269 +wbepot,373,8269 +invisibilityextendedpotion,373,8270 +invisibleextendedpotion,373,8270 +invextendedpotion,373,8270 +invisibilityexpotion,373,8270 +invisibleexpotion,373,8270 +invexpotion,373,8270 +invisibilityextendedpot,373,8270 +invisibleextendedpot,373,8270 +invextendedpot,373,8270 +invisibilityexpot,373,8270 +invisibleexpot,373,8270 +invexpot,373,8270 +iepot,373,8270 +regenerationdualbitpotion,373,8289 +regeneratedualbitpotion,373,8289 +regendualbitpotion,373,8289 +regenerationdbpotion,373,8289 +regeneratedbpotion,373,8289 +regendbpotion,373,8289 +regenerationdualbitpot,373,8289 +regeneratedualbitpot,373,8289 +regendualbitpot,373,8289 +regenerationdbpot,373,8289 +regeneratedbpot,373,8289 +regendbpot,373,8289 +rdbpot,373,8289 +swiftnessdualbitpotion,373,8290 +swiftdualbitpotion,373,8290 +speeddualbitpotion,373,8290 +swiftnessdualbitpot,373,8290 +swiftdualbitpot,373,8290 +speeddualbitpot,373,8290 +swiftnessdbpotion,373,8290 +swiftdbpotion,373,8290 +speeddbpotion,373,8290 +swiftnessdbpot,373,8290 +swiftdbpot,373,8290 +speeddbpot,373,8290 +swdbpot,373,8290 +poisondualbitpotion,373,8292 +aciddualbitpotion,373,8292 +poisondualbitpot,373,8292 +aciddualbitpot,373,8292 +poisondbpotion,373,8292 +aciddbpotion,373,8292 +poisondbpot,373,8292 +aciddbpot,373,8292 +pdbpot,373,8292 +strengthdualbitpotion,373,8297 +strongdualbitpotion,373,8297 +strdualbitpotion,373,8297 +strengthdualbitpot,373,8297 +strongdualbitpot,373,8297 +strdualbitpot,373,8297 +strengthdbpotion,373,8297 +strongdbpotion,373,8297 +strdbpotion,373,8297 +strengthdbpot,373,8297 +strongdbpot,373,8297 +strdbpot,373,8297 +stdbpot,373,8297 +splashmundanepotion,373,16384 +splmundanepotion,373,16384 +splashregenerationpotion,373,16385 +splashregeneratepotion,373,16385 +splashregenpotion,373,16385 +splashregenerationpot,373,16385 +splashregeneratepot,373,16385 +splashregenpot,373,16385 +regenerationsplashpotion,373,16385 +regeneratesplashpotion,373,16385 +regensplashpotion,373,16385 +splregenerationpotion,373,16385 +splregeneratepotion,373,16385 +splregenpotion,373,16385 +splregenerationpot,373,16385 +splregeneratepot,373,16385 +splregenpot,373,16385 +sprpot,373,16385 +splashswiftnesspotion,373,16386 +splashswiftpotion,373,16386 +splashspeedpotion,373,16386 +splashswiftnesspot,373,16386 +splashswiftpot,373,16386 +splashspeedpot,373,16386 +splswiftnesspotion,373,16386 +splswiftpotion,373,16386 +splspeedpotion,373,16386 +splswiftnesspot,373,16386 +splswiftpot,373,16386 +splspeedpot,373,16386 +spswpot,373,16386 +splashfireresistancepotion,373,16387 +splashfireresistpotion,373,16387 +splashfirerespotion,373,16387 +splashfireresistancepot,373,16387 +splashfireresistpot,373,16387 +splashfirerespot,373,16387 +splfireresistancepotion,373,16387 +splfireresistpotion,373,16387 +splfirerespotion,373,16387 +splfireresistancepot,373,16387 +splfireresistpot,373,16387 +splfirerespot,373,16387 +spfpot,373,16387 +splashpoisonpotion,373,16388 +splashacidpotion,373,16388 +splashpoisonpot,373,16388 +splashacidpot,373,16388 +splpoisonpotion,373,16388 +splacidpotion,373,16388 +splpoisonpot,373,16388 +splacidpot,373,16388 +spppot,373,16388 +splashhealingpotion,373,16389 +splashhealpotion,373,16389 +splashlifepotion,373,16389 +splashhealingpot,373,16389 +splashhealpot,373,16389 +splashlifepot,373,16389 +splhealingpotion,373,16389 +splhealpotion,373,16389 +spllifepotion,373,16389 +splhealingpot,373,16389 +splhealpot,373,16389 +spllifepot,373,16389 +sphpot,373,16389 +splashclearpotion,373,16390 +splashclearpot,373,16390 +splclearpotion,373,16390 +splclearpot,373,16390 +splashnightvisionpotion,373,16390 +splashnvisionpotion,373,16390 +splashnightvpotion,373,16390 +splashdarkvisionpotion,373,16390 +splashdvisionpotion,373,16390 +splashdarkvpotion,373,16390 +splashnightvisionpot,373,16390 +splashnvisionpot,373,16390 +splashnightvpot,373,16390 +splashdarkvisionpot,373,16390 +splashdvisionpot,373,16390 +splashdarkvpot,373,16390 +splnightvisionpotion,373,16390 +splnvisionpotion,373,16390 +splnightvpotion,373,16390 +spldarkvisionpotion,373,16390 +spldvisionpotion,373,16390 +spldarkvpotion,373,16390 +splnightvisionpot,373,16390 +splnvisionpot,373,16390 +splnightvpot,373,16390 +spldarkvisionpot,373,16390 +spldvisionpot,373,16390 +spldarkvpot,373,16390 +spnpot,373,16390 +splashclearextendedpotion,373,16391 +splashclearexpotion,373,16391 +splashclear2potion,373,16391 +splashclearextendedpot,373,16391 +splashclearexpot,373,16391 +splashclear2pot,373,16391 +splclearextendedpotion,373,16391 +splclearexpotion,373,16391 +splclear2potion,373,16391 +splclearextendedpot,373,16391 +splclearexpot,373,16391 +splclear2pot,373,16391 +splashweaknesspotion,373,16392 +splashweakpotion,373,16392 +splashweaknesspot,373,16392 +splashweakpot,373,16392 +splweaknesspotion,373,16392 +splweakpotion,373,16392 +splweaknesspot,373,16392 +splweakpot,373,16392 +spwpot,373,16392 +splashstrengthpotion,373,16393 +splashstrongpotion,373,16393 +splashstrpotion,373,16393 +splashstrengthpot,373,16393 +splashstrongpot,373,16393 +splashstrpot,373,16393 +splstrengthpotion,373,16393 +splstrongpotion,373,16393 +splstrpotion,373,16393 +splstrengthpot,373,16393 +splstrongpot,373,16393 +splstrpot,373,16393 +spstpot,373,16393 +splashslownesspotion,373,16394 +splashslowpotion,373,16394 +splashslownesspot,373,16394 +splashslowpot,373,16394 +splslownesspotion,373,16394 +splslowpotion,373,16394 +splslownesspot,373,16394 +splslowpot,373,16394 +spslpot,373,16394 +splashdiffusepotion,373,16395 +splashdiffusepot,373,16395 +spldiffusepotion,373,16395 +spldiffusepot,373,16395 +splashharmingpotion,373,16396 +splashdamagepotion,373,16396 +splashdmgpotion,373,16396 +splashharmingpot,373,16396 +splashdamagepot,373,16396 +splashdmgpot,373,16396 +splharmingpotion,373,16396 +spldamagepotion,373,16396 +spldmgpotion,373,16396 +splharmingpot,373,16396 +spldamagepot,373,16396 +spldmgpot,373,16396 +spdpot,373,16396 +splashartlesspotion,373,16397 +splashartlesspot,373,16397 +splartlesspotion,373,16397 +splartlesspot,373,16397 +splashwaterbreathingpotion,373,16397 +splashwaterbreathpotion,373,16397 +splashbreathingpotion,373,16397 +splashbreathpotion,373,16397 +splashwaterbreathingpot,373,16397 +splashwaterbreathpot,373,16397 +splashbreathingpot,373,16397 +splashbreathpot,373,16397 +splwaterbreathingpotion,373,16397 +splwaterbreathpotion,373,16397 +splbreathingpotion,373,16397 +splbreathpotion,373,16397 +splwaterbreathingpot,373,16397 +splwaterbreathpot,373,16397 +splbreathingpot,373,16397 +splbreathpot,373,16397 +spwbpot,373,16397 +splashthinpotion,373,16398 +splashthinpot,373,16398 +splthinpotion,373,16398 +splthinpot,373,16398 +splashinvisibilitypotion,373,16398 +splashinvisiblepotion,373,16398 +splashinvpotion,373,16398 +splashinvisibilitypot,373,16398 +splashinvisiblepot,373,16398 +splashinvpot,373,16398 +splinvisibilitypotion,373,16398 +splinvisiblepotion,373,16398 +splinvpotion,373,16398 +splinvisibilitypot,373,16398 +splinvisiblepot,373,16398 +splinvpot,373,16398 +spipot,373,16398 +splashthinextendedpotion,373,16399 +splashthinexpotion,373,16399 +splashthin2potion,373,16399 +splashthinextendedpot,373,16399 +splashthinexpot,373,16399 +splashthin2pot,373,16399 +splthinextendedpotion,373,16399 +splthinexpotion,373,16399 +splthin2potion,373,16399 +splthinextendedpot,373,16399 +splthinexpot,373,16399 +splthin2pot,373,16399 +splashawkwardpotion,373,16400 +splashawkwardpot,373,16400 +splawkwardpotion,373,16400 +splawkwardpot,373,16400 +splashbunglingpotion,373,16406 +splashbunglingpot,373,16406 +splbunglingpotion,373,16406 +splbunglingpot,373,16406 +splashbunglingextendedpotion,373,16407 +splashbunglingexpotion,373,16407 +splashbungling2potion,373,16407 +splashbunglingextendedpot,373,16407 +splashbunglingexpot,373,16407 +splashbungling2pot,373,16407 +splbunglingextendedpotion,373,16407 +splbunglingexpotion,373,16407 +splbungling2potion,373,16407 +splbunglingextendedpot,373,16407 +splbunglingexpot,373,16407 +splbungling2pot,373,16407 +splashsmoothpotion,373,16411 +splashsmoothpot,373,16411 +splsmoothpotion,373,16411 +splsmoothpot,373,16411 +splashsuavepotion,373,16413 +splashsuavepot,373,16413 +splsuavepotion,373,16413 +splsuavepot,373,16413 +splashdebonairpotion,373,16414 +splashdebonairpot,373,16414 +spldebonairpotion,373,16414 +spldebonairpot,373,16414 +splashdebonairextendedpotion,373,16415 +splashdebonairexpotion,373,16415 +splashdebonair2potion,373,16415 +splashdebonairextendedpot,373,16415 +splashdebonairexpot,373,16415 +splashdebonair2pot,373,16415 +spldebonairextendedpotion,373,16415 +spldebonairexpotion,373,16415 +spldebonair2potion,373,16415 +spldebonairextendedpot,373,16415 +spldebonairexpot,373,16415 +spldebonair2pot,373,16415 +splashthickpotion,373,16416 +splashthickpot,373,16416 +splthickpotion,373,16416 +splthickpot,373,16416 +splashregenerationleveliipotion,373,16417 +splashregenerateleveliipotion,373,16417 +splashregenleveliipotion,373,16417 +splashregenerationlevel2potion,373,16417 +splashregeneratelevel2potion,373,16417 +splashregenlevel2potion,373,16417 +splashregenerationiipotion,373,16417 +splashregenerateiipotion,373,16417 +splashregeniipotion,373,16417 +splashregenerationleveliipot,373,16417 +splashregenerateleveliipot,373,16417 +splashregenleveliipot,373,16417 +splashregenerationlevel2pot,373,16417 +splashregeneratelevel2pot,373,16417 +splashregenlevel2pot,373,16417 +splashregenerationiipot,373,16417 +splashregenerateiipot,373,16417 +splashregeniipot,373,16417 +splregenerationleveliipotion,373,16417 +splregenerateleveliipotion,373,16417 +splregenleveliipotion,373,16417 +splregenerationlevel2potion,373,16417 +splregeneratelevel2potion,373,16417 +splregenlevel2potion,373,16417 +splregenerationiipotion,373,16417 +splregenerateiipotion,373,16417 +splregeniipotion,373,16417 +splregenerationleveliipot,373,16417 +splregenerateleveliipot,373,16417 +splregenleveliipot,373,16417 +splregenerationlevel2pot,373,16417 +splregeneratelevel2pot,373,16417 +splregenlevel2pot,373,16417 +splregenerationiipot,373,16417 +splregenerateiipot,373,16417 +splregeniipot,373,16417 +spr2pot,373,16417 +splashswiftnessleveliipotion,373,16418 +splashswiftleveliipotion,373,16418 +splashspeedleveliipotion,373,16418 +splashswiftnesslevel2potion,373,16418 +splashswiftlevel2potion,373,16418 +splashspeedlevel2potion,373,16418 +splashswiftnessiipotion,373,16418 +splashswiftiipotion,373,16418 +splashspeediipotion,373,16418 +splashswiftnessleveliipot,373,16418 +splashswiftleveliipot,373,16418 +splashspeedleveliipot,373,16418 +splashswiftnesslevel2pot,373,16418 +splashswiftlevel2pot,373,16418 +splashspeedlevel2pot,373,16418 +splashswiftnessiipot,373,16418 +splashswiftiipot,373,16418 +splashspeediipot,373,16418 +splswiftnessleveliipotion,373,16418 +splswiftleveliipotion,373,16418 +splspeedleveliipotion,373,16418 +splswiftnesslevel2potion,373,16418 +splswiftlevel2potion,373,16418 +splspeedlevel2potion,373,16418 +splswiftnessiipotion,373,16418 +splswiftiipotion,373,16418 +splspeediipotion,373,16418 +splswiftnessleveliipot,373,16418 +splswiftleveliipot,373,16418 +splspeedleveliipot,373,16418 +splswiftnesslevel2pot,373,16418 +splswiftlevel2pot,373,16418 +splspeedlevel2pot,373,16418 +splswiftnessiipot,373,16418 +splswiftiipot,373,16418 +splspeediipot,373,16418 +spsw2pot,373,16418 +splashpoisonleveliipotion,373,16420 +splashacidleveliipotion,373,16420 +splashpoisonlevel2potion,373,16420 +splashacidlevel2potion,373,16420 +splashpoisoniipotion,373,16420 +splashacidiipotion,373,16420 +splashpoisonleveliipot,373,16420 +splashacidleveliipot,373,16420 +splashpoisonlevel2pot,373,16420 +splashacidlevel2pot,373,16420 +splashpoisoniipot,373,16420 +splashacidiipot,373,16420 +splpoisonleveliipotion,373,16420 +splacidleveliipotion,373,16420 +splpoisonlevel2potion,373,16420 +splcidlevel2potion,373,16420 +splpoisoniipotion,373,16420 +splacidiipotion,373,16420 +splpoisonleveliipot,373,16420 +splacidleveliipot,373,16420 +splpoisonlevel2pot,373,16420 +splacidlevel2pot,373,16420 +splpoisoniipot,373,16420 +splacidiipot,373,16420 +spp2pot,373,16420 +splashhealingleveliipotion,373,16421 +splashhealleveliipotion,373,16421 +splashhealinglevel2potion,373,16421 +splashheallevel2potion,373,16421 +splashhealingiipotion,373,16421 +splashhealiipotion,373,16421 +splashhealingleveliipot,373,16421 +splashhealleveliipot,373,16421 +splashhealinglevel2pot,373,16421 +splashheallevel2pot,373,16421 +splashhealingiipot,373,16421 +splashhealiipot,373,16421 +splhealingleveliipotion,373,16421 +splhealleveliipotion,373,16421 +splhealinglevel2potion,373,16421 +splheallevel2potion,373,16421 +splhealingiipotion,373,16421 +splhealiipotion,373,16421 +splhealingleveliipot,373,16421 +splhealleveliipot,373,16421 +splhealinglevel2pot,373,16421 +splheallevel2pot,373,16421 +splhealingiipot,373,16421 +splhealiipot,373,16421 +sph2pot,373,16421 +splashcharmingpotion,373,16422 +splashcharmingpot,373,16422 +splcharmingpotion,373,16422 +splcharmingpot,373,16422 +splashcharmingextendedpotion,373,16423 +splashcharmingexpotion,373,16423 +splashcharming2potion,373,16423 +splashcharmingextendedpot,373,16423 +splashcharmingexpot,373,16423 +splashcharming2pot,373,16423 +splcharmingextendedpotion,373,16423 +splcharmingexpotion,373,16423 +splcharming2potion,373,16423 +splcharmingextendedpot,373,16423 +splcharmingexpot,373,16423 +splcharming2pot,373,16423 +splashstrengthleveliipotion,373,16425 +splashstrongleveliipotion,373,16425 +splashstrleveliipotion,373,16425 +splashstrengthlevel2potion,373,16425 +splashstronglevel2potion,373,16425 +splashstrlevel2potion,373,16425 +splashstrengthiipotion,373,16425 +splashstrongiipotion,373,16425 +splashstriipotion,373,16425 +splashstrengthleveliipot,373,16425 +splashstrongleveliipot,373,16425 +splashstrleveliipot,373,16425 +splashstrengthlevel2pot,373,16425 +splashstronglevel2pot,373,16425 +splashstrlevel2pot,373,16425 +splashstrengthiipot,373,16425 +splashstrongiipot,373,16425 +splashstriipot,373,16425 +splstrengthleveliipotion,373,16425 +splstrongleveliipotion,373,16425 +splstrleveliipotion,373,16425 +splstrengthlevel2potion,373,16425 +splstronglevel2potion,373,16425 +splstrlevel2potion,373,16425 +splstrengthiipotion,373,16425 +splstrongiipotion,373,16425 +splstriipotion,373,16425 +splstrengthleveliipot,373,16425 +splstrongleveliipot,373,16425 +splstrleveliipot,373,16425 +splstrengthlevel2pot,373,16425 +splstronglevel2pot,373,16425 +splstrlevel2pot,373,16425 +splstrengthiipot,373,16425 +splstrongiipot,373,16425 +splstriipot,373,16425 +spst2pot,373,16425 +splashrefinedpotion,373,16427 +splashrefinedpot,373,16427 +splrefinedpotion,373,16427 +splrefinedpot,373,16427 +splashharmingleveliipotion,373,16428 +splashdamageleveliipotion,373,16428 +splashdmgleveliipotion,373,16428 +splashharminglevel2potion,373,16428 +splashdamagelevel2potion,373,16428 +splashdmglevel2potion,373,16428 +splashharmingiipotion,373,16428 +splashdamageiipotion,373,16428 +splashdmgiipotion,373,16428 +splashharmingleveliipot,373,16428 +splashdamageleveliipot,373,16428 +splashdmgleveliipot,373,16428 +splashharminglevel2pot,373,16428 +splashdamagelevel2pot,373,16428 +splashdmglevel2pot,373,16428 +splashharmingiipot,373,16428 +splashdamageiipot,373,16428 +splashdmgiipot,373,16428 +splharmingleveliipotion,373,16428 +spldamageleveliipotion,373,16428 +spldmgleveliipotion,373,16428 +splharminglevel2potion,373,16428 +spldamagelevel2potion,373,16428 +spldmglevel2potion,373,16428 +splharmingiipotion,373,16428 +spldamageiipotion,373,16428 +spldmgiipotion,373,16428 +splharmingleveliipot,373,16428 +spldamageleveliipot,373,16428 +spldmgleveliipot,373,16428 +splharminglevel2pot,373,16428 +spldamagelevel2pot,373,16428 +spldmglevel2pot,373,16428 +splharmingiipot,373,16428 +spldamageiipot,373,16428 +spldmgiipot,373,16428 +spd2pot,373,16428 +splashcordialpotion,373,16429 +splashcordialpot,373,16429 +splcordialpotion,373,16429 +splcordialpot,373,16429 +splashsparklingpotion,373,16430 +splashsparklingpot,373,16430 +splsparklingpotion,373,16430 +splsparklingpot,373,16430 +splashsparklingextendedpotion,373,16431 +splashsparklingexpotion,373,16431 +splashsparkling2potion,373,16431 +splashsparklingextendedpot,373,16431 +splashsparklingexpot,373,16431 +splashsparkling2pot,373,16431 +splsparklingextendedpotion,373,16431 +splsparklingexpotion,373,16431 +splsparkling2potion,373,16431 +splsparklingextendedpot,373,16431 +splsparklingexpot,373,16431 +splsparkling2pot,373,16431 +splashpotentpotion,373,16432 +splashpotentpot,373,16432 +splpotentpotion,373,16432 +splpotentpot,373,16432 +splashrankpotion,373,16438 +splashrankpot,373,16438 +splrankpotion,373,16438 +splrankpot,373,16438 +splashrankextendedpotion,373,16439 +splashrankexpotion,373,16439 +splashrank2potion,373,16439 +splashrankextendedpot,373,16439 +splashrankexpot,373,16439 +splashrank2pot,373,16439 +splrankextendedpotion,373,16439 +splrankexpotion,373,16439 +splrank2potion,373,16439 +splrankextendedpot,373,16439 +splrankexpot,373,16439 +splrank2pot,373,16439 +splashacridpotion,373,16443 +splashacridpot,373,16443 +splacridpotion,373,16443 +splacridpot,373,16443 +splashgrosspotion,373,16445 +splashgrosspot,373,16445 +splgrosspotion,373,16445 +splgrosspot,373,16445 +splashstinkypotion,373,16446 +splashstinkypot,373,16446 +splstinkypotion,373,16446 +splstinkypot,373,16446 +splashstinkyextendedpotion,373,16447 +splashstinkyexpotion,373,16447 +splashstinky2potion,373,16447 +splashstinkyextendedpot,373,16447 +splashstinkyexpot,373,16447 +splashstinky2pot,373,16447 +splstinkyextendedpotion,373,16447 +splstinkyexpotion,373,16447 +splstinky2potion,373,16447 +splstinkyextendedpot,373,16447 +splstinkyexpot,373,16447 +splstinky2pot,373,16447 +splashmundaneextendedpotion,373,16448 +splashmundaneexpotion,373,16448 +splashmundane2potion,373,16448 +splashmundaneextendedpot,373,16448 +splashmundaneexpot,373,16448 +splashmundane2pot,373,16448 +splmundaneextendedpotion,373,16448 +splmundaneexpotion,373,16448 +splmundane2potion,373,16448 +splmundaneextendedpot,373,16448 +splmundaneexpot,373,16448 +splmundane2pot,373,16448 +splashregenerationextendedpotion,373,16449 +splashregenerateextendedpotion,373,16449 +splashregenextendepotion,373,16449 +splashregenerationexpotion,373,16449 +splashregenerateexpotion,373,16449 +splashregenexpotion,373,16449 +splashregenerationextendedpot,373,16449 +splashregenerateextendedpot,373,16449 +splashregenextendepot,373,16449 +splashregenerationexpot,373,16449 +splashregenerateexpot,373,16449 +splashregenexpot,373,16449 +splregenerationextendedpotion,373,16449 +splregenerateextendedpotion,373,16449 +splregenextendepotion,373,16449 +splregenerationexpotion,373,16449 +splregenerateexpotion,373,16449 +splregenexpotion,373,16449 +splregenerationextendedpot,373,16449 +splregenerateextendedpot,373,16449 +splregenextendepot,373,16449 +splregenerationexpot,373,16449 +splregenerateexpot,373,16449 +splregenexpot,373,16449 +sprepot,373,16449 +splashswiftnessextendedpotion,373,16450 +splashswiftextendedpotion,373,16450 +splashspeedextendedpotion,373,16450 +splashswiftnessexpotion,373,16450 +splashswiftexpotion,373,16450 +splashspeedexpotion,373,16450 +splashswiftnessextendedpot,373,16450 +splashswiftextendedpot,373,16450 +splashspeedextendedpot,373,16450 +splashswiftnessexpot,373,16450 +splashswiftexpot,373,16450 +splashspeedexpot,373,16450 +splswiftnessextendedpotion,373,16450 +splswiftextendedpotion,373,16450 +splspeedextendedpotion,373,16450 +splswiftnessexpotion,373,16450 +splswiftexpotion,373,16450 +splspeedexpotion,373,16450 +splswiftnessextendedpot,373,16450 +splswiftextendedpot,373,16450 +splspeedextendedpot,373,16450 +splswiftnessexpot,373,16450 +splswiftexpot,373,16450 +splspeedexpot,373,16450 +spswepot,373,16450 +splashfireresistanceextendedpotion,373,16451 +splashfireresistextendedpotion,373,16451 +splashfireresextendedpotion,373,16451 +splashfireresistanceexpotion,373,16451 +splashfireresistexpotion,373,16451 +splashfireresexpotion,373,16451 +splashfireresistanceextendedpot,373,16451 +splashfireresistextendedpot,373,16451 +splashfireresextendedpot,373,16451 +splashfireresistanceexpot,373,16451 +splashfireresistexpot,373,16451 +splashfireresexpot,373,16451 +splfireresistanceextendedpotion,373,16451 +splfireresistextendedpotion,373,16451 +splfireresextendedpotion,373,16451 +splfireresistanceexpotion,373,16451 +splfireresistexpotion,373,16451 +splfireresexpotion,373,16451 +splfireresistanceextendedpot,373,16451 +splfireresistextendedpot,373,16451 +splfireresextendedpot,373,16451 +splfireresistanceexpot,373,16451 +splfireresistexpot,373,16451 +splfireresexpot,373,16451 +spfepot,373,16451 +splashpoisonextendedpotion,373,16452 +splashacidextendedpotion,373,16452 +splashpoisonexpotion,373,16452 +splashacidexpotion,373,16452 +splashpoisonextendedpot,373,16452 +splashacidextendedpot,373,16452 +splashpoisonexpot,373,16452 +splashacidexpot,373,16452 +splpoisonextendedpotion,373,16452 +splacidextendedpotion,373,16452 +splpoisonexpotion,373,16452 +splacidexpotion,373,16452 +splpoisonextendedpot,373,16452 +splacidextendedpot,373,16452 +splpoisonexpot,373,16452 +splacidexpot,373,16452 +sppepot,373,16452 +splashnightvisionextendedpotion,373,16454 +splashnvisionextendedpotion,373,16454 +splashnightvextendedpotion,373,16454 +splashdarkvisionextendedpotion,373,16454 +splashdvisionextendedpotion,373,16454 +splashdarkvextendedpotion,373,16454 +splashnightvisionextendedpot,373,16454 +splashnvisionextendedpot,373,16454 +splashnightvextendedpot,373,16454 +splashdarkvisionextendedpot,373,16454 +splashdvisionextendedpot,373,16454 +splashdarkvextendedpot,373,16454 +splashnightvisionexpotion,373,16454 +splashnvisionexpotion,373,16454 +splashnightvexpotion,373,16454 +splashdarkvisionexpotion,373,16454 +splashdvisionexpotion,373,16454 +splashdarkvexpotion,373,16454 +splashnightvisionexpot,373,16454 +splashnvisionexpot,373,16454 +splashnightvexpot,373,16454 +splashdarkvisionexpot,373,16454 +splashdvisionexpot,373,16454 +splashdarkvexpot,373,16454 +splnightvisionextendedpotion,373,16454 +splnvisionextendedpotion,373,16454 +splnightvextendedpotion,373,16454 +spldarkvisionextendedpotion,373,16454 +spldvisionextendedpotion,373,16454 +spldarkvextendedpotion,373,16454 +splnightvisionextendedpot,373,16454 +splnvisionextendedpot,373,16454 +splnightvextendedpot,373,16454 +spldarkvisionextendedpot,373,16454 +spldvisionextendedpot,373,16454 +spldarkvextendedpot,373,16454 +splnightvisionexpotion,373,16454 +splnvisionexpotion,373,16454 +splnightvexpotion,373,16454 +spldarkvisionexpotion,373,16454 +spldvisionexpotion,373,16454 +spldarkvexpotion,373,16454 +splnightvisionexpot,373,16454 +splnvisionexpot,373,16454 +splnightvexpot,373,16454 +spldarkvisionexpot,373,16454 +spldvisionexpot,373,16454 +spldarkvexpot,373,16454 +spnepot,373,16454 +splashweaknessextendedpotion,373,16456 +splashweakextendedpotion,373,16456 +splashweaknessexpotion,373,16456 +splashweakexpotion,373,16456 +splashweaknessextendedpot,373,16456 +splashweakextendedpot,373,16456 +splashweaknessexpot,373,16456 +splashweakexpot,373,16456 +splweaknessextendedpotion,373,16456 +sphweakextendedpotion,373,16456 +splweaknessexpotion,373,16456 +splweakexpotion,373,16456 +splweaknessextendedpot,373,16456 +splweakextendedpot,373,16456 +splweaknessexpot,373,16456 +splweakexpot,373,16456 +spwepot,373,16456 +splashstrengthextendedpotion,373,16457 +splashstrongextendedpotion,373,16457 +splashstrextendedpotion,373,16457 +splashstrengthexpotion,373,16457 +splashstrongexpotion,373,16457 +splashstrexpotion,373,16457 +splashstrengthextendedpot,373,16457 +splashstrongextendedpot,373,16457 +splashstrextendedpot,373,16457 +splashstrengthexpot,373,16457 +splashstrongexpot,373,16457 +splashstrexpot,373,16457 +splstrengthextendedpotion,373,16457 +splstrongextendedpotion,373,16457 +splstrextendedpotion,373,16457 +splstrengthexpotion,373,16457 +splstrongexpotion,373,16457 +splstrexpotion,373,16457 +splstrengthextendedpot,373,16457 +splstrongextendedpot,373,16457 +splstrextendedpot,373,16457 +splstrengthexpot,373,16457 +splstrongexpot,373,16457 +splstrexpot,373,16457 +spstepot,373,16457 +splashslownessextendedpotion,373,16458 +splashslowextenedpotion,373,16458 +splashslownessexpotion,373,16458 +splashslowexpotion,373,16458 +splashslownessextendedpot,373,16458 +splashslowextenedpot,373,16458 +splashslownessexpot,373,16458 +splashslowexpot,373,16458 +splslownessextendedpotion,373,16458 +splslowextenedpotion,373,16458 +splslownessexpotion,373,16458 +splslowexpotion,373,16458 +splslownessextendedpot,373,16458 +splslowextenedpot,373,16458 +splslownessexpot,373,16458 +splslowexpot,373,16458 +spslepot,373,16458 +splashwaterbreathingextendedpotion,373,16461 +splashwaterbreathextendedpotion,373,16461 +splashbreathingextendedpotion,373,16461 +splashbreathextendedpotion,373,16461 +splashwaterbreathingextendedpot,373,16461 +splashwaterbreathextendedpot,373,16461 +splashbreathingextendedpot,373,16461 +splashbreathextendedpot,373,16461 +splwaterbreathingextendedpotion,373,16461 +splwaterbreathextendedpotion,373,16461 +splbreathingextendedpotion,373,16461 +splbreathextendedpotion,373,16461 +splwaterbreathingextendedpot,373,16461 +splwaterbreathextendedpot,373,16461 +splbreathingextendedpot,373,16461 +splbreathextendedpot,373,16461 +splashwaterbreathingexpotion,373,16461 +splashwaterbreathexpotion,373,16461 +splashbreathingexpotion,373,16461 +splashbreathexpotion,373,16461 +splashwaterbreathingexpot,373,16461 +splashwaterbreathexpot,373,16461 +splashbreathingexpot,373,16461 +splashbreathexpot,373,16461 +splwaterbreathingexpotion,373,16461 +splwaterbreathexpotion,373,16461 +splbreathingexpotion,373,16461 +splbreathexpotion,373,16461 +splwaterbreathingexpot,373,16461 +splwaterbreathexpot,373,16461 +splbreathingexpot,373,16461 +splbreathexpot,373,16461 +spwbepot,373,16461 +splashinvisibilityextendedpotion,373,16462 +splashinvisibleextendedpotion,373,16462 +splashinvextendedpotion,373,16462 +splashinvisibilityextendedpot,373,16462 +splashinvisibleextendedpot,373,16462 +splashinvextendedpot,373,16462 +splashinvisibilityexpotion,373,16462 +splashinvisibleexpotion,373,16462 +splashinvexpotion,373,16462 +splashinvisibilityexpot,373,16462 +splashinvisibleexpot,373,16462 +splashinvexpot,373,16462 +splinvisibilityextendedpotion,373,16462 +splinvisibleextendedpotion,373,16462 +splinvextendedpotion,373,16462 +splinvisibilityextendedpot,373,16462 +splinvisibleextendedpot,373,16462 +splinvextendedpot,373,16462 +splinvisibilityexpotion,373,16462 +splinvisibleexpotion,373,16462 +splinvexpotion,373,16462 +splinvisibilityexpot,373,16462 +splinvisibleexpot,373,16462 +splinvexpot,373,16462 +spiepot,373,16462 +splashregenerationdualbitpotion,373,16481 +splashregeneratedualbitpotion,373,16481 +splashregendualbitpotion,373,16481 +splashregenerationdualbitpot,373,16481 +splashregeneratedualbitpot,373,16481 +splashregendualbitpot,373,16481 +splregenerationdualbitpotion,373,16481 +splregeneratedualbitpotion,373,16481 +splregendualbitpotion,373,16481 +splregenerationdualbitpot,373,16481 +splregeneratedualbitpot,373,16481 +splregendualbitpot,373,16481 +splashregenerationdbpotion,373,16481 +splashregeneratedbpotion,373,16481 +splashregendbpotion,373,16481 +splashregenerationdbpot,373,16481 +splashregeneratedbpot,373,16481 +splashregendbpot,373,16481 +splregenerationdbpotion,373,16481 +splregeneratedbpotion,373,16481 +splregendbpotion,373,16481 +splregenerationdbpot,373,16481 +splregeneratedbpot,373,16481 +splregendbpot,373,16481 +sprdbpot,373,16481 +splashswiftnessdualbitpotion,373,16482 +splashswiftdualbitpotion,373,16482 +splashspeeddualbitpotion,373,16482 +splashswiftnessdualbitpot,373,16482 +splashswiftdualbitpot,373,16482 +splashspeeddualbitpot,373,16482 +splswiftnessdualbitpotion,373,16482 +splswiftdualbitpotion,373,16482 +splspeeddualbitpotion,373,16482 +splswiftnessdualbitpot,373,16482 +splswiftdualbitpot,373,16482 +splspeeddualbitpot,373,16482 +splashswiftnessdbpotion,373,16482 +splashswiftdbpotion,373,16482 +splashspeeddbpotion,373,16482 +splashswiftnessdbpot,373,16482 +splashswiftdbpot,373,16482 +splashspeeddbpot,373,16482 +splswiftnessdbpotion,373,16482 +splswiftdbpotion,373,16482 +splspeeddbpotion,373,16482 +splswiftnessdbpot,373,16482 +splswiftdbpot,373,16482 +splspeeddbpot,373,16482 +spswdbpot,373,16482 +splashpoisondualbitpotion,373,16484 +splashaciddualbitpotion,373,16484 +splashpoisondualbitpot,373,16484 +splashaciddualbitpot,373,16484 +splpoisondualbitpotion,373,16484 +splaciddualbitpotion,373,16484 +splpoisondualbitpot,373,16484 +splaciddualbitpot,373,16484 +splashpoisondbpotion,373,16484 +splashaciddbpotion,373,16484 +splashpoisondbpot,373,16484 +splashaciddbpot,373,16484 +splpoisondbpotion,373,16484 +splaciddbpotion,373,16484 +splpoisondbpot,373,16484 +splaciddbpot,373,16484 +sppdbpot,373,16484 +splashstrengthdualbitpotion,373,16489 +splashstrongdualbitpotion,373,16489 +splashstrdualbitpotion,373,16489 +splashstrengthdualbitpot,373,16489 +splashstrongdualbitpot,373,16489 +splashstrdualbitpot,373,16489 +splstrengthdualbitpotion,373,16489 +splstrongdualbitpotion,373,16489 +splstrdualbitpotion,373,16489 +splstrengthdualbitpot,373,16489 +splstrongdualbitpot,373,16489 +splstrdualbitpot,373,16489 +splashstrengthdbpotion,373,16489 +splashstrongdbpotion,373,16489 +splashstrdbpotion,373,16489 +splashstrengthdbpot,373,16489 +splashstrongdbpot,373,16489 +splashstrdbpot,373,16489 +splstrengthdbpotion,373,16489 +splstrongdbpotion,373,16489 +splstrdbpotion,373,16489 +splstrengthdbpot,373,16489 +splstrongdbpot,373,16489 +splstrdbpot,373,16489 +spstdbpot,373,16489 +glassbottle,374,0 +bottle,374,0 +gbottle,374,0 +gvase,374,0 +vase,374,0 +glassvase,374,0 +emptyglassbottle,374,0 +emptybottle,374,0 +emptygbottle,374,0 +emptygvase,374,0 +emptyvase,374,0 +emptyglassvase,374,0 +eglassbottle,374,0 +ebottle,374,0 +egbottle,374,0 +egvase,374,0 +evase,374,0 +eglassvase,374,0 +spidereye,375,0 +eyeofspider,375,0 +seye,375,0 +fermentedspidereye,376,0 +craftedspidereye,376,0 +fspidereye,376,0 +cspidereye,376,0 +fermentedeyeofspider,376,0 +craftedeyeofspider,376,0 +feyeofspider,376,0 +ceyeofspider,376,0 +fermentedseye,376,0 +craftedseye,376,0 +fseye,376,0 +cseye,376,0 +blazepowder,377,0 +blazedust,377,0 +goldpowder,377,0 +golddust,377,0 +gdust,377,0 +gpowder,377,0 +bpowder,377,0 +bdust,377,0 +magmacream,378,0 +goldcream,378,0 +blazecream,378,0 +mcream,378,0 +gcream,378,0 +bcream,378,0 +combinedcream,378,0 +ccream,378,0 +bstand,379,0 +pstand,379,0 +brewingstand,379,0 +potionstand,379,0 +cauldron,380,0 +steelcauldron,380,0 +ironcauldron,380,0 +icauldron,380,0 +scauldron,380,0 +potioncauldron,380,0 +pcauldron,380,0 +eyeofender,381,0 +endereye,381,0 +endeye,381,0 +evilendereye,381,0 +evileyeofender,381,0 +evilenderpearl,381,0 +eeye,381,0 +eofender,381,0 +glisteringmelon,382,0 +speckledmelon,382,0 +goldmelon,382,0 +sparklymelon,382,0 +shiningmelon,382,0 +gmelon,382,0 +smelon,382,0 +creeperegg,383,50 +eggcreeper,383,50 +skeletonegg,383,51 +eggskeleton,383,51 +spideregg,383,52 +eggspider,383,52 +giantegg,383,53 +egggiant,383,53 +zombieegg,383,54 +eggzombie,383,54 +slimeegg,383,55 +eggslime,383,55 +ghastegg,383,56 +eggghast,383,56 +zombiepigmanegg,383,57 +zpigmanegg,383,57 +pigmanegg,383,57 +zombiepmanegg,383,57 +zpmanegg,383,57 +zombiepigmegg,383,57 +zpigmegg,383,57 +zombiepigegg,383,57 +zpigegg,383,57 +zombiepmegg,383,57 +zombiepegg,383,57 +eggzombiepigman,383,57 +eggzpigman,383,57 +eggpigman,383,57 +eggzombiepman,383,57 +eggzpman,383,57 +eggzombiepigm,383,57 +eggzpigm,383,57 +eggzombiepig,383,57 +eggzpig,383,57 +eggzombiepm,383,57 +eggzombiep,383,57 +endermanegg,383,58 +eggenderman,383,58 +eggcavespider,383,59 +cavespideregg,383,59 +silverfishegg,383,60 +eggsilverfish,383,60 +blazeegg,383,61 +eggblaze,383,61 +lavaslimeegg,383,62 +lavacubeegg,383,62 +magmacubeegg,383,62 +magmaslimeegg,383,62 +egglavaslime,383,62 +egglavacube,383,62 +eggmagmacube,383,62 +eggmagmaslime,383,62 +bategg,383,65 +eggbat,383,65 +witchegg,383,66 +eggwitch,383,66 +pigegg,383,90 +eggpig,383,90 +sheepegg,383,91 +eggsheep,383,91 +cowegg,383,92 +eggcow,383,92 +chickenegg,383,93 +eggchicken,383,93 +squidegg,383,94 +eggsquid,383,94 +wolfegg,383,95 +eggwolf,383,95 +mooshroomegg,383,96 +mushroomcowegg,383,96 +eggmooshroom,383,96 +eggmushroomcow,383,96 +snowgolemegg,383,97 +sgolemegg,383,97 +eggsnowgolem,383,97 +eggsgolem,383,97 +ocelotegg,383,98 +eggocelot,383,98 +irongolemegg,383,99 +igolemegg,383,99 +eggirongolem,383,99 +eggigolem,383,99 +egghorse,383,100 +horseegg,383,100 +villageregg,383,120 +eggvillager,383,120 +bottleofenchanting,384,0 +enchantingbottle,384,0 +expbottle,384,0 +xpbottle,384,0 +bottleexp,384,0 +bottlexp,384,0 +enchantbottle,384,0 +bottleenchanting,384,0 +bottleenchant,384,0 +bottleoenchanting,384,0 +firecharge,385,0 +fireball,385,0 +grenade,385,0 +bookandquill,386,0 +booknquill,386,0 +bookandfeather,386,0 +booknfeather,386,0 +writeablebook,386,0 +writtenbook,387,0 +readablebook,387,0 +sealedbook,387,0 +diary,387,0 +ownedbook,387,0 +emerald,388,0 +itemframe,389,0 +pictureframe,389,0 +iframe,389,0 +pframe,389,0 +flowerpot,390,0 +pot,390,0 +carrot,391,0 +potato,392,0 +rawpotato,392,0 +bakedpotato,393,0 +roastedpotato,393,0 +cookedpotato,393,0 +bakepotato,393,0 +roastpotato,393,0 +cookpotato,393,0 +bpotato,393,0 +rpotato,393,0 +cpotato,393,0 +poisonouspotato,394,0 +poisonpotato,394,0 +ppotato,394,0 +emptymap,395,0 +map,395,0 +goldencarrot,396,0 +goldcarrot,396,0 +gcarrot,396,0 +head,397,0 +skull,397,0 +skeletonhead,397,0 +headskeleton,397,0 +skeletonskull,397,0 +skullskeleton,397,0 +witherhead,397,1 +witherskeletonhead,397,1 +wskeletionhead,397,1 +headwither,397,1 +headwitherskeleton,397,1 +headwskeletion,397,1 +witherskull,397,1 +witherskeletonskull,397,1 +wskeletionskull,397,1 +skullwither,397,1 +skullwitherskeleton,397,1 +skullwskeletion,397,1 +zombiehead,397,2 +headzombie,397,2 +zombieskull,397,2 +skullzombie,397,2 +playerhead,397,3 +humanhead,397,3 +stevehead,397,3 +headplayer,397,3 +headhuman,397,3 +headsteve,397,3 +playerskull,397,3 +humanskull,397,3 +steveskull,397,3 +skullplayer,397,3 +skullhuman,397,3 +skullsteve,397,3 +creeperhead,397,4 +headcreeper,397,4 +creeperskull,397,4 +skullcreeper,397,4 +carrotonastick,398,0 +carrotonstick,398,0 +netherstar,399,0 +hellstar,399,0 +nstar,399,0 +hstar,399,0 +star,399,0 +pumpkinpie,400,0 +pumpkincake,400,0 +ppie,400,0 +pcake,400,0 +pie,400,0 +fireworkrocket,401,0 +fireworkmissle,401,0 +firework,401,0 +fworkrocket,401,0 +fworkmissle,401,0 +fwork,401,0 +fwrocket,401,0 +fwmissle,401,0 +fireworkstar,402,0 +fworkstar,402,0 +fwstar,402,0 +fireworkball,402,0 +fworkball,402,0 +fwball,402,0 +fireworkpowder,402,0 +fworkpowder,402,0 +fwpowder,402,0 +fireworkcharge,402,0 +fworkcharge,402,0 +fwcharge,402,0 +enchantedbook,403,0 +enchantmentbook,403,0 +enchantingbook,403,0 +enchantbook,403,0 +magicalbook,403,0 +magicbook,403,0 +ebook,403,0 +mbook,403,0 +redstonecomparator,404,0 +redstonecomparer,404,0 +redstonecompare,404,0 +rstonecomparator,404,0 +rstonecomparer,404,0 +rstonecompare,404,0 +redscomparator,404,0 +redscomparer,404,0 +redscompare,404,0 +rscomparator,404,0 +rscomparer,404,0 +rscompare,404,0 +comparator,404,0 +comparer,404,0 +compare,404,0 +netherbrick,405,0 +nbrick,405,0 +hellbrick,405,0 +deathbrick,405,0 +dbrick,405,0 +hbrick,405,0 +netherquartz,406,0 +deathquartz,406,0 +hellquartz,406,0 +nquartz,406,0 +dquartz,406,0 +hquartz,406,0 +quartz,406,0 +tntminecart,407,0 +dynamiteminecart,407,0 +dynamitemcart,407,0 +dynamitecart,407,0 +bombminecart,407,0 +bombmcart,407,0 +bombcart,407,0 +tntmcart,407,0 +tntcart,407,0 +dminecart,407,0 +dmcart,407,0 +dcart,407,0 +bminecart,407,0 +bmcart,407,0 +bcart,407,0 +tminecart,407,0 +tmcart,407,0 +tcart,407,0 +hopperminecart,408,0 +hoppermcart,408,0 +hoppercart,408,0 +hopminecart,408,0 +hopmcart,408,0 +hopcart,408,0 +hminecart,408,0 +hmcart,408,0 +hcart,408,0 +ironhorsearmor,417,0 +ironharmor,417,0 +ironarmor,417,0 +ihorsearmor,417,0 +iharmor,417,0 +iarmor,417,0 +steelhorsearmor,417,0 +steelharmor,417,0 +steelarmor,417,0 +shorsearmor,417,0 +sharmor,417,0 +sarmor,417,0 +goldenhorsearmor,418,0 +goldenharmor,418,0 +goldenarmor,418,0 +goldhorsearmor,418,0 +goldharmor,418,0 +goldarmor,418,0 +ghorsearmor,418,0 +gharmor,418,0 +garmor,418,0 +diamondhorsearmor,419,0 +diamondharmor,419,0 +diamondarmor,419,0 +dhorsearmor,419,0 +dharmor,419,0 +darmor,419,0 +crystalhorsearmor,419,0 +crystalharmor,419,0 +crystalarmor,419,0 +chorsearmor,419,0 +charmor,419,0 +carmor,419,0 +lead,420,0 +leash,420,0 +rope,420,0 +nametag,421,0 +tag,421,0 +commandblockminecart,422,0 +cmdblockminecart,422,0 +cblockminecart,422,0 +commandminecart,422,0 +cmdminecart,422,0 +cbminecart,422,0 +commandblockcart,422,0 +cmdblockcart,422,0 +cblockcart,422,0 +commandcart,422,0 +cmdcart,422,0 +cbcart,422,0 +13disc,2256,0 +goldmusicrecord,2256,0 +goldmusicdisk,2256,0 +goldmusicdisc,2256,0 +goldmusiccd,2256,0 +13musicrecord,2256,0 +13musicdisk,2256,0 +13musicdisc,2256,0 +13musiccd,2256,0 +gomusicrecord,2256,0 +gomusicdisk,2256,0 +gomusicdisc,2256,0 +gomusiccd,2256,0 +goldmrecord,2256,0 +goldmdisk,2256,0 +goldmdisc,2256,0 +goldmcd,2256,0 +13mrecord,2256,0 +13mdisk,2256,0 +13mdisc,2256,0 +13mcd,2256,0 +gomrecord,2256,0 +gomdisk,2256,0 +gomdisc,2256,0 +gomcd,2256,0 +goldrecord,2256,0 +golddisk,2256,0 +golddisc,2256,0 +goldcd,2256,0 +13record,2256,0 +13disk,2256,0 +13cd,2256,0 +gorecord,2256,0 +godisk,2256,0 +godisc,2256,0 +gocd,2256,0 +record1,2256,0 +disk1,2256,0 +disc1,2256,0 +cd1,2256,0 +1record,2256,0 +1disk,2256,0 +1disc,2256,0 +1cd,2256,0 +catdisc,2257,0 +greenmusicrecord,2257,0 +greenmusicdisk,2257,0 +greenmusicdisc,2257,0 +greenmusiccd,2257,0 +catmusicrecord,2257,0 +catmusicdisk,2257,0 +catmusicdisc,2257,0 +catmusiccd,2257,0 +grmusicrecord,2257,0 +grmusicdisk,2257,0 +grmusicdisc,2257,0 +grmusiccd,2257,0 +greenmrecord,2257,0 +greenmdisk,2257,0 +greenmdisc,2257,0 +greenmcd,2257,0 +catmrecord,2257,0 +catmdisk,2257,0 +catmdisc,2257,0 +catmcd,2257,0 +grmrecord,2257,0 +grmdisk,2257,0 +grmdisc,2257,0 +grmcd,2257,0 +greenrecord,2257,0 +greendisk,2257,0 +greendisc,2257,0 +greencd,2257,0 +catrecord,2257,0 +catdisk,2257,0 +catcd,2257,0 +grrecord,2257,0 +grdisk,2257,0 +grdisc,2257,0 +grcd,2257,0 +record2,2257,0 +disk2,2257,0 +disc2,2257,0 +cd2,2257,0 +2record,2257,0 +2disk,2257,0 +2disc,2257,0 +2cd,2257,0 +blocksdisc,2258,0 +orangemusicrecord,2258,0 +orangemusicdisk,2258,0 +orangemusicdisc,2258,0 +orangemusiccd,2258,0 +blocksmusicrecord,2258,0 +blocksmusicdisk,2258,0 +blocksmusicdisc,2258,0 +blocksmusiccd,2258,0 +ormusicrecord,2258,0 +ormusicdisk,2258,0 +ormusicdisc,2258,0 +ormusiccd,2258,0 +orangemrecord,2258,0 +orangemdisk,2258,0 +orangemdisc,2258,0 +orangemcd,2258,0 +blocksmrecord,2258,0 +blocksmdisk,2258,0 +blocksmdisc,2258,0 +blocksmcd,2258,0 +ormrecord,2258,0 +ormdisk,2258,0 +ormdisc,2258,0 +ormcd,2258,0 +orangerecord,2258,0 +orangedisk,2258,0 +orangedisc,2258,0 +orangecd,2258,0 +blocksrecord,2258,0 +blocksdisk,2258,0 +blockscd,2258,0 +orrecord,2258,0 +ordisk,2258,0 +ordisc,2258,0 +orcd,2258,0 +record3,2258,0 +disk3,2258,0 +disc3,2258,0 +cd3,2258,0 +3record,2258,0 +3disk,2258,0 +3disc,2258,0 +3cd,2258,0 +chirpdisc,2259,0 +redmusicrecord,2259,0 +redmusicdisk,2259,0 +redmusicdisc,2259,0 +redmusiccd,2259,0 +chirpmusicrecord,2259,0 +chirpmusicdisk,2259,0 +chirpmusicdisc,2259,0 +chirpmusiccd,2259,0 +remusicrecord,2259,0 +remusicdisk,2259,0 +remusicdisc,2259,0 +remusiccd,2259,0 +redmrecord,2259,0 +redmdisk,2259,0 +redmdisc,2259,0 +redmcd,2259,0 +chirpmrecord,2259,0 +chirpmdisk,2259,0 +chirpmdisc,2259,0 +chirpmcd,2259,0 +remrecord,2259,0 +remdisk,2259,0 +remdisc,2259,0 +remcd,2259,0 +redrecord,2259,0 +reddisk,2259,0 +reddisc,2259,0 +redcd,2259,0 +chirprecord,2259,0 +chirpdisk,2259,0 +chirpcd,2259,0 +rerecord,2259,0 +redisk,2259,0 +redisc,2259,0 +recd,2259,0 +record4,2259,0 +disk4,2259,0 +disc4,2259,0 +cd4,2259,0 +4record,2259,0 +4disk,2259,0 +4disc,2259,0 +4cd,2259,0 +fardisc,2260,0 +lightgreenmusicrecord,2260,0 +lightgreenmusicdisk,2260,0 +lightgreenmusicdisc,2260,0 +lightgreenmusiccd,2260,0 +lgreenmusicrecord,2260,0 +lgreenmusicdisk,2260,0 +lgreenmusicdisc,2260,0 +lgreenmusiccd,2260,0 +lightgrmusicrecord,2260,0 +lightgrmusicdisk,2260,0 +lightgrmusicdisc,2260,0 +lightgrmusiccd,2260,0 +farmusicrecord,2260,0 +farmusicdisk,2260,0 +farmusicdisc,2260,0 +farmusiccd,2260,0 +lgrmusicrecord,2260,0 +lgrmusicdisk,2260,0 +lgrmusicdisc,2260,0 +lgrmusiccd,2260,0 +lightgreenmrecord,2260,0 +lightgreenmdisk,2260,0 +lightgreenmdisc,2260,0 +lightgreenmcd,2260,0 +lgreenmrecord,2260,0 +lgreenmdisk,2260,0 +lgreenmdisc,2260,0 +lgreenmcd,2260,0 +lightgrmrecord,2260,0 +lightgrmdisk,2260,0 +lightgrmdisc,2260,0 +lightgrmcd,2260,0 +farmrecord,2260,0 +farmdisk,2260,0 +farmdisc,2260,0 +farmcd,2260,0 +lgrmrecord,2260,0 +lgrmdisk,2260,0 +lgrmdisc,2260,0 +lgrmcd,2260,0 +lightgreenrecord,2260,0 +lightgreendisk,2260,0 +lightgreendisc,2260,0 +lightgreencd,2260,0 +lgreenrecord,2260,0 +lgreendisk,2260,0 +lgreendisc,2260,0 +lgreencd,2260,0 +lightgrrecord,2260,0 +lightgrdisk,2260,0 +lightgrdisc,2260,0 +lightgrcd,2260,0 +farrecord,2260,0 +fardisk,2260,0 +farcd,2260,0 +lgrrecord,2260,0 +lgrdisk,2260,0 +lgrdisc,2260,0 +lgrcd,2260,0 +record5,2260,0 +disk5,2260,0 +disc5,2260,0 +cd5,2260,0 +5record,2260,0 +5disk,2260,0 +5disc,2260,0 +5cd,2260,0 +malldisc,2261,0 +purplemusicrecord,2261,0 +purplemusicdisk,2261,0 +purplemusicdisc,2261,0 +purplemusiccd,2261,0 +mallmusicrecord,2261,0 +mallmusicdisk,2261,0 +mallmusicdisc,2261,0 +mallmusiccd,2261,0 +pumusicrecord,2261,0 +pumusicdisk,2261,0 +pumusicdisc,2261,0 +pumusiccd,2261,0 +purplemrecord,2261,0 +purplemdisk,2261,0 +purplemdisc,2261,0 +purplemcd,2261,0 +mallmrecord,2261,0 +mallmdisk,2261,0 +mallmdisc,2261,0 +mallmcd,2261,0 +pumrecord,2261,0 +pumdisk,2261,0 +pumdisc,2261,0 +pumcd,2261,0 +purplerecord,2261,0 +purpledisk,2261,0 +purpledisc,2261,0 +purplecd,2261,0 +mallrecord,2261,0 +malldisk,2261,0 +mallcd,2261,0 +purecord,2261,0 +pudisk,2261,0 +pudisc,2261,0 +pucd,2261,0 +record6,2261,0 +disk6,2261,0 +disc6,2261,0 +cd6,2261,0 +6record,2261,0 +6disk,2261,0 +6disc,2261,0 +6cd,2261,0 +mellohidisc,2262,0 +pinkmusicrecord,2262,0 +pinkmusicdisk,2262,0 +pinkmusicdisc,2262,0 +pinkmusiccd,2262,0 +mellohimusicrecord,2262,0 +mellohimusicdisk,2262,0 +mellohimusicdisc,2262,0 +mellohimusiccd,2262,0 +pimusicrecord,2262,0 +pimusicdisk,2262,0 +pimusicdisc,2262,0 +pimusiccd,2262,0 +pinkmrecord,2262,0 +pinkmdisk,2262,0 +pinkmdisc,2262,0 +pinkmcd,2262,0 +mellohimrecord,2262,0 +mellohimdisk,2262,0 +mellohimdisc,2262,0 +mellohimcd,2262,0 +pimrecord,2262,0 +pimdisk,2262,0 +pimdisc,2262,0 +pimcd,2262,0 +pinkrecord,2262,0 +pinkdisk,2262,0 +pinkdisc,2262,0 +pinkcd,2262,0 +mellohirecord,2262,0 +mellohidisk,2262,0 +mellohicd,2262,0 +pirecord,2262,0 +pidisk,2262,0 +pidisc,2262,0 +picd,2262,0 +record7,2262,0 +disk7,2262,0 +disc7,2262,0 +cd7,2262,0 +7record,2262,0 +7disk,2262,0 +7disc,2262,0 +7cd,2262,0 +staldisc,2263,0 +blackmusicrecord,2263,0 +blackmusicdisk,2263,0 +blackmusicdisc,2263,0 +blackmusiccd,2263,0 +stalmusicrecord,2263,0 +stalmusicdisk,2263,0 +stalmusicdisc,2263,0 +stalmusiccd,2263,0 +blmusicrecord,2263,0 +blmusicdisk,2263,0 +blmusicdisc,2263,0 +blmusiccd,2263,0 +blackmrecord,2263,0 +blackmdisk,2263,0 +blackmdisc,2263,0 +blackmcd,2263,0 +stalmrecord,2263,0 +stalmdisk,2263,0 +stalmdisc,2263,0 +stalmcd,2263,0 +blmrecord,2263,0 +blmdisk,2263,0 +blmdisc,2263,0 +blmcd,2263,0 +blackrecord,2263,0 +blackdisk,2263,0 +blackdisc,2263,0 +blackcd,2263,0 +stalrecord,2263,0 +staldisk,2263,0 +stalcd,2263,0 +blrecord,2263,0 +bldisk,2263,0 +bldisc,2263,0 +blcd,2263,0 +record8,2263,0 +disk8,2263,0 +disc8,2263,0 +cd8,2263,0 +8record,2263,0 +8disk,2263,0 +8disc,2263,0 +8cd,2263,0 +straddisc,2264,0 +whitemusicrecord,2264,0 +whitemusicdisk,2264,0 +whitemusicdisc,2264,0 +whitemusiccd,2264,0 +stradmusicrecord,2264,0 +stradmusicdisk,2264,0 +stradmusicdisc,2264,0 +stradmusiccd,2264,0 +whmusicrecord,2264,0 +whmusicdisk,2264,0 +whmusicdisc,2264,0 +whmusiccd,2264,0 +whitemrecord,2264,0 +whitemdisk,2264,0 +whitemdisc,2264,0 +whitemcd,2264,0 +stradmrecord,2264,0 +stradmdisk,2264,0 +stradmdisc,2264,0 +stradmcd,2264,0 +whmrecord,2264,0 +whmdisk,2264,0 +whmdisc,2264,0 +whmcd,2264,0 +whiterecord,2264,0 +whitedisk,2264,0 +whitedisc,2264,0 +whitecd,2264,0 +stradrecord,2264,0 +straddisk,2264,0 +stradcd,2264,0 +whrecord,2264,0 +whdisk,2264,0 +whdisc,2264,0 +whcd,2264,0 +record9,2264,0 +disk9,2264,0 +disc9,2264,0 +cd9,2264,0 +9record,2264,0 +9disk,2264,0 +9disc,2264,0 +9cd,2264,0 +warddisc,2265,0 +darkgreenmusicrecord,2265,0 +darkgreenmusicdisk,2265,0 +darkgreenmusicdisc,2265,0 +darkgreenmusiccd,2265,0 +dgreenmusicrecord,2265,0 +dgreenmusicdisk,2265,0 +dgreenmusicdisc,2265,0 +dgreenmusiccd,2265,0 +darkgrmusicrecord,2265,0 +darkgrmusicdisk,2265,0 +darkgrmusicdisc,2265,0 +darkgrmusiccd,2265,0 +wardmusicrecord,2265,0 +wardmusicdisk,2265,0 +wardmusicdisc,2265,0 +wardmusiccd,2265,0 +dgrmusicrecord,2265,0 +dgrmusicdisk,2265,0 +dgrmusicdisc,2265,0 +dgrmusiccd,2265,0 +darkgreenmrecord,2265,0 +darkgreenmdisk,2265,0 +darkgreenmdisc,2265,0 +darkgreenmcd,2265,0 +dgreenmrecord,2265,0 +dgreenmdisk,2265,0 +dgreenmdisc,2265,0 +dgreenmcd,2265,0 +darkgrmrecord,2265,0 +darkgrmdisk,2265,0 +darkgrmdisc,2265,0 +darkgrmcd,2265,0 +wardmrecord,2265,0 +wardmdisk,2265,0 +wardmdisc,2265,0 +wardmcd,2265,0 +dgrmrecord,2265,0 +dgrmdisk,2265,0 +dgrmdisc,2265,0 +dgrmcd,2265,0 +darkgreenrecord,2265,0 +darkgreendisk,2265,0 +darkgreendisc,2265,0 +darkgreencd,2265,0 +dgreenrecord,2265,0 +dgreendisk,2265,0 +dgreendisc,2265,0 +dgreencd,2265,0 +darkgrrecord,2265,0 +darkgrdisk,2265,0 +darkgrdisc,2265,0 +darkgrcd,2265,0 +wardrecord,2265,0 +warddisk,2265,0 +wardcd,2265,0 +dgrrecord,2265,0 +dgrdisk,2265,0 +dgrdisc,2265,0 +dgrcd,2265,0 +record10,2265,0 +disk10,2265,0 +disc10,2265,0 +cd10,2265,0 +10record,2265,0 +10disk,2265,0 +10disc,2265,0 +10cd,2265,0 +11disc,2266,0 +crackedmusicrecord,2266,0 +crackedmusicdisk,2266,0 +crackedmusicdisc,2266,0 +crackedmusiccd,2266,0 +crackmusicrecord,2266,0 +crackmusicdisk,2266,0 +crackmusicdisc,2266,0 +crackmusiccd,2266,0 +11musicrecord,2266,0 +11musicdisk,2266,0 +11musicdisc,2266,0 +11musiccd,2266,0 +cmusicrecord,2266,0 +cmusicdisk,2266,0 +cmusicdisc,2266,0 +cmusiccd,2266,0 +crackedmrecord,2266,0 +crackedmdisk,2266,0 +crackedmdisc,2266,0 +crackedmcd,2266,0 +crackmrecord,2266,0 +crackmdisk,2266,0 +crackmdisc,2266,0 +crackmcd,2266,0 +11mrecord,2266,0 +11mdisk,2266,0 +11mdisc,2266,0 +11mcd,2266,0 +cmrecord,2266,0 +cmdisk,2266,0 +cmdisc,2266,0 +cmcd,2266,0 +crackedrecord,2266,0 +crackeddisk,2266,0 +crackeddisc,2266,0 +crackedcd,2266,0 +crackrecord,2266,0 +crackdisk,2266,0 +crackdisc,2266,0 +crackcd,2266,0 +crecord,2266,0 +cdisk,2266,0 +cdisc,2266,0 +ccd,2266,0 +record11,2266,0 +disk11,2266,0 +disc11,2266,0 +cd11,2266,0 +11record,2266,0 +11disk,2266,0 +11cd,2266,0 +waitdisc,2267,0 +waitmusicrecord,2267,0 +waitmusicdisk,2267,0 +waitmusicdisc,2267,0 +waitmusiccd,2267,0 +bluemusicrecord,2267,0 +bluemusicdisk,2267,0 +bluemusicdisc,2267,0 +bluemusiccd,2267,0 +12musicrecord,2267,0 +12musicdisk,2267,0 +12musicdisc,2267,0 +12musiccd,2267,0 +cyanmusicrecord,2267,0 +cyanmusicdisk,2267,0 +cyanmusicdisc,2267,0 +cyanmusiccd,2267,0 +waitmrecord,2267,0 +waitmdisk,2267,0 +waitmdisc,2267,0 +waitmcd,2267,0 +bluemrecord,2267,0 +bluemdisk,2267,0 +bluemdisc,2267,0 +bluemcd,2267,0 +12mrecord,2267,0 +12mdisk,2267,0 +12mdisc,2267,0 +12mcd,2267,0 +cyanmrecord,2267,0 +cyanmdisk,2267,0 +cyanmdisc,2267,0 +cyanmcd,2267,0 +waitrecord,2267,0 +waitdisk,2267,0 +waitcd,2267,0 +bluerecord,2267,0 +bluedisk,2267,0 +bluedisc,2267,0 +bluecd,2267,0 +cyanrecord,2267,0 +cyandisk,2267,0 +cyandisc,2267,0 +cyancd,2267,0 +record12,2267,0 +disk12,2267,0 +disc12,2267,0 +cd12,2267,0 +12record,2267,0 +12disk,2267,0 +12disc,2267,0 +12cd,2267,0 +#9024e88d64262f1c5ea92df8399fa658 \ No newline at end of file diff --git a/lives.yml b/lives.yml new file mode 100644 index 0000000..04ec367 --- /dev/null +++ b/lives.yml @@ -0,0 +1 @@ +lives: {} diff --git a/locale.yml b/locale.yml new file mode 100644 index 0000000..619f9fe --- /dev/null +++ b/locale.yml @@ -0,0 +1,107 @@ +player_only: "&cOnly players may use that!" +no_permission: "&cNo permission." +player_unfound: "&e{0}&4 could not be found" +enabled: "&aEnabled" +disabled: "&cDisabled" +able: "&aAble" +unable: "&cUnable" +inventoryFull: "&cYou must clear your inventory first!" +notNumber: "&e{0} is not a number!" +angle_message: "&e{0} yaw&f, &e{1} pitch" +revive_cooldown: "&4You may not revive a player for another &e{0}4." +not_dead: "&e{0} &eis not deathbanned" +revived: "&aYou have revived &e{0}&a!" +revive_player: "&cYou revived {0}!" +revive_broadcast: "&c{0} revived {1}!" +selectEndPortal: "&cYou must select an end portal frame!" +locationSuccess: "&aSet location {0}" +firstLocationUnset: "&cYou must set the first location!" +portalTooBig: "&cYou cannot create a portal that big!" +portalElevation: "&cMake sure the portal is on the same elevation!" +portalSuccess: "&aCreated portal." +portalWandGive: "&aSelect 2 points to make an end portal" +noCooldown: "&4You do not have a Gopple cooldown active." +activeCooldown: "&eYour Gopple cooldown expires in {0}" +helpMenu: + - "&aThis is" + - "&aThe help menu" +userLocation: "&e{0}&a is in the area of {1} at coordinates: {2},{3},{4}" +logoutActive: "&aYour logout timer is already active!" +logoutStart: "&aYour logout timer is now active!" +pvpTimerNotActive: "&cYour {0} timer is currently not active." +pvpTimerDeactivate: "&cYour {0} timer has now been deactivated!" +pvpTimerActive: "&aYour {0} timer is still active for another {1}" +notInFaction: "&cYou are not in a faction!" +fullDTR: "&aYour faction has full DTR." +frozenDTR: "&aYour faction DTR is frozen for another {0}" +regeneratingDTR: "&aYour faction currently has {0} DTR and is regenerating at a rate of {1} every {2}. Estimated time until full DTR is {3}." +serverTime: "&aThe server time is {0}" +cannonOnlyOverworld: "&aYou can only " +toggleCapZoneMessages: "&eYou are now {0} to see cap zone entry messages" +toggleFDMessages: "&e{0} &ahas toggled &bFound Diamond Alerts" +toggleLSMessages: "&eYou will now be {0} to see Lightning Strikes on player deaths" + +# Scoreboard toggle +toggleScoreboard: "&eYou have now {0} your scoreboard" + +# Lives and deathban messages +noLivesInDB: "&eThere are no lives in the database!" +eotwDeathBanJoin: "&cYou are deathbanned for the rest of the map due to EOTW." +deathbanTimer: "&cYou are still deathbanned for {0}" +lifeUsed: "&aYou have used a life! You now have {0} lives." +noLives: "&cYou have no lives!" +deathbanWithLives: "&cYou are still deathbanned with {0} remaining! You can use a life by joining within {1}" +deathbanBypass: "&aYou would be deathbanned, but you have permission to bypass." +playerLifeCheck: "&e{0} currently has {1} lives" +notDeathbanned: "&e{0} is not deathbanned!" +deathbanReason: + - "&eDeathban caused by {0}" + - "&eTime: {1}" + - "&eDuration: {2}" +deathbanLocation: "&eLocation: ({0},{1},{2})" +deathbanReason: "&eReason: [{0}]" +clearDeathbanMessaage: "&eAll deathbans have been cleared" +livesMustBePositive: "&cThe amount of lives must be positive" +livesGiftFailure: "&cYou could not give {0} {1} live(s) because you only have {2}." +livesGiftSuccess: "&aYou gifted {0} with {1} live(s)" +livesGiftSuccessPlayer: "&e{0} gifted you with {1} live(s)" +livesReviveKitmap: "&eYou cannot revive players during kitmap!" +livesReviveEOTW: "&eYou cannot revive players during EOTW!" +lifeUsedOnOther: "&eYou have used a life to revive {0}" +livesConsoleRevive: "&eYou have revived {0}" +livesSet: "&e{0} now has {1} lives." +deathbanDurationError: "&cInvalid duration! Use format &o1h 2m" +deathbanDurationSet: "&eDeathban time has now been set to {0}!" +topLivesTitle: "&eTop {0} lives:" +topLivesFormat: "&e{0} {1}: {2}" +ecoGiveAll: "&e{0} gave all players ${1}" +ecoBalance: "&eYour balance: {0}" +ecoBalanceOther: "&e{0}'s balance: {1}" +ecoAdded: "&eAdded {0} to {1}'s balance. Their new balance is {2}" +ecoTaken: "&eTaken {0} from {1}'s balance. Their new balance is {2}" +ecoSet: "&eSet balance of {0} to {1}" +ecoNotPositive: "&cYou must send money in positive amounts." +ecoSendFailure: "&cYou tried to pay {0}, but you only have {1} in your account." +ecoSendSuccess: "&aYou have sent {0} to {1}" +ecoSendSuccessPlayer: "&a{0} sent you {1}" +notPlayerFaction: "&cThat faction could not be found or is not a player faction." +noEvents: "&cThere are no running events!" +eventCancelled: "&c{0} has cancelled the event {1}" +eventCreateNameUsed: "&cThere is already an event faction named {0}" +eventCreateSuccess: "&aCreated event faction {0} with event type {1}!" +eventDeleteNameUnused: "&cThere is no such event faction called {0}" +eventDeleteSuccess: "&aDeleted event faction {0}!" +eventRenameSuccess: "&aRenamed event {0} to {1}" +noWorldEdit: "&cYou need WorldEdit installed to use this feature!" +requireWorldEditSelection: "&cPlease make a WorldEdit selection!" +areaTooSmall: "&cRegion selection must be {0} x {0}" +eventAreaSuccess: "&aUpdated the claim area for event {0}" +eventStarted: "&aEvent has been started!" +eventUptime: "&aEvent &e({0})&a has been live for &e{1}&a and started at &e{2}" +conquestSetPointsError: "&cMaximum points for Conquest is {0}" +conquestSetPoints: "&aSet points for {0} to {1}" +noKeyFound: "&cNo key type named {0}" +keyOnlyPositive: "&cYou can only give keys in positive quantities" +keyMaximumAllowed: "&cYou cannot give keys in more than {0}'s" +keyGiven: "&cGiven {0}x {1} key to {2}" +crateClosedDuring: "&aYou closed your crate reward inventory, dropping your items on the ground!" \ No newline at end of file diff --git a/plugin.yml b/plugin.yml new file mode 100644 index 0000000..67eb09f --- /dev/null +++ b/plugin.yml @@ -0,0 +1,130 @@ +name: Zorex +version: 1.0 +description: HCF CORE +author: bruceboy +main: me.bruce.factions.LorexHCF +softdepend: [ProtocolLib] +commands: + hcf: + rawcast: + wb: + nv: + stats: + setnpc: + staffguide: + tablistgui: + aliases: [tabgui] + coords: + pots: + vanish: + aliases: [v] + staffgui: + author: + aliases: [dev,developer,best,bestdev] + gamemode: + aliases: [gm] + setprefix: + slowchat: + disablechat: + tp: + here: + fly: + fix: + invsee: + randomtp: + panic: + tl: + baller: + rules: + vip: + zorex: + spawn: + lff: + pro: + prefix: + keysale: + sp: + fr: + reboot: + rank: + broadcast: + aliases: [bc] + buy: + tablist: + aliases: [pot] + settings: + refund: + aliases: [inv, restore, invrestore] + ping: + freeze: + aliases: [ss] + enderdragon: + hub: + this: + playtime: + aliases: [pt] + cobble: + crowgive: + aliases: [crowbar, crowbargive] + Amethyst: + hcfhelp: + aliases: [help, ehelp, pl, ?] + conquest: + description: Command used to handle Conquest events. + economy: + aliases: [$, bal, money, eco, econ] + description: Command used to modify the economy. + eotw: + aliases: [endoftheworld] + description: Sets if the server is in End of the World mode. + event: + description: Command used to manage minigame events. + faction: + aliases: [f, fac] + description: Faction related commands. + gopple: + description: Command to check remaining OP apple cooldown time. + aliases: [opple, goppletimer, goppletime, oppletimer, oppletime] + hcf: + aliases: [hardcorefactions, hcfactions] + koth: + description: Make or delete KotH arenas. + lives: + description: Management of lives or deathbans. + location: + aliases: [loc] + description: Check the faction location of a player. + logout: + aliases: [disconnect] + description: Command to safely logout without an NPC spawning. + mapkit: + aliases: [viewkit] + description: Used to check the current map restrictions. + pay: + aliases: [p2p] + description: Allow players to pay money. + pvptimer: + aliases: [pvp] + description: Command to enable or disable pvp timer protection. + regen: + description: Check ETA until a faction is able to regenerate DTR. + sotw: + aliases: [startoftheworld] + description: Command used to manage start of the world. + staffrevive: + aliases: [revive] + description: Command used by staff to revive players. + timer: + description: Command to manage timers. + togglecapzoneentry: + aliases: [togglecapentry] + description: Command used to hide or show capture zone entry messages. + togglelightning: + aliases: [lightningtoggle, togglestrikes] + description: Toggles the lightning strikes for when a player dies. + rename: + ores: + description: See ores mined. + aliases: [stats, mined] + glowstonemountain: + aliases: [reset] \ No newline at end of file diff --git a/settings.yml b/settings.yml new file mode 100644 index 0000000..4bb0deb --- /dev/null +++ b/settings.yml @@ -0,0 +1,75 @@ +disable_obsidian_generators: true +server_time_zone: EST +warzone_radius: 650 +donate_url: store.Vengeful.us +spawn_buffer: 128 +map_number: 1 +disallowed_faction_names: +- Venge +- Vengeful +enchantment_limits: + PROTECTION_ENVIRONMENTAL: 2 + DAMAGE_ALL: 1 + ARROW_KNOCKBACK: 0 + KNOCKBACK: 0 + FIRE_ASPECT: 0 + THORNS: 0 + ARROW_FIRE: 1 + ARROW_DAMAGE: 3 +potion_limits: + STRENGTH: 1 + WEAKNESS: 0 + SLOWNESS: 0 + INVISIBILITY: 0 + POISON: 0 +road_lengths: + NORMAL: 4000 + NETHER: 4000 +border_sizes: + NORMAL: 2000 + NETHER: 2000 + THE_END: 1500 +spawn_radius_map: + NORMAL: 50 + NETHER: 25 + THE_END: 15 +diamond_ore_alerts: false +subclaim_name_characters_min: 3 +subclaim_name_characters_max: 16 +faction_name_characters_min: 3 +faction_name_characters_max: 16 +max_members_per_faction: 8 +road_distance: 2500 +road_min_height: 0 +road_max_height: 256 +end_portal_radius: 20 +end_portal_center: 750 +default_deathban_duration: 3600000 +kit_map: true +#Tablist is currently weird for 1.8 users use if you want +tablist: false +teammate_colour: DARK_GREEN +ally_colour: LIGHT_PURPLE +enemy_colour: RED +safezone_colour: AQUA +road_colour: GOLD +warzone_colour: RED +wilderness_colour: GREEN +scoreboard_title: '(Speed)' +max_allies_per_faction: 0 +max_claims_per_faction: 8 +allow_claiming_besides_roads: false +dtr_millis_between_updates: 45000 +dtr_increment_between_updates: 0.1 +maximum_dtr: 6.0 +exp_multiplier_general: 2.0 +exp_multiplier_fishing: 2.0 +exp_multiplier_smelting: 2.0 +exp_multiplier_looting_per_level: 6.0 +exp_multiplier_luck_per_level: 1.5 +exp_multiplier_fortune_per_level: 1.5 +conquest_point_loss_per_death: 30 +conquest_required_win_points: 300 +found_diamonds_alerts: true +combat_log_despawn_ticks: 600 +combat_log_prevention_enabled: true diff --git a/src/LorexMC/us/utils/BukkitUtils.java b/src/LorexMC/us/utils/BukkitUtils.java new file mode 100644 index 0000000..5d7f493 --- /dev/null +++ b/src/LorexMC/us/utils/BukkitUtils.java @@ -0,0 +1,181 @@ +package LorexMC.us.utils; + +import com.google.common.collect.*; + +import gnu.trove.list.*; + +import java.util.stream.*; + +import org.bukkit.command.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import net.minecraft.server.v1_7_R4.*; + +import org.bukkit.event.entity.*; +import org.bukkit.projectiles.*; +import org.bukkit.*; +import org.bukkit.World; +import org.bukkit.block.Block; +import org.bukkit.potion.*; +import org.bukkit.entity.*; +import org.bukkit.entity.Entity; + +import java.util.*; + +import com.google.common.base.*; + +import gnu.trove.list.array.*; + +public final class BukkitUtils { + private static final ImmutableMap CHAT_DYE_COLOUR_MAP; + private static final ImmutableSet DEBUFF_TYPES; + private static final int DEFAULT_COMPLETION_LIMIT = 80; + private static final String STRAIGHT_LINE_TEMPLATE; + public static final String STRAIGHT_LINE_DEFAULT; + private static final TCharList COLOUR_CHARACTER_LIST; + + public static int countColoursUsed(final String id, final boolean ignoreDuplicates) { + int count = 0; + final Set found = new HashSet(); + for (int i = 1; i < id.length(); ++i) { + final char current = id.charAt(i); + if (BukkitUtils.COLOUR_CHARACTER_LIST.contains(current) && id.charAt(i - 1) == '&' + && (ignoreDuplicates || found.add(ChatColor.getByChar(current)))) { + ++count; + } + } + return count; + } + + public static List getCompletions(final String[] args, final List input) { + return getCompletions(args, input, 80); + } + + public static List getCompletions(final String[] args, final List input, final int limit) { + Preconditions.checkNotNull((Object) args); + Preconditions.checkArgument(args.length != 0); + final String argument = args[args.length - 1]; + return input.stream().filter(string -> string.regionMatches(true, 0, argument, 0, argument.length())) + .limit(limit).collect(Collectors.toList()); + } + + public static String getDisplayName(final CommandSender sender) { + Preconditions.checkNotNull((Object) sender); + return (sender instanceof Player) ? ((Player) sender).getDisplayName() : sender.getName(); + } + + public static long getIdleTime(final Player player) { + Preconditions.checkNotNull((Object) player); + final long idleTime = ((CraftPlayer) player).getHandle().x(); + return (idleTime > 0L) ? (MinecraftServer.ar() - idleTime) : 0L; + } + + public static DyeColor toDyeColor(final ChatColor colour) { + return BukkitUtils.CHAT_DYE_COLOUR_MAP.get(colour); + } + + public static Player getFinalAttacker(final EntityDamageEvent ede, final boolean ignoreSelf) { + Player attacker = null; + if (ede instanceof EntityDamageByEntityEvent) { + final EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) ede; + final Entity damager = event.getDamager(); + if (event.getDamager() instanceof Player) { + attacker = (Player) damager; + } else if (event.getDamager() instanceof Projectile) { + final Projectile projectile = (Projectile) damager; + final ProjectileSource shooter = projectile.getShooter(); + if (shooter instanceof Player) { + attacker = (Player) shooter; + } + } + if (attacker != null && ignoreSelf && event.getEntity().equals(attacker)) { + attacker = null; + } + } + return attacker; + } + + public static Player playerWithNameOrUUID(final String string) { + if (string == null) { + return null; + } + return JavaUtils.isUUID(string) ? Bukkit.getPlayer(UUID.fromString(string)) : Bukkit.getPlayer(string); + } + + @Deprecated + public static OfflinePlayer offlinePlayerWithNameOrUUID(final String string) { + if (string == null) { + return null; + } + return JavaUtils.isUUID(string) ? Bukkit.getOfflinePlayer(UUID.fromString(string)) + : Bukkit.getOfflinePlayer(string); + } + + public static boolean isWithinX(final Location location, final Location other, final double distance) { + return location.getWorld().equals(other.getWorld()) && Math.abs(other.getX() - location.getX()) <= distance + && Math.abs(other.getZ() - location.getZ()) <= distance; + } + + public static Location getHighestLocation(final Location origin) { + return getHighestLocation(origin, null); + } + + public static Location getHighestLocation(final Location origin, final Location def) { + Preconditions.checkNotNull((Object) origin, (Object) "The location cannot be null"); + final Location cloned = origin.clone(); + final World world = cloned.getWorld(); + final int x = cloned.getBlockX(); + int y = world.getMaxHeight(); + final int z = cloned.getBlockZ(); + while (y > origin.getBlockY()) { + final Block block = world.getBlockAt(x, --y, z); + if (!block.isEmpty()) { + final Location next = block.getLocation(); + next.setPitch(origin.getPitch()); + next.setYaw(origin.getYaw()); + return next; + } + } + return def; + } + + public static boolean isDebuff(final PotionEffectType type) { + return BukkitUtils.DEBUFF_TYPES.contains(type); + } + + public static boolean isDebuff(final PotionEffect potionEffect) { + return isDebuff(potionEffect.getType()); + } + + public static boolean isDebuff(final ThrownPotion thrownPotion) { + for (final PotionEffect effect : thrownPotion.getEffects()) { + if (isDebuff(effect)) { + return true; + } + } + return false; + } + + static { + STRAIGHT_LINE_TEMPLATE = ChatColor.STRIKETHROUGH.toString() + Strings.repeat("-", 256); + STRAIGHT_LINE_DEFAULT = BukkitUtils.STRAIGHT_LINE_TEMPLATE.substring(0, 55); + CHAT_DYE_COLOUR_MAP = ImmutableMap.builder().put(ChatColor.AQUA, DyeColor.LIGHT_BLUE) + .put(ChatColor.BLACK, DyeColor.BLACK).put(ChatColor.BLUE, DyeColor.LIGHT_BLUE) + .put(ChatColor.DARK_AQUA, DyeColor.CYAN).put(ChatColor.DARK_BLUE, DyeColor.BLUE) + .put(ChatColor.DARK_GRAY, DyeColor.GRAY).put(ChatColor.DARK_GREEN, DyeColor.GREEN) + .put(ChatColor.DARK_PURPLE, DyeColor.PURPLE).put(ChatColor.DARK_RED, DyeColor.RED) + .put(ChatColor.GOLD, DyeColor.ORANGE).put(ChatColor.GRAY, DyeColor.SILVER) + .put(ChatColor.GREEN, DyeColor.LIME).put(ChatColor.LIGHT_PURPLE, DyeColor.MAGENTA) + .put(ChatColor.RED, DyeColor.RED).put(ChatColor.WHITE, DyeColor.WHITE) + .put(ChatColor.YELLOW, DyeColor.YELLOW).build(); + DEBUFF_TYPES = ImmutableSet.builder().add(PotionEffectType.BLINDNESS) + .add(PotionEffectType.CONFUSION).add(PotionEffectType.HARM).add(PotionEffectType.HUNGER) + .add(PotionEffectType.POISON).add(PotionEffectType.SATURATION).add(PotionEffectType.SLOW) + .add(PotionEffectType.SLOW_DIGGING).add(PotionEffectType.WEAKNESS).add(PotionEffectType.WITHER).build(); + final ChatColor[] values = ChatColor.values(); + COLOUR_CHARACTER_LIST = new TCharArrayList(values.length); + for (final ChatColor colour : values) { + BukkitUtils.COLOUR_CHARACTER_LIST.add(colour.getChar()); + } + } +} diff --git a/src/LorexMC/us/utils/Color.java b/src/LorexMC/us/utils/Color.java new file mode 100644 index 0000000..68c2861 --- /dev/null +++ b/src/LorexMC/us/utils/Color.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils; + +import org.bukkit.*; +import java.util.*; + +public class Color { + public static String translate(final String input) { + return ChatColor.translateAlternateColorCodes('&', input); + } + + public static List translateFromArray(final List text) { + final List messages = new ArrayList(); + for (final String string : text) { + messages.add(translate(string)); + } + return messages; + } +} diff --git a/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java b/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java new file mode 100644 index 0000000..a793a7c --- /dev/null +++ b/src/LorexMC/us/utils/ConcurrentValueOrderedMap.java @@ -0,0 +1,89 @@ +package LorexMC.us.utils; + +import java.io.*; +import java.util.concurrent.*; +import java.util.*; +import javax.annotation.*; + +public class ConcurrentValueOrderedMap> extends AbstractMap + implements Map, Cloneable, Serializable { + private final Set> ordering; + private final ConcurrentMap> lookup; + + public ConcurrentValueOrderedMap() { + this.ordering = new ConcurrentSkipListSet>(); + this.lookup = new ConcurrentHashMap>(); + } + + @Override + public V get(final Object key) { + final InternalEntry old = this.lookup.get(key); + return (old != null) ? old.getValue() : null; + } + + @Override + public V put(final K key, final V val) { + final InternalEntry entry = new InternalEntry(key, val); + final InternalEntry old = this.lookup.put(key, entry); + if (old == null) { + this.ordering.add(entry); + return null; + } + this.ordering.remove(old); + this.ordering.add(entry); + return old.getValue(); + } + + @Override + public V remove(final Object key) { + final InternalEntry old = this.lookup.remove(key); + if (old != null) { + this.ordering.remove(old); + return old.getValue(); + } + return null; + } + + @Override + public void clear() { + this.ordering.clear(); + this.lookup.clear(); + } + + @Nonnull + @Override + public Set> entrySet() { + return Collections.unmodifiableSet((Set>) this.ordering); + } + + private static class InternalEntry> + implements Comparable>, Entry { + private final K key; + private final V value; + + InternalEntry(final K key, final V value) { + this.key = key; + this.value = value; + } + + @Override + public K getKey() { + return this.key; + } + + @Override + public V getValue() { + return this.value; + } + + @Override + public V setValue(final V value) throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + + @Override + public int compareTo(@Nonnull final InternalEntry o) { + return o.value.compareTo(this.value); + } + } +} diff --git a/src/LorexMC/us/utils/Config.java b/src/LorexMC/us/utils/Config.java new file mode 100644 index 0000000..692b447 --- /dev/null +++ b/src/LorexMC/us/utils/Config.java @@ -0,0 +1,93 @@ +package LorexMC.us.utils; + +import org.bukkit.configuration.file.*; +import org.bukkit.plugin.java.*; +import java.io.*; + +public class Config extends YamlConfiguration { + private final String fileName; + private final JavaPlugin plugin; + + public Config(final JavaPlugin plugin, final String fileName) { + this(plugin, fileName, ".yml"); + } + + public Config(final JavaPlugin plugin, final String fileName, final String fileExtension) { + this.plugin = plugin; + this.fileName = fileName + (fileName.endsWith(fileExtension) ? "" : fileExtension); + this.createFile(); + } + + public String getFileName() { + return this.fileName; + } + + public JavaPlugin getPlugin() { + return this.plugin; + } + + private void createFile() { + final File folder = this.plugin.getDataFolder(); + try { + final File file = new File(folder, this.fileName); + if (!file.exists()) { + if (this.plugin.getResource(this.fileName) != null) { + this.plugin.saveResource(this.fileName, false); + } else { + this.save(file); + } + this.load(file); + } else { + this.load(file); + this.save(file); + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + public void save() { + final File folder = this.plugin.getDataFolder(); + try { + this.save(new File(folder, this.fileName)); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Config)) { + return false; + } + final Config config = (Config) o; + Label_0054: { + if (this.fileName != null) { + if (this.fileName.equals(config.fileName)) { + break Label_0054; + } + } else if (config.fileName == null) { + break Label_0054; + } + return false; + } + if (this.plugin != null) { + if (!this.plugin.equals(config.plugin)) { + return false; + } + } else if (config.plugin != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.fileName != null) ? this.fileName.hashCode() : 0; + result = 31 * result + ((this.plugin != null) ? this.plugin.hashCode() : 0); + return result; + } +} diff --git a/src/LorexMC/us/utils/DelayedMessageRunnable.java b/src/LorexMC/us/utils/DelayedMessageRunnable.java new file mode 100644 index 0000000..8afd21c --- /dev/null +++ b/src/LorexMC/us/utils/DelayedMessageRunnable.java @@ -0,0 +1,22 @@ +package LorexMC.us.utils; + +import org.bukkit.scheduler.*; +import org.bukkit.entity.*; +import org.bukkit.plugin.java.*; +import org.bukkit.plugin.*; + +public class DelayedMessageRunnable extends BukkitRunnable { + private final Player player; + private final String message; + + public DelayedMessageRunnable(final JavaPlugin plugin, final Player player, final String message) { + this.player = player; + this.message = message; + this.runTask(plugin); + } + + @Override + public void run() { + this.player.sendMessage(this.message); + } +} diff --git a/src/LorexMC/us/utils/DurationFormatter.java b/src/LorexMC/us/utils/DurationFormatter.java new file mode 100644 index 0000000..5c0b1a7 --- /dev/null +++ b/src/LorexMC/us/utils/DurationFormatter.java @@ -0,0 +1,30 @@ +package LorexMC.us.utils; + +import org.apache.commons.lang3.time.*; + +import me.bruce.factions.listener.DateTimeFormats; + +import java.util.concurrent.*; + +public class DurationFormatter { + private static final long MINUTE; + private static final long HOUR; + + public static String getRemaining(final long millis, final boolean milliseconds) { + return getRemaining(millis, milliseconds, true); + } + + public static String getRemaining(final long duration, final boolean milliseconds, final boolean trail) { + if (milliseconds && duration < DurationFormatter.MINUTE) { + return (trail ? DateTimeFormats.REMAINING_SECONDS_TRAILING : DateTimeFormats.REMAINING_SECONDS).get() + .format(duration * 0.001); + } + return DurationFormatUtils.formatDuration(duration, + ((duration >= DurationFormatter.HOUR) ? "HH:" : "") + "mm:ss"); + } + + static { + MINUTE = TimeUnit.MINUTES.toMillis(1L); + HOUR = TimeUnit.HOURS.toMillis(1L); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/ExperienceManager.java b/src/LorexMC/us/utils/ExperienceManager.java new file mode 100644 index 0000000..402a638 --- /dev/null +++ b/src/LorexMC/us/utils/ExperienceManager.java @@ -0,0 +1,134 @@ +package LorexMC.us.utils; + +import java.lang.ref.*; +import org.bukkit.entity.*; +import com.google.common.base.*; +import java.util.*; + +public class ExperienceManager { + private static int hardMaxLevel; + private static int[] xpTotalToReachLevel; + private final WeakReference player; + private final String playerName; + + public ExperienceManager(final Player player) { + Preconditions.checkNotNull((Object) player, (Object) "Player cannot be null"); + this.player = new WeakReference(player); + this.playerName = player.getName(); + } + + public static int getHardMaxLevel() { + return ExperienceManager.hardMaxLevel; + } + + public static void setHardMaxLevel(final int hardMaxLevel) { + ExperienceManager.hardMaxLevel = hardMaxLevel; + } + + private static void initLookupTables(final int maxLevel) { + ExperienceManager.xpTotalToReachLevel = new int[maxLevel]; + for (int i = 0; i < ExperienceManager.xpTotalToReachLevel.length; ++i) { + ExperienceManager.xpTotalToReachLevel[i] = ((i >= 30) ? ((int) (3.5 * i * i - 151.5 * i + 2220.0)) + : ((i >= 16) ? ((int) (1.5 * i * i - 29.5 * i + 360.0)) : (17 * i))); + } + } + + private static int calculateLevelForExp(final int exp) { + int level = 0; + for (int curExp = 7, incr = 10; curExp <= exp; curExp += incr, ++level, incr += ((level % 2 == 0) ? 3 : 4)) { + } + return level; + } + + public Player getPlayer() { + final Player p = this.player.get(); + if (p == null) { + throw new IllegalStateException("Player " + this.playerName + " is not online"); + } + return p; + } + + public void changeExp(final int amt) { + this.changeExp((double) amt); + } + + public void changeExp(final double amt) { + this.setExp(this.getCurrentFractionalXP(), amt); + } + + public void setExp(final int amt) { + this.setExp(0.0, amt); + } + + public void setExp(final double amt) { + this.setExp(0.0, amt); + } + + private void setExp(final double base, final double amt) { + final int xp = (int) Math.max(base + amt, 0.0); + final Player player = this.getPlayer(); + final int curLvl = player.getLevel(); + final int newLvl = this.getLevelForExp(xp); + if (curLvl != newLvl) { + player.setLevel(newLvl); + } + if (xp > base) { + player.setTotalExperience(player.getTotalExperience() + xp - (int) base); + } + final double pct = (base - this.getXpForLevel(newLvl) + amt) / this.getXpNeededToLevelUp(newLvl); + player.setExp((float) pct); + } + + public int getCurrentExp() { + final Player player = this.getPlayer(); + final int lvl = player.getLevel(); + return this.getXpForLevel(lvl) + Math.round(this.getXpNeededToLevelUp(lvl) * player.getExp()); + } + + private double getCurrentFractionalXP() { + final Player player = this.getPlayer(); + final int lvl = player.getLevel(); + return this.getXpForLevel(lvl) + this.getXpNeededToLevelUp(lvl) * player.getExp(); + } + + public boolean hasExp(final int amt) { + return this.getCurrentExp() >= amt; + } + + public boolean hasExp(final double amt) { + return this.getCurrentFractionalXP() >= amt; + } + + public int getLevelForExp(final int exp) { + if (exp <= 0) { + return 0; + } + if (exp > ExperienceManager.xpTotalToReachLevel[ExperienceManager.xpTotalToReachLevel.length - 1]) { + final int newMax = calculateLevelForExp(exp) * 2; + Preconditions.checkArgument(newMax <= ExperienceManager.hardMaxLevel, + "Level for exp " + exp + " > hard max level " + ExperienceManager.hardMaxLevel); + initLookupTables(newMax); + } + final int pos = Arrays.binarySearch(ExperienceManager.xpTotalToReachLevel, exp); + return (pos < 0) ? (-pos - 2) : pos; + } + + public int getXpNeededToLevelUp(final int level) { + Preconditions.checkArgument(level >= 0, "Level may not be negative."); + return (level > 30) ? (62 + (level - 30) * 7) : ((level >= 16) ? (17 + (level - 15) * 3) : 17); + } + + public int getXpForLevel(final int level) { + Preconditions.checkArgument(level >= 0 && level <= ExperienceManager.hardMaxLevel, + "Invalid level " + level + "(must be in range 0.." + ExperienceManager.hardMaxLevel + ')'); + if (level >= ExperienceManager.xpTotalToReachLevel.length) { + initLookupTables(level * 2); + } + return ExperienceManager.xpTotalToReachLevel[level]; + } + + static { + ExperienceManager.hardMaxLevel = 100000; + initLookupTables(25); + } +} diff --git a/src/LorexMC/us/utils/GenericUtils.java b/src/LorexMC/us/utils/GenericUtils.java new file mode 100644 index 0000000..08b18b4 --- /dev/null +++ b/src/LorexMC/us/utils/GenericUtils.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils; + +import java.util.*; + +public final class GenericUtils { + public static List createList(final Object object, final Class type) { + final List output = new ArrayList(); + if (object != null && object instanceof List) { + final List input = (List) object; + for (final Object value : input) { + if (value != null) { + if (value.getClass() == null) { + continue; + } + if (!type.isAssignableFrom(value.getClass())) { + final String simpleName = type.getSimpleName(); + throw new AssertionError("Cannot cast to list! Key " + value + " is not a " + simpleName); + } + final E e = type.cast(value); + output.add(e); + } + } + } + return output; + } + + public static Set castSet(final Object object, final Class type) { + final Set output = new HashSet(); + if (object != null && object instanceof List) { + final List input = (List) object; + for (final Object value : input) { + if (value != null) { + if (value.getClass() == null) { + continue; + } + if (!type.isAssignableFrom(value.getClass())) { + final String simpleName = type.getSimpleName(); + throw new AssertionError("Cannot cast to list! Key " + value + " is not a " + simpleName); + } + final E e = type.cast(value); + output.add(e); + } + } + } + return output; + } + + public static Map castMap(final Object object, final Class keyClass, final Class valueClass) { + final Map output = new HashMap(); + if (object != null && object instanceof Map) { + final Map input = (Map) object; + final String keyClassName = keyClass.getSimpleName(); + final String valueClassName = valueClass.getSimpleName(); + for (final Object key : input.keySet().toArray()) { + if (key != null && !keyClass.isAssignableFrom(key.getClass())) { + throw new AssertionError("Cannot cast to HashMap: " + keyClassName + ", " + keyClassName + + ". Value " + valueClassName + " is not a " + keyClassName); + } + final Object value = input.get(key); + if (value != null && !valueClass.isAssignableFrom(value.getClass())) { + throw new AssertionError("Cannot cast to HashMap: " + valueClassName + ", " + valueClassName + + ". Key " + key + " is not a " + valueClassName); + } + output.put(keyClass.cast(key), valueClass.cast(value)); + } + } + return output; + } +} diff --git a/src/LorexMC/us/utils/InventorySerialisation.java b/src/LorexMC/us/utils/InventorySerialisation.java new file mode 100644 index 0000000..9eb4455 --- /dev/null +++ b/src/LorexMC/us/utils/InventorySerialisation.java @@ -0,0 +1,75 @@ +package LorexMC.us.utils; + +import org.yaml.snakeyaml.external.biz.base64Coder.*; +import org.bukkit.util.io.*; +import org.bukkit.*; +import org.bukkit.inventory.*; +import java.io.*; + +public class InventorySerialisation { + public static String[] playerInventoryToBase64(final PlayerInventory playerInventory) throws IllegalStateException { + final String content = toBase64(playerInventory); + final String armor = itemStackArrayToBase64(playerInventory.getArmorContents()); + return new String[] { content, armor }; + } + + public static String itemStackArrayToBase64(final ItemStack[] items) throws IllegalStateException { + try { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + final BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(items.length); + for (final ItemStack item : items) { + dataOutput.writeObject(item); + } + dataOutput.close(); + return Base64Coder.encodeLines(outputStream.toByteArray()); + } catch (Exception e) { + throw new IllegalStateException("Unable to save item stacks.", e); + } + } + + public static String toBase64(final Inventory inventory) throws IllegalStateException { + try { + final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + final BukkitObjectOutputStream dataOutput = new BukkitObjectOutputStream(outputStream); + dataOutput.writeInt(inventory.getSize()); + for (int i = 0; i < inventory.getSize(); ++i) { + dataOutput.writeObject(inventory.getItem(i)); + } + dataOutput.close(); + return Base64Coder.encodeLines(outputStream.toByteArray()); + } catch (Exception e) { + throw new IllegalStateException("Unable to save item stacks.", e); + } + } + + public static Inventory fromBase64(final String data) throws IOException { + try { + final ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + final BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); + final Inventory inventory = Bukkit.createInventory((InventoryHolder) null, dataInput.readInt()); + for (int i = 0; i < inventory.getSize(); ++i) { + inventory.setItem(i, (ItemStack) dataInput.readObject()); + } + dataInput.close(); + return inventory; + } catch (ClassNotFoundException e) { + throw new IOException("Unable to decode class type.", e); + } + } + + public static ItemStack[] itemStackArrayFromBase64(final String data) throws IOException { + try { + final ByteArrayInputStream inputStream = new ByteArrayInputStream(Base64Coder.decodeLines(data)); + final BukkitObjectInputStream dataInput = new BukkitObjectInputStream(inputStream); + final ItemStack[] items = new ItemStack[dataInput.readInt()]; + for (int i = 0; i < items.length; ++i) { + items[i] = (ItemStack) dataInput.readObject(); + } + dataInput.close(); + return items; + } catch (ClassNotFoundException ex) { + throw new IOException("Unable to decode class type.", ex); + } + } +} diff --git a/src/LorexMC/us/utils/InventoryUtils.java b/src/LorexMC/us/utils/InventoryUtils.java new file mode 100644 index 0000000..c8209ac --- /dev/null +++ b/src/LorexMC/us/utils/InventoryUtils.java @@ -0,0 +1,117 @@ +package LorexMC.us.utils; + +import com.google.common.base.*; +import org.bukkit.*; +import org.bukkit.event.inventory.*; +import org.bukkit.inventory.*; +import java.util.*; + +public final class InventoryUtils { + public static final int DEFAULT_INVENTORY_WIDTH = 9; + public static final int MINIMUM_INVENTORY_HEIGHT = 1; + public static final int MINIMUM_INVENTORY_SIZE = 9; + public static final int MAXIMUM_INVENTORY_HEIGHT = 6; + public static final int MAXIMUM_INVENTORY_SIZE = 54; + public static final int MAXIMUM_SINGLE_CHEST_SIZE = 27; + public static final int MAXIMUM_DOUBLE_CHEST_SIZE = 54; + + public static ItemStack[] deepClone(final ItemStack[] origin) { + Preconditions.checkNotNull((Object) origin, (Object) "Origin cannot be null"); + final ItemStack[] cloned = new ItemStack[origin.length]; + for (int i = 0; i < origin.length; ++i) { + final ItemStack next = origin[i]; + cloned[i] = ((next == null) ? null : next.clone()); + } + return cloned; + } + + public static int getSafestInventorySize(final int initialSize) { + return (initialSize + 8) / 9 * 9; + } + + public static void removeItem(final Inventory inventory, final Material type, final short data, + final int quantity) { + final ItemStack[] contents = inventory.getContents(); + final boolean compareDamage = type.getMaxDurability() == 0; + for (int i = quantity; i > 0; --i) { + for (final ItemStack content : contents) { + if (content != null) { + if (content.getType() == type) { + if (!compareDamage || content.getData().getData() == data) { + if (content.getAmount() <= 1) { + inventory.removeItem(new ItemStack[] { content }); + break; + } + content.setAmount(content.getAmount() - 1); + break; + } + } + } + } + } + } + + public static int countAmount(final Inventory inventory, final Material type, final short data) { + final ItemStack[] contents = inventory.getContents(); + final boolean compareDamage = type.getMaxDurability() == 0; + int counter = 0; + for (final ItemStack item : contents) { + if (item != null) { + if (item.getType() == type) { + if (!compareDamage || item.getData().getData() == data) { + counter += item.getAmount(); + } + } + } + } + return counter; + } + + public static boolean isEmpty(final Inventory inventory) { + return isEmpty(inventory, true); + } + + public static boolean isEmpty(final Inventory inventory, final boolean checkArmour) { + boolean result = true; + final ItemStack[] contents2; + ItemStack[] contents = contents2 = inventory.getContents(); + for (final ItemStack content : contents2) { + if (content != null && content.getType() != Material.AIR) { + result = false; + break; + } + } + if (!result) { + return false; + } + if (checkArmour && inventory instanceof PlayerInventory) { + final ItemStack[] armorContents; + contents = (armorContents = ((PlayerInventory) inventory).getArmorContents()); + for (final ItemStack content : armorContents) { + if (content != null && content.getType() != Material.AIR) { + result = false; + break; + } + } + } + return result; + } + + public static boolean clickedTopInventory(final InventoryDragEvent event) { + final InventoryView view = event.getView(); + final Inventory topInventory = view.getTopInventory(); + if (topInventory == null) { + return false; + } + boolean result = false; + final Set> entrySet = event.getNewItems().entrySet(); + final int size = topInventory.getSize(); + for (final Map.Entry entry : entrySet) { + if (entry.getKey() < size) { + result = true; + break; + } + } + return result; + } +} diff --git a/src/LorexMC/us/utils/ItemBuilder.java b/src/LorexMC/us/utils/ItemBuilder.java new file mode 100644 index 0000000..8badde0 --- /dev/null +++ b/src/LorexMC/us/utils/ItemBuilder.java @@ -0,0 +1,84 @@ +package LorexMC.us.utils; + +import org.bukkit.inventory.*; +import org.bukkit.inventory.meta.*; +import org.bukkit.*; +import com.google.common.base.*; +import java.util.*; +import org.bukkit.enchantments.*; + +public class ItemBuilder { + private ItemStack stack; + private ItemMeta meta; + + public ItemBuilder(final Material material) { + this(material, 1); + } + + public ItemBuilder(final Material material, final int amount) { + this(material, amount, (byte) 0); + } + + public ItemBuilder(final ItemStack stack) { + Preconditions.checkNotNull((Object) stack, (Object) "ItemStack cannot be null"); + this.stack = stack; + } + + public ItemBuilder(final Material material, final int amount, final byte data) { + Preconditions.checkNotNull((Object) material, (Object) "Material cannot be null"); + Preconditions.checkArgument(amount > 0, "Amount must be positive"); + this.stack = new ItemStack(material, amount, data); + } + + public ItemBuilder displayName(final String name) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + this.meta.setDisplayName(name); + return this; + } + + public ItemBuilder loreLine(final String line) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + final boolean hasLore = this.meta.hasLore(); + final List lore = hasLore ? this.meta.getLore() : new ArrayList(); + lore.add(hasLore ? lore.size() : 0, line); + this.lore(line); + return this; + } + + public ItemBuilder lore(final String... lore) { + if (this.meta == null) { + this.meta = this.stack.getItemMeta(); + } + this.meta.setLore(Arrays.asList(lore)); + return this; + } + + public ItemBuilder enchant(final Enchantment enchantment, final int level) { + return this.enchant(enchantment, level, true); + } + + public ItemBuilder enchant(final Enchantment enchantment, final int level, final boolean unsafe) { + if (unsafe && level >= enchantment.getMaxLevel()) { + this.stack.addUnsafeEnchantment(enchantment, level); + } else { + this.stack.addEnchantment(enchantment, level); + } + return this; + } + + public ItemBuilder data(final short data) { + this.stack.setDurability(data); + return this; + } + + public ItemStack build() { + if (this.meta != null) { + this.stack.setItemMeta(this.meta); + } + return this.stack; + } +} diff --git a/src/LorexMC/us/utils/JavaUtils.java b/src/LorexMC/us/utils/JavaUtils.java new file mode 100644 index 0000000..849f236 --- /dev/null +++ b/src/LorexMC/us/utils/JavaUtils.java @@ -0,0 +1,133 @@ +package LorexMC.us.utils; + +import java.util.regex.*; +import org.apache.commons.lang3.*; +import java.math.*; +import com.google.common.base.*; +import java.util.*; +import java.util.concurrent.*; + +public final class JavaUtils { + private static final CharMatcher CHAR_MATCHER_ASCII; + private static final Pattern UUID_PATTERN; + private static final int DEFAULT_NUMBER_FORMAT_DECIMAL_PLACES = 5; + + public static Integer tryParseInt(final String string) { + try { + return Integer.parseInt(string); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static Double tryParseDouble(final String string) { + try { + return Double.parseDouble(string); + } catch (IllegalArgumentException ex) { + return null; + } + } + + public static boolean isUUID(final String string) { + return JavaUtils.UUID_PATTERN.matcher(string).find(); + } + + public static boolean isAlphanumeric(final String string) { + return JavaUtils.CHAR_MATCHER_ASCII.matchesAllOf(string); + } + + public static boolean containsIgnoreCase(final Iterable elements, final String string) { + for (final String element : elements) { + if (StringUtils.containsIgnoreCase(element, string)) { + return true; + } + } + return false; + } + + public static String format(final Number number) { + return format(number, 5); + } + + public static String format(final Number number, final int decimalPlaces) { + return format(number, decimalPlaces, RoundingMode.HALF_DOWN); + } + + public static String format(final Number number, final int decimalPlaces, final RoundingMode roundingMode) { + Preconditions.checkNotNull((Object) number, (Object) "The number cannot be null"); + return new BigDecimal(number.toString()).setScale(decimalPlaces, roundingMode).stripTrailingZeros() + .toPlainString(); + } + + public static String andJoin(final Collection collection, final boolean delimiterBeforeAnd) { + return andJoin(collection, delimiterBeforeAnd, ", "); + } + + public static String andJoin(final Collection collection, final boolean delimiterBeforeAnd, + final String delimiter) { + if (collection == null || collection.isEmpty()) { + return ""; + } + final List contents = new ArrayList(collection); + final String last = contents.remove(contents.size() - 1); + final StringBuilder builder = new StringBuilder(Joiner.on(delimiter).join(contents)); + if (delimiterBeforeAnd) { + builder.append(delimiter); + } + return builder.append(" and ").append(last).toString(); + } + + public static long parse(final String input) { + if (input == null || input.isEmpty()) { + return -1L; + } + long result = 0L; + StringBuilder number = new StringBuilder(); + for (int i = 0; i < input.length(); ++i) { + final char c = input.charAt(i); + if (Character.isDigit(c)) { + number.append(c); + } else { + final String str; + if (Character.isLetter(c) && !(str = number.toString()).isEmpty()) { + result += convert(Integer.parseInt(str), c); + number = new StringBuilder(); + } + } + } + return result; + } + + private static long convert(final int value, final char unit) { + switch (unit) { + case 'y': { + return value * TimeUnit.DAYS.toMillis(365L); + } + case 'M': { + return value * TimeUnit.DAYS.toMillis(30L); + } + case 'd': { + return value * TimeUnit.DAYS.toMillis(1L); + } + case 'h': { + return value * TimeUnit.HOURS.toMillis(1L); + } + case 'm': { + return value * TimeUnit.MINUTES.toMillis(1L); + } + case 's': { + return value * TimeUnit.SECONDS.toMillis(1L); + } + default: { + return -1L; + } + } + } + + static { + CHAR_MATCHER_ASCII = CharMatcher.inRange('0', '9').or(CharMatcher.inRange('a', 'z')) + .or(CharMatcher.inRange('A', 'Z')).or(CharMatcher.WHITESPACE).precomputed(); + UUID_PATTERN = Pattern + .compile("[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[34][0-9a-fA-F]{3}-[89ab][0-9a-fA-F]{3}-[0-9a-fA-F]{12}"); + } +} diff --git a/src/LorexMC/us/utils/MapSorting.java b/src/LorexMC/us/utils/MapSorting.java new file mode 100644 index 0000000..95d6e1c --- /dev/null +++ b/src/LorexMC/us/utils/MapSorting.java @@ -0,0 +1,84 @@ +package LorexMC.us.utils; + +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import com.google.common.base.Function; +import com.google.common.collect.Iterables; +import com.google.common.collect.Ordering; + +@SuppressWarnings("rawtypes") +public class MapSorting { + // Building block - extract key from entry + private static final Function EXTRACT_KEY = new Function, Object>() { + @Override + public Object apply(Entry input) { + return input.getKey(); + } + }; + // Same as above, only we extract the value + private static final Function EXTRACT_VALUE = new Function, Object>() { + @Override + public Object apply(Entry input) { + return input.getValue(); + } + }; + + /** + * Sort the given map by the value in each entry. + * + * @param map + * - map of comparable values. + * @return A new list with the sort result. + */ + public static > List> sortedValues(Map map) { + return sortedValues(map, Ordering.natural()); + } + + /** + * Sort the given map by the value in each entry. + * + * @param map + * - map of comparable values. + * @param valueComparator + * - object for comparing each values. + * @return A new list with the sort result. + */ + public static List> sortedValues(Map map, Comparator valueComparator) { + return Ordering.from(valueComparator).onResultOf(MapSorting.extractValue()).sortedCopy(map.entrySet()); + } + + /** + * Retrieve every key in the entry list in order. + * + * @param entryList + * - the entry list. + * @return Every key in order. + */ + public static Iterable keys(List> entryList) { + return Iterables.transform(entryList, MapSorting.extractKey()); + } + + /** + * Retrieve every value in the entry list in order. + * + * @param entryList + * - the entry list. + * @return Every value in order. + */ + public static Iterable values(List> entryList) { + return Iterables.transform(entryList, MapSorting.extractValue()); + } + + @SuppressWarnings("unchecked") + private static Function, T> extractKey() { + return EXTRACT_KEY; + } + + @SuppressWarnings("unchecked") + private static Function, V> extractValue() { + return EXTRACT_VALUE; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/NmsUtils.java b/src/LorexMC/us/utils/NmsUtils.java new file mode 100644 index 0000000..0c85575 --- /dev/null +++ b/src/LorexMC/us/utils/NmsUtils.java @@ -0,0 +1,53 @@ +package LorexMC.us.utils; + +import org.bukkit.entity.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import net.minecraft.server.v1_7_R4.*; +import net.minecraft.server.v1_7_R4.ItemStack; +import net.minecraft.server.v1_7_R4.PlayerInventory; + +import org.bukkit.inventory.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; + +public class NmsUtils { + public static int getProtocolVersion(final Player player) { + return ((CraftPlayer) player).getHandle().playerConnection.networkManager.getVersion(); + } + + public static void resendHeldItemPacket(final Player player) { + sendItemPacketAtHeldSlot(player, getCleanHeldItem(player)); + } + + public static void sendItemPacketAtHeldSlot(final Player player, final ItemStack stack) { + sendItemPacketAtSlot(player, stack, player.getInventory().getHeldItemSlot()); + } + + public static void sendItemPacketAtSlot(final Player player, final ItemStack stack, final int index) { + sendItemPacketAtSlot(player, stack, index, ((CraftPlayer) player).getHandle().defaultContainer.windowId); + } + + public static void sendItemPacketAtSlot(final Player player, final ItemStack stack, int index, final int windowID) { + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + if (entityPlayer.playerConnection != null) { + if (index < PlayerInventory.getHotbarSize()) { + index += 36; + } else if (index > 35) { + index = 8 - (index - 36); + } + entityPlayer.playerConnection.sendPacket(new PacketPlayOutSetSlot(windowID, index, stack)); + } + } + + public static ItemStack getCleanItem(final Inventory inventory, final int slot) { + return ((CraftInventory) inventory).getInventory().getItem(slot); + } + + public static ItemStack getCleanItem(final Player player, final int slot) { + return getCleanItem(player.getInventory(), slot); + } + + public static ItemStack getCleanHeldItem(final Player player) { + return getCleanItem(player, player.getInventory().getHeldItemSlot()); + } +} diff --git a/src/LorexMC/us/utils/ParticleEffect.java b/src/LorexMC/us/utils/ParticleEffect.java new file mode 100644 index 0000000..1bb0dd7 --- /dev/null +++ b/src/LorexMC/us/utils/ParticleEffect.java @@ -0,0 +1,156 @@ +package LorexMC.us.utils; + +import org.bukkit.craftbukkit.v1_7_R4.entity.*; + +import org.bukkit.entity.*; +import javax.annotation.*; + +import com.google.common.base.*; + +import org.bukkit.*; +import org.bukkit.World; + +import net.minecraft.server.v1_7_R4.*; + +public enum ParticleEffect { + HUGE_EXPLODE("hugeexplosion", 0), LARGE_EXPLODE("largeexplode", 1), FIREWORK_SPARK("fireworksSpark", 2), AIR_BUBBLE( + "bubble", + 3), SUSPEND("suspend", 4), DEPTH_SUSPEND("depthSuspend", 5), TOWN_AURA("townaura", 6), CRITICAL_HIT("crit", + 7), MAGIC_CRITICAL_HIT("magicCrit", 8), MOB_SPELL("mobSpell", 9), MOB_SPELL_AMBIENT( + "mobSpellAmbient", 10), SPELL("spell", 11), INSTANT_SPELL("instantSpell", 12), BLUE_SPARKLE( + "witchMagic", 13), NOTE_BLOCK("note", 14), ENDER("portal", 15), ENCHANTMENT_TABLE( + "enchantmenttable", + 16), EXPLODE("explode", 17), FIRE("flame", 18), LAVA_SPARK("lava", + 19), FOOTSTEP("footstep", 20), SPLASH("splash", 21), LARGE_SMOKE( + "largesmoke", + 22), CLOUD("cloud", 23), REDSTONE_DUST("reddust", + 24), SNOWBALL_HIT("snowballpoof", 25), DRIP_WATER( + "dripWater", + 26), DRIP_LAVA("dripLava", 27), SNOW_DIG( + "snowshovel", + 28), SLIME("slime", 29), HEART( + "heart", + 30), ANGRY_VILLAGER( + "angryVillager", + 31), GREEN_SPARKLE( + "happyVillager", + 32), ICONCRACK( + "iconcrack", + 33), TILECRACK( + "tilecrack", + 34); + + private final String name; + @Deprecated + private final int id; + + private ParticleEffect(final String name, final int id) { + this.name = name; + this.id = id; + } + + @Deprecated + String getName() { + return this.name; + } + + @Deprecated + public int getId() { + return this.id; + } + + public void display(final Player player, final float x, final float y, final float z, final float speed, + final int amount) { + this.display(player, x, y, z, 0.0f, 0.0f, 0.0f, speed, amount); + } + + public void display(final Player player, final float x, final float y, final float z, final float offsetX, + final float offsetY, final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(x, y, z, offsetX, offsetY, offsetZ, speed, amount); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + public void display(final Player player, final Location location, final float speed, final int amount) { + this.display(player, location, 0.0f, 0.0f, 0.0f, speed, amount); + } + + public void display(final Player player, final Location location, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(location, offsetX, offsetY, offsetZ, speed, amount); + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + + public void broadcast(final float x, final float y, final float z, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + final Packet packet = this.createPacket(x, y, z, offsetX, offsetY, offsetZ, speed, amount); + for (final Player player : Bukkit.getOnlinePlayers()) { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount) { + this.broadcast(location, offsetX, offsetY, offsetZ, speed, amount, null, null); + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount, @Nullable final Player source) { + this.broadcast(location, offsetX, offsetY, offsetZ, speed, amount, source, null); + } + + public void broadcast(final Location location, final float offsetX, final float offsetY, final float offsetZ, + final float speed, final int amount, @Nullable final Player source, + @Nullable final Predicate predicate) { + final Packet packet = this.createPacket(location, offsetX, offsetY, offsetZ, speed, amount); + for (final Player player : Bukkit.getOnlinePlayers()) { + if ((source == null || player.canSee(source)) && (predicate == null || predicate.apply(player))) { + ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet); + } + } + } + + public void sphere(@Nullable final Player player, final Location location, final float radius) { + this.sphere(player, location, radius, 20.0f, 2); + } + + public void sphere(@Nullable final Player player, final Location location, final float radius, final float density, + final int intensity) { + Preconditions.checkNotNull((Object) location, (Object) "Location cannot be null"); + Preconditions.checkArgument(radius >= 0.0f, "Radius must be positive"); + Preconditions.checkArgument(density >= 0.0f, "Density must be positive"); + Preconditions.checkArgument(intensity >= 0, "Intensity must be positive"); + final float deltaPitch = 180.0f / density; + final float deltaYaw = 360.0f / density; + final World world = location.getWorld(); + for (int i = 0; i < density; ++i) { + for (int j = 0; j < density; ++j) { + final float pitch = -90.0f + j * deltaPitch; + final float yaw = -180.0f + i * deltaYaw; + final float x = radius * MathHelper.sin(-yaw * 0.017453292f - 3.1415927f) + * -MathHelper.cos(-pitch * 0.017453292f) + (float) location.getX(); + final float y = radius * MathHelper.sin(-pitch * 0.017453292f) + (float) location.getY(); + final float z = radius * MathHelper.cos(-yaw * 0.017453292f - 3.1415927f) + * -MathHelper.cos(-pitch * 0.017453292f) + (float) location.getZ(); + final Location target = new Location(world, x, y, z); + if (player == null) { + this.broadcast(target, 0.0f, 0.0f, 0.0f, 0.0f, intensity); + } else { + this.display(player, target, 0.0f, 0.0f, 0.0f, 0.0f, intensity); + } + } + } + } + + private PacketPlayOutWorldParticles createPacket(final Location location, final float offsetX, final float offsetY, + final float offsetZ, final float speed, final int amount) { + return this.createPacket((float) location.getX(), (float) location.getY(), (float) location.getZ(), offsetX, + offsetY, offsetZ, speed, amount); + } + + private PacketPlayOutWorldParticles createPacket(final float x, final float y, final float z, final float offsetX, + final float offsetY, final float offsetZ, final float speed, final int amount) { + Preconditions.checkArgument(speed >= 0.0f, "Speed must be positive"); + Preconditions.checkArgument(amount > 0, "Cannot use less than one particle."); + return new PacketPlayOutWorldParticles(this.name, x, y, z, offsetX, offsetY, offsetZ, speed, amount); + } +} diff --git a/src/LorexMC/us/utils/PersistableLocation.java b/src/LorexMC/us/utils/PersistableLocation.java new file mode 100644 index 0000000..4c88c6c --- /dev/null +++ b/src/LorexMC/us/utils/PersistableLocation.java @@ -0,0 +1,249 @@ +package LorexMC.us.utils; + +import org.bukkit.configuration.serialization.*; +import com.google.common.base.*; +import java.util.*; +import org.bukkit.*; + +public class PersistableLocation implements ConfigurationSerializable, Cloneable { + private Location location; + private World world; + private String worldName; + private UUID worldUID; + private double x; + private double y; + private double z; + private float yaw; + private float pitch; + + public PersistableLocation(final Location location) { + Preconditions.checkNotNull((Object) location, (Object) "Location cannot be null"); + Preconditions.checkNotNull((Object) location.getWorld(), (Object) "Locations' world cannot be null"); + this.world = location.getWorld(); + this.worldName = this.world.getName(); + this.worldUID = this.world.getUID(); + this.x = location.getX(); + this.y = location.getY(); + this.z = location.getZ(); + this.yaw = location.getYaw(); + this.pitch = location.getPitch(); + } + + public PersistableLocation(final World world, final double x, final double y, final double z) { + this.worldName = world.getName(); + this.x = x; + this.y = y; + this.z = z; + final float n = 0.0f; + this.yaw = n; + this.pitch = n; + } + + public PersistableLocation(final String worldName, final double x, final double y, final double z) { + this.worldName = worldName; + this.x = x; + this.y = y; + this.z = z; + final float n = 0.0f; + this.yaw = n; + this.pitch = n; + } + + public PersistableLocation(final Map map) { + this.worldName = map.get("worldName"); + this.worldUID = UUID.fromString(map.get("worldUID")); + Object o = map.get("x"); + if (o instanceof String) { + this.x = Double.parseDouble((String) o); + } else { + this.x = (double) o; + } + o = map.get("y"); + if (o instanceof String) { + this.y = Double.parseDouble((String) o); + } else { + this.y = (double) o; + } + o = map.get("z"); + if (o instanceof String) { + this.z = Double.parseDouble((String) o); + } else { + this.z = (double) o; + } + this.yaw = Float.parseFloat(map.get("yaw")); + this.pitch = Float.parseFloat(map.get("pitch")); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("worldName", this.worldName); + map.put("worldUID", this.worldUID.toString()); + map.put("x", this.x); + map.put("y", this.y); + map.put("z", this.z); + map.put("yaw", Float.toString(this.yaw)); + map.put("pitch", Float.toString(this.pitch)); + return map; + } + + public World getWorld() { + Preconditions.checkNotNull((Object) this.worldUID, (Object) "World UUID cannot be null"); + Preconditions.checkNotNull((Object) this.worldName, (Object) "World name cannot be null"); + if (this.world == null) { + this.world = Bukkit.getWorld(this.worldUID); + } + return this.world; + } + + public void setWorld(final World world) { + this.worldName = world.getName(); + this.worldUID = world.getUID(); + this.world = world; + } + + public Location getLocation() { + if (this.location == null) { + this.location = new Location(this.getWorld(), this.x, this.y, this.z, this.yaw, this.pitch); + } + return this.location; + } + + @Override + public PersistableLocation clone() throws CloneNotSupportedException { + try { + return (PersistableLocation) super.clone(); + } catch (CloneNotSupportedException ex) { + ex.printStackTrace(); + throw new RuntimeException(); + } + } + + @Override + public String toString() { + return "PersistableLocation [worldName=" + this.worldName + ", worldUID=" + this.worldUID + ", x=" + this.x + + ", y=" + this.y + ", z=" + this.z + ", yaw=" + this.yaw + ", pitch=" + this.pitch + ']'; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof PersistableLocation)) { + return false; + } + final PersistableLocation that = (PersistableLocation) o; + if (Double.compare(that.x, this.x) != 0) { + return false; + } + if (Double.compare(that.y, this.y) != 0) { + return false; + } + if (Double.compare(that.z, this.z) != 0) { + return false; + } + if (Float.compare(that.yaw, this.yaw) != 0) { + return false; + } + if (Float.compare(that.pitch, this.pitch) != 0) { + return false; + } + Label_0134: { + if (this.world != null) { + if (this.world.equals(that.world)) { + break Label_0134; + } + } else if (that.world == null) { + break Label_0134; + } + return false; + } + Label_0167: { + if (this.worldName != null) { + if (this.worldName.equals(that.worldName)) { + break Label_0167; + } + } else if (that.worldName == null) { + break Label_0167; + } + return false; + } + if (this.worldUID != null) { + if (!this.worldUID.equals(that.worldUID)) { + return false; + } + } else if (that.worldUID != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.world != null) ? this.world.hashCode() : 0; + result = 31 * result + ((this.worldName != null) ? this.worldName.hashCode() : 0); + result = 31 * result + ((this.worldUID != null) ? this.worldUID.hashCode() : 0); + long temp = Double.doubleToLongBits(this.x); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(this.y); + result = 31 * result + (int) (temp ^ temp >>> 32); + temp = Double.doubleToLongBits(this.z); + result = 31 * result + (int) (temp ^ temp >>> 32); + result = 31 * result + ((this.yaw != 0.0f) ? Float.floatToIntBits(this.yaw) : 0); + result = 31 * result + ((this.pitch != 0.0f) ? Float.floatToIntBits(this.pitch) : 0); + return result; + } + + public String getWorldName() { + return this.worldName; + } + + public UUID getWorldUID() { + return this.worldUID; + } + + public double getX() { + return this.x; + } + + public double getY() { + return this.y; + } + + public double getZ() { + return this.z; + } + + public float getYaw() { + return this.yaw; + } + + public float getPitch() { + return this.pitch; + } + + public void setWorldUID(final UUID worldUID) { + this.worldUID = worldUID; + } + + public void setX(final double x) { + this.x = x; + } + + public void setY(final double y) { + this.y = y; + } + + public void setZ(final double z) { + this.z = z; + } + + public void setYaw(final float yaw) { + this.yaw = yaw; + } + + public void setPitch(final float pitch) { + this.pitch = pitch; + } +} diff --git a/src/LorexMC/us/utils/SignHandler.java b/src/LorexMC/us/utils/SignHandler.java new file mode 100644 index 0000000..54cbba0 --- /dev/null +++ b/src/LorexMC/us/utils/SignHandler.java @@ -0,0 +1,124 @@ +package LorexMC.us.utils; + +import org.bukkit.plugin.java.*; +import com.google.common.collect.*; +import org.bukkit.event.*; +import org.bukkit.event.player.*; +import org.bukkit.entity.*; +import org.bukkit.scheduler.*; +import org.bukkit.block.*; +import org.bukkit.*; +import org.bukkit.plugin.*; +import javax.annotation.*; +import java.util.*; + +public class SignHandler implements Listener { + private final Multimap signUpdateMap; + private final JavaPlugin plugin; + + public SignHandler(final JavaPlugin plugin) { + this.signUpdateMap = HashMultimap.create(); + this.plugin = plugin; + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerKick(final PlayerQuitEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(final PlayerQuitEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onWorldChange(final PlayerChangedWorldEvent event) { + this.cancelTasks(event.getPlayer(), null, false); + } + + public boolean showLines(final Player player, final Sign sign, final String[] newLines, final long ticks, + final boolean forceChange) { + final String[] lines = sign.getLines(); + if (Arrays.equals(lines, newLines)) { + return false; + } + final Collection signChanges = this.getSignChanges(player); + final Iterator iterator = signChanges.iterator(); + while (iterator.hasNext()) { + final SignChange signChange = iterator.next(); + if (signChange.sign.equals(sign)) { + if (!forceChange && Arrays.equals(signChange.newLines, newLines)) { + return false; + } + signChange.runnable.cancel(); + iterator.remove(); + break; + } + } + final Location location = sign.getLocation(); + player.sendSignChange(location, newLines); + SignChange signChange; + if (signChanges.add(signChange = new SignChange(sign, newLines))) { + final Block block = sign.getBlock(); + final BlockState previous = block.getState(); + final BukkitRunnable runnable = new BukkitRunnable() { + @Override + public void run() { + if (SignHandler.this.signUpdateMap.remove(player.getUniqueId(), signChange) + && previous.equals(block.getState())) { + player.sendSignChange(location, lines); + } + } + }; + runnable.runTaskLater(this.plugin, ticks); + signChange.runnable = runnable; + } + return true; + } + + public Collection getSignChanges(final Player player) { + return this.signUpdateMap.get(player.getUniqueId()); + } + + public void cancelTasks(@Nullable final Sign sign) { + final Iterator iterator = this.signUpdateMap.values().iterator(); + while (iterator.hasNext()) { + final SignChange signChange = iterator.next(); + if (sign == null || signChange.sign.equals(sign)) { + signChange.runnable.cancel(); + signChange.sign.update(); + iterator.remove(); + } + } + } + + public void cancelTasks(final Player player, @Nullable final Sign sign, final boolean revertLines) { + final UUID uuid = player.getUniqueId(); + final Iterator> iterator = this.signUpdateMap.entries().iterator(); + while (iterator.hasNext()) { + final Map.Entry entry = iterator.next(); + if (entry.getKey().equals(uuid)) { + final SignChange signChange = entry.getValue(); + if (sign != null && !signChange.sign.equals(sign)) { + continue; + } + if (revertLines) { + player.sendSignChange(signChange.sign.getLocation(), signChange.sign.getLines()); + } + signChange.runnable.cancel(); + iterator.remove(); + } + } + } + + private static final class SignChange { + public BukkitRunnable runnable; + public final Sign sign; + public final String[] newLines; + + public SignChange(final Sign sign, final String[] newLines) { + this.sign = sign; + this.newLines = newLines; + } + } +} diff --git a/src/LorexMC/us/utils/SpigotUtils.java b/src/LorexMC/us/utils/SpigotUtils.java new file mode 100644 index 0000000..c666cc2 --- /dev/null +++ b/src/LorexMC/us/utils/SpigotUtils.java @@ -0,0 +1,79 @@ +package LorexMC.us.utils; + +import org.bukkit.*; + +public class SpigotUtils { + public static net.md_5.bungee.api.ChatColor toBungee(final ChatColor color) { + switch (color) { + case BLACK: { + return net.md_5.bungee.api.ChatColor.BLACK; + } + case DARK_BLUE: { + return net.md_5.bungee.api.ChatColor.DARK_BLUE; + } + case DARK_GREEN: { + return net.md_5.bungee.api.ChatColor.DARK_GREEN; + } + case DARK_AQUA: { + return net.md_5.bungee.api.ChatColor.DARK_AQUA; + } + case DARK_RED: { + return net.md_5.bungee.api.ChatColor.DARK_RED; + } + case DARK_PURPLE: { + return net.md_5.bungee.api.ChatColor.DARK_PURPLE; + } + case GOLD: { + return net.md_5.bungee.api.ChatColor.GOLD; + } + case GRAY: { + return net.md_5.bungee.api.ChatColor.GRAY; + } + case DARK_GRAY: { + return net.md_5.bungee.api.ChatColor.DARK_GRAY; + } + case BLUE: { + return net.md_5.bungee.api.ChatColor.BLUE; + } + case GREEN: { + return net.md_5.bungee.api.ChatColor.GREEN; + } + case AQUA: { + return net.md_5.bungee.api.ChatColor.AQUA; + } + case RED: { + return net.md_5.bungee.api.ChatColor.RED; + } + case LIGHT_PURPLE: { + return net.md_5.bungee.api.ChatColor.LIGHT_PURPLE; + } + case YELLOW: { + return net.md_5.bungee.api.ChatColor.YELLOW; + } + case WHITE: { + return net.md_5.bungee.api.ChatColor.WHITE; + } + case MAGIC: { + return net.md_5.bungee.api.ChatColor.MAGIC; + } + case BOLD: { + return net.md_5.bungee.api.ChatColor.BOLD; + } + case STRIKETHROUGH: { + return net.md_5.bungee.api.ChatColor.STRIKETHROUGH; + } + case UNDERLINE: { + return net.md_5.bungee.api.ChatColor.UNDERLINE; + } + case ITALIC: { + return net.md_5.bungee.api.ChatColor.ITALIC; + } + case RESET: { + return net.md_5.bungee.api.ChatColor.RESET; + } + default: { + throw new IllegalArgumentException("Unrecognised Bukkit colour " + color.name() + "."); + } + } + } +} diff --git a/src/LorexMC/us/utils/UUIDFetcher.java b/src/LorexMC/us/utils/UUIDFetcher.java new file mode 100644 index 0000000..a236ff6 --- /dev/null +++ b/src/LorexMC/us/utils/UUIDFetcher.java @@ -0,0 +1,97 @@ +package LorexMC.us.utils; + +import java.util.concurrent.*; +import org.json.simple.parser.*; +import com.google.common.collect.*; +import java.nio.charset.*; +import org.json.simple.*; +import java.io.*; +import java.net.*; +import java.nio.*; +import java.util.*; + +public class UUIDFetcher implements Callable> { + private static final double PROFILES_PER_REQUEST = 100.0; + private static final String PROFILE_URL = "https://api.mojang.com/profiles/minecraft"; + private final JSONParser jsonParser; + private final List names; + private final boolean rateLimiting; + + public UUIDFetcher(final List names) { + this(names, true); + } + + public UUIDFetcher(final List names, final boolean rateLimiting) { + this.jsonParser = new JSONParser(); + this.names = ImmutableList.copyOf((Collection) names); + this.rateLimiting = rateLimiting; + } + + @Override + public Map call() throws Exception { + final Map uuidMap = new HashMap(); + for (int requests = (int) Math.ceil(this.names.size() / 100.0), i = 0; i < requests; ++i) { + final HttpURLConnection connection = createConnection(); + final String body = JSONArray + .toJSONString(this.names.subList(i * 100, Math.min((i + 1) * 100, this.names.size()))); + writeBody(connection, body); + final JSONArray array = (JSONArray) this.jsonParser + .parse(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8)); + for (final Object profile : array) { + final JSONObject jsonProfile = (JSONObject) profile; + final String id = (String) jsonProfile.get("id"); + final String name = (String) jsonProfile.get("name"); + final UUID uuid = getUUID(id); + uuidMap.put(name, uuid); + } + if (this.rateLimiting && i != requests - 1) { + Thread.sleep(100L); + } + } + return uuidMap; + } + + private static void writeBody(final HttpURLConnection connection, final String body) throws Exception { + final OutputStream stream = connection.getOutputStream(); + stream.write(body.getBytes(StandardCharsets.UTF_8)); + stream.flush(); + stream.close(); + } + + private static HttpURLConnection createConnection() throws Exception { + final URL url = new URL("https://api.mojang.com/profiles/minecraft"); + final HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod("POST"); + connection.setRequestProperty("Content-Type", "application/json"); + connection.setUseCaches(false); + connection.setDoInput(true); + connection.setDoOutput(true); + return connection; + } + + private static UUID getUUID(final String id) { + return UUID.fromString(id.substring(0, 8) + "-" + id.substring(8, 12) + "-" + id.substring(12, 16) + "-" + + id.substring(16, 20) + "-" + id.substring(20, 32)); + } + + public static byte[] toBytes(final UUID uuid) { + final ByteBuffer byteBuffer = ByteBuffer.wrap(new byte[16]); + byteBuffer.putLong(uuid.getMostSignificantBits()); + byteBuffer.putLong(uuid.getLeastSignificantBits()); + return byteBuffer.array(); + } + + public static UUID fromBytes(final byte[] array) { + if (array.length != 16) { + throw new IllegalArgumentException("Illegal byte array length: " + array.length); + } + final ByteBuffer byteBuffer = ByteBuffer.wrap(array); + final long mostSignificant = byteBuffer.getLong(); + final long leastSignificant = byteBuffer.getLong(); + return new UUID(mostSignificant, leastSignificant); + } + + public static UUID getUUIDOf(final String name) throws Exception { + return new UUIDFetcher(Collections.singletonList(name)).call().get(name); + } +} diff --git a/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java b/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java new file mode 100644 index 0000000..4d71d7d --- /dev/null +++ b/src/LorexMC/us/utils/compat/com/google/common/collect/FluentIterableCompat.java @@ -0,0 +1,48 @@ +package LorexMC.us.utils.compat.com.google.common.collect; + +import com.google.common.annotations.*; +import java.util.*; +import javax.annotation.*; +import com.google.common.base.*; +import com.google.common.collect.*; + +@GwtCompatible(emulated = true) +public abstract class FluentIterableCompat implements Iterable { + private final Iterable iterable; + + FluentIterableCompat(final Iterable iterable) { + this.iterable = (Iterable) Preconditions.checkNotNull((Object) iterable); + } + + @CheckReturnValue + public static FluentIterableCompat from(final Iterable iterable) { + return (iterable instanceof FluentIterableCompat) ? ((FluentIterableCompat) iterable) + : new FluentIterableCompat(iterable) { + @Override + public Iterator iterator() { + return iterable.iterator(); + } + }; + } + + @CheckReturnValue + @Override + public String toString() { + return Iterables.toString(this.iterable); + } + + @CheckReturnValue + public final FluentIterableCompat filter(final Predicate predicate) { + return from((Iterable) Iterables.filter((Iterable) this.iterable, (Predicate) predicate)); + } + + @CheckReturnValue + public final FluentIterableCompat transform(final Function function) { + return from((Iterable) Iterables.transform((Iterable) this.iterable, (Function) function)); + } + + @CheckReturnValue + public final ImmutableList toList() { + return ImmutableList.copyOf((Iterable) this.iterable); + } +} diff --git a/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java b/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java new file mode 100644 index 0000000..52956e7 --- /dev/null +++ b/src/LorexMC/us/utils/compat/com/google/common/collect/GuavaCompat.java @@ -0,0 +1,20 @@ +package LorexMC.us.utils.compat.com.google.common.collect; + +import com.google.common.base.*; +import javax.annotation.*; + +public class GuavaCompat { + public static > Optional getIfPresent(final Class enumClass, final String value) { + Preconditions.checkNotNull((Object) enumClass); + Preconditions.checkNotNull((Object) value); + try { + return Optional.of(Enum.valueOf(enumClass, value)); + } catch (IllegalArgumentException iae) { + return Optional.absent(); + } + } + + public static T firstNonNull(@Nullable final T first, @Nullable final T second) { + return (first != null) ? first : Preconditions.checkNotNull(second); + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java b/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java new file mode 100644 index 0000000..41800b7 --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/BaseConstants.java @@ -0,0 +1,12 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +import org.bukkit.*; + +public final class BaseConstants { + public static final String PLAYER_WITH_NAME_OR_UUID_NOT_FOUND; + + static { + PLAYER_WITH_NAME_OR_UUID_NOT_FOUND = ChatColor.GOLD + "Player with name or UUID '" + ChatColor.WHITE + "%1$s" + + ChatColor.GOLD + "' not found."; + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java b/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java new file mode 100644 index 0000000..c1c4f8d --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/BasePlugin.java @@ -0,0 +1,76 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +import java.util.*; +import org.bukkit.plugin.java.*; + +import LorexMC.us.utils.PersistableLocation; +import LorexMC.us.utils.SignHandler; +import LorexMC.us.utils.other.chat.*; +import LorexMC.us.utils.other.cuboid.*; +import LorexMC.us.utils.other.itemdb.*; +import me.bruce.factions.listener.PlayTimeManager; + +import org.bukkit.configuration.serialization.*; + +import java.io.*; + +public class BasePlugin { + private Random random; + private static ItemDb itemDb; + private SignHandler signHandler; + private static BasePlugin plugin; + private JavaPlugin javaPlugin; + + private BasePlugin() { + this.random = new Random(); + } + + public void init(final JavaPlugin plugin) { + this.javaPlugin = plugin; + ConfigurationSerialization.registerClass(PersistableLocation.class); + ConfigurationSerialization.registerClass(Cuboid.class); + ConfigurationSerialization.registerClass(NamedCuboid.class); + this.itemDb = new SimpleItemDb(plugin); + this.signHandler = new SignHandler(plugin); + try { + Lang.initialize("en_US"); + } catch (IOException ex) { + ex.printStackTrace(); + } + } + + public void disable() { + this.signHandler.cancelTasks(null); + this.javaPlugin = null; + BasePlugin.plugin = null; + } + + public Random getRandom() { + return this.random; + } + + public static ItemDb getItemDb() { + return itemDb; + } + + public SignHandler getSignHandler() { + return this.signHandler; + } + + public static BasePlugin getPlugin() { + return BasePlugin.plugin; + } + + public JavaPlugin getJavaPlugin() { + return this.javaPlugin; + } + + static { + BasePlugin.plugin = new BasePlugin(); + } + + public PlayTimeManager getPlayTimeManager() { + // TODO Auto-generated method stub + return null; + } +} diff --git a/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java b/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java new file mode 100644 index 0000000..419c0ab --- /dev/null +++ b/src/LorexMC/us/utils/internal/com/bruce/base/Callback.java @@ -0,0 +1,5 @@ +package LorexMC.us.utils.internal.com.bruce.base; + +public interface Callback { + void done(final V p0, final Throwable p1); +} diff --git a/src/LorexMC/us/utils/other/chat/ChatUtil.java b/src/LorexMC/us/utils/other/chat/ChatUtil.java new file mode 100644 index 0000000..fad0af5 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/ChatUtil.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.potion.*; +import org.apache.commons.lang.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; +import org.bukkit.*; +import org.bukkit.Material; +import org.bukkit.command.*; +import org.bukkit.entity.*; +import org.bukkit.craftbukkit.v1_7_R4.entity.*; +import net.minecraft.server.v1_7_R4.*; + +public class ChatUtil { + public static String getName(final ItemStack stack) { + if (stack.tag != null && stack.tag.hasKeyOfType("display", 10)) { + final NBTTagCompound nbttagcompound = stack.tag.getCompound("display"); + if (nbttagcompound.hasKeyOfType("Name", 8)) { + return nbttagcompound.getString("Name"); + } + } + return stack.getItem().a(stack) + ".name"; + } + + public static Trans localFromItem(final org.bukkit.inventory.ItemStack stack) { + if (stack.getType() == Material.POTION && stack.getData().getData() == 0) { + final Potion potion = Potion.fromItemStack(stack); + if (potion != null) { + final PotionType type = potion.getType(); + if (type != null && type != PotionType.WATER) { + final String effectName = (potion.isSplash() ? "Splash " : "") + + WordUtils.capitalizeFully(type.name().replace('_', ' ')) + " L" + potion.getLevel(); + return fromItemStack(stack).append(" of " + effectName); + } + } + } + return fromItemStack(stack); + } + + public static Trans fromItemStack(final org.bukkit.inventory.ItemStack stack) { + final ItemStack nms = CraftItemStack.asNMSCopy(stack); + final NBTTagCompound tag = new NBTTagCompound(); + nms.save(tag); + return new Trans(getName(nms), new Object[0]).setColor(ChatColor.getByChar(nms.w().e.getChar())) + .setHover(HoverAction.SHOW_ITEM, new ChatComponentText(tag.toString())); + } + + public static void reset(final IChatBaseComponent text) { + final ChatModifier modifier = text.getChatModifier(); + modifier.a((ChatHoverable) null); + modifier.setChatClickable((ChatClickable) null); + modifier.setBold(false); + modifier.setColor(EnumChatFormat.RESET); + modifier.setItalic(false); + modifier.setRandom(false); + modifier.setStrikethrough(false); + modifier.setUnderline(false); + } + + public static void send(final CommandSender sender, final IChatBaseComponent text) { + if (sender instanceof Player) { + final Player player = (Player) sender; + final PacketPlayOutChat packet = new PacketPlayOutChat(text, true); + final EntityPlayer entityPlayer = ((CraftPlayer) player).getHandle(); + entityPlayer.playerConnection.sendPacket(packet); + } else { + sender.sendMessage(text.c()); + } + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/ClickAction.java b/src/LorexMC/us/utils/other/chat/ClickAction.java new file mode 100644 index 0000000..f291597 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/ClickAction.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils.other.chat; + +import net.minecraft.server.v1_7_R4.*; + +public enum ClickAction { + OPEN_URL(EnumClickAction.OPEN_URL), OPEN_FILE(EnumClickAction.OPEN_FILE), RUN_COMMAND( + EnumClickAction.RUN_COMMAND), SUGGEST_COMMAND(EnumClickAction.SUGGEST_COMMAND); + + private final EnumClickAction clickAction; + + private ClickAction(final EnumClickAction action) { + this.clickAction = action; + } + + public EnumClickAction getNMS() { + return this.clickAction; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/HoverAction.java b/src/LorexMC/us/utils/other/chat/HoverAction.java new file mode 100644 index 0000000..fe7b0cd --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/HoverAction.java @@ -0,0 +1,18 @@ +package LorexMC.us.utils.other.chat; + +import net.minecraft.server.v1_7_R4.*; + +public enum HoverAction { + SHOW_TEXT(EnumHoverAction.SHOW_TEXT), SHOW_ITEM(EnumHoverAction.SHOW_ITEM), SHOW_ACHIEVEMENT( + EnumHoverAction.SHOW_ACHIEVEMENT); + + private final EnumHoverAction hoverAction; + + private HoverAction(final EnumHoverAction hoverAction) { + this.hoverAction = hoverAction; + } + + public EnumHoverAction getNMS() { + return this.hoverAction; + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/Lang.java b/src/LorexMC/us/utils/other/chat/Lang.java new file mode 100644 index 0000000..6a3cffb --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Lang.java @@ -0,0 +1,99 @@ +package LorexMC.us.utils.other.chat; + +import java.util.*; + +import org.bukkit.*; + +import java.util.logging.*; +import java.net.*; +import java.nio.charset.*; +import java.util.regex.*; +import java.io.*; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; + +import net.minecraft.server.v1_7_R4.*; + +import com.google.common.base.*; + +import org.bukkit.enchantments.Enchantment; +import org.bukkit.potion.*; +import org.bukkit.craftbukkit.v1_7_R4.potion.*; + +@Deprecated +public class Lang { + private static final Pattern PATTERN; + private static final String HASH_17 = "03f31164d234f10a3230611656332f1756e570a9"; + private static Map translations; + + public static void initialize(final String lang) throws IOException { + Lang.translations = new HashMap(); + Bukkit.getLogger().log(Level.INFO, "Initialling"); + if ("03f31164d234f10a3230611656332f1756e570a9".length() >= 2) { + final String url = "http://resources.download.minecraft.net/" + + "03f31164d234f10a3230611656332f1756e570a9".substring(0, 2) + "/" + + "03f31164d234f10a3230611656332f1756e570a9"; + try (final BufferedReader reader = new BufferedReader( + new InputStreamReader(new URL(url).openStream(), StandardCharsets.UTF_8))) { + String line; + while ((line = reader.readLine()) != null) { + line = line.trim(); + // Bukkit.getLogger().info(line); + if (line.contains("=")) { + final Matcher matcher = Lang.PATTERN.matcher(line); + if (!matcher.matches()) { + continue; + } + Lang.translations.put(matcher.group(1), matcher.group(2)); + } + } + } + } + } + + public static String translatableFromStack(final ItemStack stack) { + final net.minecraft.server.v1_7_R4.ItemStack nms = CraftItemStack.asNMSCopy(stack); + final Item item = nms.getItem(); + return item.a(nms) + ".name"; + } + + public static String fromStack(final ItemStack stack) { + final String node = translatableFromStack(stack); + return (String) MoreObjects.firstNonNull((Object) Lang.translations.get(node), (Object) node); + } + + public static String translatableFromEnchantment(final Enchantment ench) { + final net.minecraft.server.v1_7_R4.Enchantment nms = net.minecraft.server.v1_7_R4.Enchantment.byId[ench + .getId()]; + return (nms == null) ? ench.getName() : nms.a(); + } + + public static String fromEnchantment(final Enchantment enchantment) { + final String node = translatableFromEnchantment(enchantment); + final String trans = Lang.translations.get(node); + return (trans != null) ? trans : node; + } + + public static String translatableFromPotionEffectType(final PotionEffectType effectType) { + final CraftPotionEffectType craftType = (CraftPotionEffectType) PotionEffectType.getById(effectType.getId()); + return craftType.getHandle().a(); + } + + public static String fromPotionEffectType(final PotionEffectType effectType) { + final String node = translatableFromPotionEffectType(effectType); + final String val = Lang.translations.get(node); + if (val == null) { + return node; + } + return val; + } + + public static String translate(final String key, final Object... args) { + return String.format(Lang.translations.get(key), args); + } + + static { + PATTERN = Pattern.compile("^\\s*([\\w\\d\\.]+)\\s*=\\s*(.*)\\s*$"); + } +} diff --git a/src/LorexMC/us/utils/other/chat/Text.java b/src/LorexMC/us/utils/other/chat/Text.java new file mode 100644 index 0000000..334d7d8 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Text.java @@ -0,0 +1,133 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.inventory.ItemStack; + +import net.minecraft.server.v1_7_R4.*; +import org.bukkit.command.*; +import org.bukkit.*; +import org.bukkit.entity.*; + +public class Text extends ChatComponentText { + public Text() { + super(""); + } + + public Text(final String string) { + super(string); + } + + public Text(final Object object) { + super(String.valueOf(object)); + } + + public static Trans fromItemStack(final ItemStack stack) { + return ChatUtil.fromItemStack(stack); + } + + public Text append(final Object object) { + return this.append(String.valueOf(object)); + } + + public Text append(final String text) { + return (Text) this.a(text); + } + + public Text setClick1(ClickAction action, String value) { + getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Text append(final IChatBaseComponent node) { + return (Text) this.addSibling(node); + } + + public Text append(final IChatBaseComponent... nodes) { + for (final IChatBaseComponent node : nodes) { + this.addSibling(node); + } + return this; + } + + public Text localText(final ItemStack stack) { + return this.append(ChatUtil.localFromItem(stack)); + } + + public Text appendItem(final ItemStack stack) { + return this.append(ChatUtil.fromItemStack(stack)); + } + + public Text setBold(final boolean bold) { + this.getChatModifier().setBold(bold); + return this; + } + + public Text setItalic(final boolean italic) { + this.getChatModifier().setItalic(italic); + return this; + } + + public Text setUnderline(final boolean underline) { + this.getChatModifier().setUnderline(underline); + return this; + } + + public Text setRandom(final boolean random) { + this.getChatModifier().setRandom(random); + return this; + } + + public Text setStrikethrough(final boolean strikethrough) { + this.getChatModifier().setStrikethrough(strikethrough); + return this; + } + + public Text setColor(final ChatColor color) { + this.getChatModifier().setColor(EnumChatFormat.valueOf(color.name())); + return this; + } + + public Text setClick(final ClickAction action, final String value) { + this.getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Text setHover(final HoverAction action, final IChatBaseComponent value) { + this.getChatModifier().a(new ChatHoverable(action.getNMS(), value)); + return this; + } + + public Text setHoverText(final String text) { + return this.setHover(HoverAction.SHOW_TEXT, new Text(text)); + } + + public Text reset() { + ChatUtil.reset(this); + return this; + } + + @Override + public IChatBaseComponent f() { + return this.h(); + } + + public String toRawText() { + return this.c(); + } + + public void send(final CommandSender sender) { + ChatUtil.send(sender, this); + } + + public void broadcast() { + this.broadcast(null); + } + + public void broadcast(final String permission) { + for (final Player player : Bukkit.getOnlinePlayers()) { + if (permission == null || player.hasPermission(permission)) { + this.send(player); + } + } + this.send(Bukkit.getConsoleSender()); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/chat/Trans.java b/src/LorexMC/us/utils/other/chat/Trans.java new file mode 100644 index 0000000..0bbf3f0 --- /dev/null +++ b/src/LorexMC/us/utils/other/chat/Trans.java @@ -0,0 +1,109 @@ +package LorexMC.us.utils.other.chat; + +import org.bukkit.inventory.ItemStack; +import org.bukkit.*; +import net.minecraft.server.v1_7_R4.*; +import org.bukkit.command.*; + +public class Trans extends ChatMessage { + public Trans() { + super("", new Object[0]); + } + + public Trans(final String string, final Object... objects) { + super(string, objects); + } + + public static Trans fromItemStack(final ItemStack stack) { + return ChatUtil.fromItemStack(stack); + } + + @Override + public IChatBaseComponent f() { + return this.h(); + } + + public Trans append(final Object object) { + return this.append(String.valueOf(object)); + } + + public Trans append(final String text) { + return (Trans) this.a(text); + } + + public Trans append(final IChatBaseComponent node) { + return (Trans) this.addSibling(node); + } + + public Trans append(final IChatBaseComponent... nodes) { + for (final IChatBaseComponent node : nodes) { + this.addSibling(node); + } + return this; + } + + public Trans appendItem(final ItemStack stack) { + return this.append(ChatUtil.fromItemStack(stack)); + } + + public Trans localText(final ItemStack stack) { + return this.append(ChatUtil.localFromItem(stack)); + } + + public Trans setBold(final boolean bold) { + this.getChatModifier().setBold(bold); + return this; + } + + public Trans setItalic(final boolean italic) { + this.getChatModifier().setItalic(italic); + return this; + } + + public Trans setUnderline(final boolean underline) { + this.getChatModifier().setUnderline(underline); + return this; + } + + public Trans setRandom(final boolean random) { + this.getChatModifier().setRandom(random); + return this; + } + + public Trans setStrikethrough(final boolean strikethrough) { + this.getChatModifier().setStrikethrough(strikethrough); + return this; + } + + public Trans setColor(final ChatColor color) { + this.getChatModifier().setColor(EnumChatFormat.valueOf(color.name())); + return this; + } + + public Trans setClick(final ClickAction action, final String value) { + this.getChatModifier().setChatClickable(new ChatClickable(action.getNMS(), value)); + return this; + } + + public Trans setHover(final HoverAction action, final IChatBaseComponent value) { + this.getChatModifier().a(new ChatHoverable(action.getNMS(), value)); + return this; + } + + public Trans setHoverText(final String text) { + return this.setHover(HoverAction.SHOW_TEXT, new Text(text)); + } + + public Trans reset() { + ChatUtil.reset(this); + return this; + } + + public String toRawText() { + return this.c(); + } + + public void send(final CommandSender sender) { + ChatUtil.send(sender, this); + } +} \ No newline at end of file diff --git a/src/LorexMC/us/utils/other/command/ArgumentExecutor.java b/src/LorexMC/us/utils/other/command/ArgumentExecutor.java new file mode 100644 index 0000000..d44dda0 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/ArgumentExecutor.java @@ -0,0 +1,107 @@ +package LorexMC.us.utils.other.command; + +import com.google.common.collect.*; + +import LorexMC.us.utils.*; + +import java.util.*; +import org.bukkit.command.*; +import org.bukkit.*; +import org.apache.commons.lang3.text.*; + +public abstract class ArgumentExecutor implements CommandExecutor, TabCompleter { + protected final List arguments; + protected final String label; + + public ArgumentExecutor(final String label) { + this.arguments = new ArrayList(); + this.label = label; + } + + public boolean containsArgument(final CommandArgument argument) { + return this.arguments.contains(argument); + } + + public void addArgument(final CommandArgument argument) { + this.arguments.add(argument); + } + + public void removeArgument(final CommandArgument argument) { + this.arguments.remove(argument); + } + + public CommandArgument getArgument(final String id) { + for (final CommandArgument argument : this.arguments) { + final String name = argument.getName(); + if (name.equalsIgnoreCase(id) || Arrays.asList(argument.getAliases()).contains(id.toLowerCase())) { + return argument; + } + } + return null; + } + + public String getLabel() { + return this.label; + } + + public List getArguments() { + return ImmutableList.copyOf((Collection) this.arguments); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(String.valueOf(ChatColor.GRAY.toString()) + ChatColor.STRIKETHROUGH + + "----------------------------------------------------"); + sender.sendMessage(String.valueOf(ChatColor.GOLD.toString()) + ChatColor.BOLD + WordUtils + .capitalizeFully(String.valueOf(this.label) + ChatColor.GOLD + ChatColor.BOLD + " Help")); + sender.sendMessage(""); + for (final CommandArgument argument : this.arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + sender.sendMessage( + ChatColor.GOLD + argument.getUsage(label) + " §7» §f" + argument.getDescription() + '.'); + } + } + sender.sendMessage(String.valueOf(ChatColor.GRAY.toString()) + ChatColor.STRIKETHROUGH + + "----------------------------------------------------"); + return true; + } + final CommandArgument argument2 = this.getArgument(args[0]); + final String permission2 = (argument2 == null) ? null : argument2.getPermission(); + if (argument2 == null || (permission2 != null && !sender.hasPermission(permission2))) { + sender.sendMessage(ChatColor.RED + WordUtils.capitalizeFully(this.label) + "Error."); + return true; + } + argument2.onCommand(sender, command, label, args); + return true; + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + List results = new ArrayList(); + if (args.length < 2) { + for (final CommandArgument argument : this.arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + results.add(argument.getName()); + } + } + } else { + final CommandArgument argument2 = this.getArgument(args[0]); + if (argument2 == null) { + return results; + } + final String permission2 = argument2.getPermission(); + if (permission2 == null || sender.hasPermission(permission2)) { + results = argument2.onTabComplete(sender, command, label, args); + if (results == null) { + return null; + } + } + } + return BukkitUtils.getCompletions(args, results); + } +} diff --git a/src/LorexMC/us/utils/other/command/CommandArgument.java b/src/LorexMC/us/utils/other/command/CommandArgument.java new file mode 100644 index 0000000..42866e2 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/CommandArgument.java @@ -0,0 +1,114 @@ +package LorexMC.us.utils.other.command; + +import org.apache.commons.lang3.*; +import org.bukkit.command.*; +import java.util.*; + +public abstract class CommandArgument { + private final String name; + protected boolean isPlayerOnly; + protected String description; + protected String permission; + protected String[] aliases; + + public CommandArgument(final String name, final String description) { + this(name, description, (String) null); + } + + public CommandArgument(final String name, final String description, final String permission) { + this(name, description, permission, ArrayUtils.EMPTY_STRING_ARRAY); + } + + public CommandArgument(final String name, final String description, final String[] aliases) { + this(name, description, null, aliases); + } + + public CommandArgument(final String name, final String description, final String permission, + final String[] aliases) { + this.isPlayerOnly = false; + this.name = name; + this.description = description; + this.permission = permission; + this.aliases = Arrays.copyOf(aliases, aliases.length); + } + + public final String getName() { + return this.name; + } + + public boolean isPlayerOnly() { + return this.isPlayerOnly; + } + + public final String getDescription() { + return this.description; + } + + public final String getPermission() { + return this.permission; + } + + public final String[] getAliases() { + if (this.aliases == null) { + this.aliases = ArrayUtils.EMPTY_STRING_ARRAY; + } + return Arrays.copyOf(this.aliases, this.aliases.length); + } + + public abstract String getUsage(final String p0); + + public abstract boolean onCommand(final CommandSender p0, final Command p1, final String p2, final String[] p3); + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + return Collections.emptyList(); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CommandArgument)) { + return false; + } + final CommandArgument that = (CommandArgument) o; + Label_0054: { + if (this.name != null) { + if (this.name.equals(that.name)) { + break Label_0054; + } + } else if (that.name == null) { + break Label_0054; + } + return false; + } + Label_0087: { + if (this.description != null) { + if (this.description.equals(that.description)) { + break Label_0087; + } + } else if (that.description == null) { + break Label_0087; + } + return false; + } + if (this.permission != null) { + if (this.permission.equals(that.permission)) { + return Arrays.equals(this.aliases, that.aliases); + } + } else if (that.permission == null) { + return Arrays.equals(this.aliases, that.aliases); + } + return false; + } + + @Override + public int hashCode() { + int result = (this.name != null) ? this.name.hashCode() : 0; + result = 31 * result + ((this.description != null) ? this.description.hashCode() : 0); + result = 31 * result + ((this.permission != null) ? this.permission.hashCode() : 0); + result = 31 * result + ((this.aliases != null) ? Arrays.hashCode(this.aliases) : 0); + return result; + } +} diff --git a/src/LorexMC/us/utils/other/command/CommandWrapper.java b/src/LorexMC/us/utils/other/command/CommandWrapper.java new file mode 100644 index 0000000..d367d25 --- /dev/null +++ b/src/LorexMC/us/utils/other/command/CommandWrapper.java @@ -0,0 +1,97 @@ +package LorexMC.us.utils.other.command; + +import org.bukkit.command.*; +import org.bukkit.entity.*; + +import LorexMC.us.utils.BukkitUtils; +import org.bukkit.*; +import org.apache.commons.lang3.text.*; +import java.util.*; +import java.io.*; + +public class CommandWrapper implements CommandExecutor, TabCompleter { + private final Collection arguments; + + public CommandWrapper(final Collection arguments) { + this.arguments = arguments; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + printUsage(sender, label, this.arguments); + return true; + } + final CommandArgument argument = matchArgument(args[0], sender, this.arguments); + if (argument == null) { + printUsage(sender, label, this.arguments); + return true; + } + return argument.onCommand(sender, command, label, args); + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (!(sender instanceof Player)) { + return Collections.emptyList(); + } + List results; + if (args.length == 1) { + results = getAccessibleArgumentNames(sender, this.arguments); + } else { + final CommandArgument argument = matchArgument(args[0], sender, this.arguments); + if (argument == null) { + return Collections.emptyList(); + } + results = argument.onTabComplete(sender, command, label, args); + if (results == null) { + return null; + } + } + return BukkitUtils.getCompletions(args, results); + } + + public static void printUsage(final CommandSender sender, final String label, + final Collection arguments) { + sender.sendMessage(ChatColor.DARK_AQUA + "*** " + WordUtils.capitalizeFully(label) + " Help ***"); + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + sender.sendMessage(ChatColor.GRAY + argument.getUsage(label) + " - " + argument.getDescription()); + } + } + } + + public static CommandArgument matchArgument(final String id, final CommandSender sender, + final Collection arguments) { + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if ((permission == null || sender.hasPermission(permission)) + && (argument.getName().equalsIgnoreCase(id) || Arrays.asList(argument.getAliases()).contains(id))) { + return argument; + } + } + return null; + } + + public static List getAccessibleArgumentNames(final CommandSender sender, + final Collection arguments) { + final List results = new ArrayList(); + for (final CommandArgument argument : arguments) { + final String permission = argument.getPermission(); + if (permission == null || sender.hasPermission(permission)) { + results.add(argument.getName()); + } + } + return results; + } + + public static class ArgumentComparator implements Comparator, Serializable { + @Override + public int compare(final CommandArgument primaryArgument, final CommandArgument secondaryArgument) { + return secondaryArgument.getName().compareTo(primaryArgument.getName()); + } + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java b/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java new file mode 100644 index 0000000..4fc7344 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CoordinatePair.java @@ -0,0 +1,69 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; +import org.bukkit.*; + +public class CoordinatePair { + private final String worldName; + private final int x; + private final int z; + + public CoordinatePair(final Block block) { + this(block.getWorld(), block.getX(), block.getZ()); + } + + public CoordinatePair(final World world, final int x, final int z) { + this.worldName = world.getName(); + this.x = x; + this.z = z; + } + + public World getWorld() { + return Bukkit.getWorld(this.worldName); + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (!(o instanceof CoordinatePair)) { + return false; + } + final CoordinatePair that = (CoordinatePair) o; + if (this.x != that.x) { + return false; + } + if (this.z != that.z) { + return false; + } + if (this.worldName != null) { + if (!this.worldName.equals(that.worldName)) { + return false; + } + } else if (that.worldName != null) { + return false; + } + return true; + } + + @Override + public int hashCode() { + int result = (this.worldName != null) ? this.worldName.hashCode() : 0; + result = 31 * result + this.x; + result = 31 * result + this.z; + return result; + } + + public String getWorldName() { + return this.worldName; + } + + public int getX() { + return this.x; + } + + public int getZ() { + return this.z; + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/Cuboid.java b/src/LorexMC/us/utils/other/cuboid/Cuboid.java new file mode 100644 index 0000000..6905044 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/Cuboid.java @@ -0,0 +1,519 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; +import org.bukkit.configuration.serialization.*; + +import com.google.common.base.*; + +import org.bukkit.util.Vector; +import org.bukkit.entity.*; + +import java.util.*; + +import org.bukkit.*; + +public class Cuboid implements Iterable, Cloneable, ConfigurationSerializable { + protected final String worldName; + protected int x1; + protected int y1; + protected int z1; + protected int x2; + protected int y2; + protected int z2; + private static final int CHUNK_SIZE = 16; + + public Cuboid(final Map map) { + this.worldName = (String) map.get("worldName"); + this.x1 = (int) map.get("x1"); + this.y1 = (int) map.get("y1"); + this.z1 = (int) map.get("z1"); + this.x2 = (int) map.get("x2"); + this.y2 = (int) map.get("y2"); + this.z2 = (int) map.get("z2"); + } + + public Cuboid(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + this(((World) Preconditions.checkNotNull((Object) world)).getName(), x1, y1, z1, x2, y2, z2); + } + + private Cuboid(final String worldName, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + Preconditions.checkNotNull((Object) worldName, (Object) "World name cannot be null"); + this.worldName = worldName; + this.x1 = Math.min(x1, x2); + this.y1 = Math.min(y1, y2); + this.z1 = Math.min(z1, z2); + this.x2 = Math.max(x1, x2); + this.y2 = Math.max(y1, y2); + this.z2 = Math.max(z1, z2); + } + + public Cuboid(final Location first, final Location second) { + Preconditions.checkNotNull((Object) first, (Object) "Location 1 cannot be null"); + Preconditions.checkNotNull((Object) second, (Object) "Location 2 cannot be null"); + Preconditions.checkArgument(first.getWorld().equals(second.getWorld()), "Locations must be on the same world"); + this.worldName = first.getWorld().getName(); + this.x1 = Math.min(first.getBlockX(), second.getBlockX()); + this.y1 = Math.min(first.getBlockY(), second.getBlockY()); + this.z1 = Math.min(first.getBlockZ(), second.getBlockZ()); + this.x2 = Math.max(first.getBlockX(), second.getBlockX()); + this.y2 = Math.max(first.getBlockY(), second.getBlockY()); + this.z2 = Math.max(first.getBlockZ(), second.getBlockZ()); + } + + public Cuboid(final Location location) { + this(location, location); + } + + public Cuboid(final Cuboid other) { + this(other.getWorld().getName(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("worldName", this.worldName); + map.put("x1", this.x1); + map.put("y1", this.y1); + map.put("z1", this.z1); + map.put("x2", this.x2); + map.put("y2", this.y2); + map.put("z2", this.z2); + return map; + } + + public boolean hasBothPositionsSet() { + return this.getMinimumPoint() != null && this.getMaximumPoint() != null; + } + + public int getMinimumX() { + return Math.min(this.x1, this.x2); + } + + public int getMinimumZ() { + return Math.min(this.z1, this.z2); + } + + public int getMaximumX() { + return Math.max(this.x1, this.x2); + } + + public int getMaximumZ() { + return Math.max(this.z1, this.z2); + } + + public List edges() { + return this.edges(-1, -1, -1, -1); + } + + public List edges(final int fixedMinX, final int fixedMaxX, final int fixedMinZ, final int fixedMaxZ) { + final Vector v1 = this.getMinimumPoint().toVector(); + final Vector v2 = this.getMaximumPoint().toVector(); + final int minX = v1.getBlockX(); + final int maxX = v2.getBlockX(); + final int minZ = v1.getBlockZ(); + final int maxZ = v2.getBlockZ(); + int capacity = (maxX - minX) * 4 + (maxZ - minZ) * 4; + capacity += 4; + final List result = new ArrayList(capacity); + if (capacity <= 0) { + return result; + } + final int minY = v1.getBlockY(); + final int maxY = v1.getBlockY(); + for (int x = minX; x <= maxX; ++x) { + result.add(new Vector(x, minY, minZ)); + result.add(new Vector(x, minY, maxZ)); + result.add(new Vector(x, maxY, minZ)); + result.add(new Vector(x, maxY, maxZ)); + } + for (int z = minZ; z <= maxZ; ++z) { + result.add(new Vector(minX, minY, z)); + result.add(new Vector(minX, maxY, z)); + result.add(new Vector(maxX, minY, z)); + result.add(new Vector(maxX, maxY, z)); + } + return result; + } + + public Set getPlayers() { + final Set players = new HashSet(); + for (final Player player : Bukkit.getOnlinePlayers()) { + if (this.contains(player)) { + players.add(player); + } + } + return players; + } + + public Location getLowerNE() { + return new Location(this.getWorld(), this.x1, this.y1, this.z1); + } + + public Location getUpperSW() { + return new Location(this.getWorld(), this.x2, this.y2, this.z2); + } + + public Location getCenter() { + final int x1 = this.x2 + 1; + final int y1 = this.y2 + 1; + final int z1 = this.z2 + 1; + return new Location(this.getWorld(), this.x1 + (x1 - this.x1) / 2.0, this.y1 + (y1 - this.y1) / 2.0, + this.z1 + (z1 - this.z1) / 2.0); + } + + public String getWorldName() { + return this.worldName; + } + + public World getWorld() { + return Bukkit.getWorld(this.worldName); + } + + public int getSizeX() { + return this.x2 - this.x1 + 1; + } + + public int getSizeY() { + return this.y2 - this.y1 + 1; + } + + public int getSizeZ() { + return this.z2 - this.z1 + 1; + } + + public int getX1() { + return this.x1; + } + + public void setX1(final int x1) { + this.x1 = x1; + } + + public int getY1() { + return this.y1; + } + + public void setY1(final int y1) { + this.y1 = y1; + } + + public int getZ1() { + return this.z1; + } + + public void setZ1(final int z1) { + this.z1 = z1; + } + + public int getX2() { + return this.x2; + } + + public int getY2() { + return this.y2; + } + + public void setY2(final int y2) { + this.y2 = y2; + } + + public int getZ2() { + return this.z2; + } + + public Location[] getCornerLocations() { + final Location[] result = new Location[8]; + final Block[] cornerBlocks = this.getCornerBlocks(); + for (int i = 0; i < cornerBlocks.length; ++i) { + result[i] = cornerBlocks[i].getLocation(); + } + return result; + } + + public Block[] getCornerBlocks() { + final Block[] result = new Block[8]; + final World world = this.getWorld(); + result[0] = world.getBlockAt(this.x1, this.y1, this.z1); + result[1] = world.getBlockAt(this.x1, this.y1, this.z2); + result[2] = world.getBlockAt(this.x1, this.y2, this.z1); + result[3] = world.getBlockAt(this.x1, this.y2, this.z2); + result[4] = world.getBlockAt(this.x2, this.y1, this.z1); + result[5] = world.getBlockAt(this.x2, this.y1, this.z2); + result[6] = world.getBlockAt(this.x2, this.y2, this.z1); + result[7] = world.getBlockAt(this.x2, this.y2, this.z2); + return result; + } + + public Cuboid shift(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + return this.expand(direction, amount).expand(direction.opposite(), -amount); + } + + public Cuboid inset(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + return this.outset(direction, -amount); + } + + public Cuboid expand(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + switch (direction) { + case NORTH: { + return new Cuboid(this.worldName, this.x1 - amount, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case SOUTH: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2 + amount, this.y2, this.z2); + } + case EAST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1 - amount, this.x2, this.y2, this.z2); + } + case WEST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z2 + amount); + } + case DOWN: { + return new Cuboid(this.worldName, this.x1, this.y1 - amount, this.z1, this.x2, this.y2, this.z2); + } + case UP: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2 + amount, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public Cuboid outset(final CuboidDirection direction, final int amount) throws IllegalArgumentException { + switch (direction) { + case HORIZONTAL: { + return this.expand(CuboidDirection.NORTH, amount).expand(CuboidDirection.SOUTH, amount) + .expand(CuboidDirection.EAST, amount).expand(CuboidDirection.WEST, amount); + } + case VERTICAL: { + return this.expand(CuboidDirection.DOWN, amount).expand(CuboidDirection.UP, amount); + } + case BOTH: { + return this.outset(CuboidDirection.HORIZONTAL, amount).outset(CuboidDirection.VERTICAL, amount); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public boolean contains(final Cuboid cuboid) { + return this.contains(cuboid.getMinimumPoint()) || this.contains(cuboid.getMaximumPoint()); + } + + public boolean contains(final Player player) { + return this.contains(player.getLocation()); + } + + public boolean contains(final World world, final int x, final int z) { + return (world == null || this.getWorld().equals(world)) && x >= this.x1 && x <= this.x2 && z >= this.z1 + && z <= this.z2; + } + + public boolean contains(final int x, final int y, final int z) { + return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; + } + + public boolean contains(final Block block) { + return this.contains(block.getLocation()); + } + + public boolean contains(final Location location) { + if (location == null || this.worldName == null) { + return false; + } + final World world = location.getWorld(); + return world != null && this.worldName.equals(location.getWorld().getName()) + && this.contains(location.getBlockX(), location.getBlockY(), location.getBlockZ()); + } + + public int getVolume() { + return this.getSizeX() * this.getSizeY() * this.getSizeZ(); + } + + public int getArea() { + final Location min = this.getMinimumPoint(); + final Location max = this.getMaximumPoint(); + return (max.getBlockX() - min.getBlockX() + 1) * (max.getBlockZ() - min.getBlockZ() + 1); + } + + public byte getAverageLightLevel() { + long total = 0L; + int count = 0; + for (final Block block : this) { + if (block.isEmpty()) { + total += block.getLightLevel(); + ++count; + } + } + return (count > 0) ? ((byte) (total / count)) : 0; + } + + public Location getMinimumPoint() { + return new Location(this.getWorld(), Math.min(this.x1, this.x2), Math.min(this.y1, this.y2), + Math.min(this.z1, this.z2)); + } + + public Location getMaximumPoint() { + return new Location(this.getWorld(), Math.max(this.x1, this.x2), Math.max(this.y1, this.y2), + Math.max(this.z1, this.z2)); + } + + public int getWidth() { + return this.getMaximumPoint().getBlockX() - this.getMinimumPoint().getBlockX(); + } + + public int getHeight() { + return this.getMaximumPoint().getBlockY() - this.getMinimumPoint().getBlockY(); + } + + public int getLength() { + return this.getMaximumPoint().getBlockZ() - this.getMinimumPoint().getBlockZ(); + } + + public Cuboid contract() { + return this.contract(CuboidDirection.DOWN).contract(CuboidDirection.SOUTH).contract(CuboidDirection.EAST) + .contract(CuboidDirection.UP).contract(CuboidDirection.NORTH).contract(CuboidDirection.WEST); + } + + public Cuboid contract(final CuboidDirection direction) { + Cuboid face = this.getFace(direction.opposite()); + switch (direction) { + case DOWN: { + while (face.containsOnly(Material.AIR) && face.y1 > this.y1) { + face = face.shift(CuboidDirection.DOWN, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, face.y2, this.z2); + } + case UP: { + while (face.containsOnly(Material.AIR) && face.y2 < this.y2) { + face = face.shift(CuboidDirection.UP, 1); + } + return new Cuboid(this.worldName, this.x1, face.y1, this.z1, this.x2, this.y2, this.z2); + } + case NORTH: { + while (face.containsOnly(Material.AIR) && face.x1 > this.x1) { + face = face.shift(CuboidDirection.NORTH, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, face.x2, this.y2, this.z2); + } + case SOUTH: { + while (face.containsOnly(Material.AIR) && face.x2 < this.x2) { + face = face.shift(CuboidDirection.SOUTH, 1); + } + return new Cuboid(this.worldName, face.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case EAST: { + while (face.containsOnly(Material.AIR) && face.z1 > this.z1) { + face = face.shift(CuboidDirection.EAST, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, face.z2); + } + case WEST: { + while (face.containsOnly(Material.AIR) && face.z2 < this.z2) { + face = face.shift(CuboidDirection.WEST, 1); + } + return new Cuboid(this.worldName, this.x1, this.y1, face.z1, this.x2, this.y2, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public Cuboid getFace(final CuboidDirection direction) { + switch (direction) { + case DOWN: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y1, this.z2); + } + case UP: { + return new Cuboid(this.worldName, this.x1, this.y2, this.z1, this.x2, this.y2, this.z2); + } + case NORTH: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x1, this.y2, this.z2); + } + case SOUTH: { + return new Cuboid(this.worldName, this.x2, this.y1, this.z1, this.x2, this.y2, this.z2); + } + case EAST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z1, this.x2, this.y2, this.z1); + } + case WEST: { + return new Cuboid(this.worldName, this.x1, this.y1, this.z2, this.x2, this.y2, this.z2); + } + default: { + throw new IllegalArgumentException("Invalid direction " + direction); + } + } + } + + public boolean containsOnly(final Material material) { + for (final Block block : this) { + if (block.getType() != material) { + return false; + } + } + return true; + } + + public Cuboid getBoundingCuboid(final Cuboid other) { + if (other == null) { + return this; + } + final int xMin = Math.min(this.x1, other.x1); + final int yMin = Math.min(this.y1, other.y1); + final int zMin = Math.min(this.z1, other.z1); + final int xMax = Math.max(this.x2, other.x2); + final int yMax = Math.max(this.y2, other.y2); + final int zMax = Math.max(this.z2, other.z2); + return new Cuboid(this.worldName, xMin, yMin, zMin, xMax, yMax, zMax); + } + + public Block getRelativeBlock(final int x, final int y, final int z) { + return this.getWorld().getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z); + } + + public Block getRelativeBlock(final World world, final int x, final int y, final int z) { + return world.getBlockAt(this.x1 + x, this.y1 + y, this.z1 + z); + } + + public List getChunks() { + final World world = this.getWorld(); + final int x1 = this.x1 & 0xFFFFFFF0; + final int x2 = this.x2 & 0xFFFFFFF0; + final int z1 = this.z1 & 0xFFFFFFF0; + final int z2 = this.z2 & 0xFFFFFFF0; + final List result = new ArrayList(x2 - x1 + 16 + (z2 - z1) * 16); + for (int x3 = x1; x3 <= x2; x3 += 16) { + for (int z3 = z1; z3 <= z2; z3 += 16) { + result.add(world.getChunkAt(x3 >> 4, z3 >> 4)); + } + } + return result; + } + + @Override + public Iterator iterator() { + return new CuboidBlockIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + + public Iterator locationIterator() { + return new CuboidLocationIterator(this.getWorld(), this.x1, this.y1, this.z1, this.x2, this.y2, this.z2); + } + + @Override + public Cuboid clone() { + try { + return (Cuboid) super.clone(); + } catch (CloneNotSupportedException ex) { + throw new RuntimeException("This could never happen", ex); + } + } + + @Override + public String toString() { + return "Cuboid: " + this.worldName + ',' + this.x1 + ',' + this.y1 + ',' + this.z1 + "=>" + this.x2 + ',' + + this.y2 + ',' + this.z2; + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java b/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java new file mode 100644 index 0000000..613edec --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidBlockIterator.java @@ -0,0 +1,56 @@ +package LorexMC.us.utils.other.cuboid; + +import java.util.*; +import org.bukkit.block.*; +import org.bukkit.*; + +public class CuboidBlockIterator implements Iterator { + private final World world; + private final int baseX; + private final int baseY; + private final int baseZ; + private final int sizeX; + private final int sizeY; + private final int sizeZ; + private int x; + private int y; + private int z; + + public CuboidBlockIterator(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + this.world = world; + this.baseX = x1; + this.baseY = y1; + this.baseZ = z1; + this.sizeX = Math.abs(x2 - x1) + 1; + this.sizeY = Math.abs(y2 - y1) + 1; + this.sizeZ = Math.abs(z2 - z1) + 1; + final boolean x3 = false; + this.z = (x3 ? 1 : 0); + this.y = (x3 ? 1 : 0); + this.x = (x3 ? 1 : 0); + } + + @Override + public boolean hasNext() { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ; + } + + @Override + public Block next() { + final Block block = this.world.getBlockAt(this.baseX + this.x, this.baseY + this.y, this.baseZ + this.z); + if (++this.x >= this.sizeX) { + this.x = 0; + if (++this.y >= this.sizeY) { + this.y = 0; + ++this.z; + } + } + return block; + } + + @Override + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java b/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java new file mode 100644 index 0000000..3e6d234 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidDirection.java @@ -0,0 +1,68 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.block.*; + +public enum CuboidDirection { + NORTH, EAST, SOUTH, WEST, UP, DOWN, HORIZONTAL, VERTICAL, BOTH, UNKNOWN; + + public CuboidDirection opposite() { + switch (this) { + case NORTH: { + return CuboidDirection.SOUTH; + } + case EAST: { + return CuboidDirection.WEST; + } + case SOUTH: { + return CuboidDirection.NORTH; + } + case WEST: { + return CuboidDirection.EAST; + } + case HORIZONTAL: { + return CuboidDirection.VERTICAL; + } + case VERTICAL: { + return CuboidDirection.HORIZONTAL; + } + case UP: { + return CuboidDirection.DOWN; + } + case DOWN: { + return CuboidDirection.UP; + } + case BOTH: { + return CuboidDirection.BOTH; + } + default: { + return CuboidDirection.UNKNOWN; + } + } + } + + public BlockFace toBukkitDirection() { + switch (this) { + case NORTH: { + return BlockFace.NORTH; + } + case EAST: { + return BlockFace.EAST; + } + case SOUTH: { + return BlockFace.SOUTH; + } + case WEST: { + return BlockFace.WEST; + } + case UP: { + return BlockFace.UP; + } + case DOWN: { + return BlockFace.DOWN; + } + default: { + return null; + } + } + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java b/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java new file mode 100644 index 0000000..d838803 --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/CuboidLocationIterator.java @@ -0,0 +1,56 @@ +package LorexMC.us.utils.other.cuboid; + +import java.util.*; +import org.bukkit.*; + +public class CuboidLocationIterator implements Iterator { + private final World world; + private final int baseX; + private final int baseY; + private final int baseZ; + private final int sizeX; + private final int sizeY; + private final int sizeZ; + private int x; + private int y; + private int z; + + public CuboidLocationIterator(final World world, final int x1, final int y1, final int z1, final int x2, + final int y2, final int z2) { + this.world = world; + this.baseX = x1; + this.baseY = y1; + this.baseZ = z1; + this.sizeX = Math.abs(x2 - x1) + 1; + this.sizeY = Math.abs(y2 - y1) + 1; + this.sizeZ = Math.abs(z2 - z1) + 1; + final boolean x3 = false; + this.z = (x3 ? 1 : 0); + this.y = (x3 ? 1 : 0); + this.x = (x3 ? 1 : 0); + } + + @Override + public boolean hasNext() { + return this.x < this.sizeX && this.y < this.sizeY && this.z < this.sizeZ; + } + + @Override + public Location next() { + final Location location = new Location(this.world, this.baseX + this.x, this.baseY + this.y, + this.baseZ + this.z); + if (++this.x >= this.sizeX) { + this.x = 0; + if (++this.y >= this.sizeY) { + this.y = 0; + ++this.z; + } + } + return location; + } + + @Override + public void remove() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } +} diff --git a/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java b/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java new file mode 100644 index 0000000..e1e892f --- /dev/null +++ b/src/LorexMC/us/utils/other/cuboid/NamedCuboid.java @@ -0,0 +1,57 @@ +package LorexMC.us.utils.other.cuboid; + +import org.bukkit.*; + +import java.util.*; + +public class NamedCuboid extends Cuboid { + protected String name; + + public NamedCuboid(final Cuboid other) { + super(other.getWorld(), other.x1, other.y1, other.z1, other.x2, other.y2, other.z2); + } + + public NamedCuboid(final World world, final int x1, final int y1, final int z1, final int x2, final int y2, + final int z2) { + super(world, x1, y1, z1, x2, y2, z2); + } + + public NamedCuboid(final Location location) { + super(location, location); + } + + public NamedCuboid(final Location first, final Location second) { + super(first, second); + } + + public NamedCuboid(final Map map) { + super(map); + this.name = (String) map.get("name"); + } + + @Override + public Map serialize() { + final Map map = super.serialize(); + map.put("name", this.name); + return map; + } + + public String getName() { + return this.name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public NamedCuboid clone() { + return (NamedCuboid) super.clone(); + } + + @Override + public String toString() { + return "NamedCuboid: " + this.worldName + ',' + this.x1 + ',' + this.y1 + ',' + this.z1 + "=>" + this.x2 + ',' + + this.y2 + ',' + this.z2 + ':' + this.name; + } +} diff --git a/src/LorexMC/us/utils/other/imagemessage/ImageChar.java b/src/LorexMC/us/utils/other/imagemessage/ImageChar.java new file mode 100644 index 0000000..0eeb7c5 --- /dev/null +++ b/src/LorexMC/us/utils/other/imagemessage/ImageChar.java @@ -0,0 +1,15 @@ +package LorexMC.us.utils.other.imagemessage; + +public enum ImageChar { + BLOCK('\u2588'), DARK_SHADE('\u2593'), MEDIUM_SHADE('\u2592'), LIGHT_SHADE('\u2591'); + + private final char character; + + private ImageChar(final char character) { + this.character = character; + } + + public char getChar() { + return this.character; + } +} diff --git a/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java b/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java new file mode 100644 index 0000000..02c7f38 --- /dev/null +++ b/src/LorexMC/us/utils/other/imagemessage/ImageMessage.java @@ -0,0 +1,182 @@ +package LorexMC.us.utils.other.imagemessage; + +import java.awt.Color; + +import com.google.common.base.*; + +import org.bukkit.*; + +import java.net.*; + +import javax.imageio.*; + +import java.io.*; +import java.awt.geom.*; +import java.awt.image.*; + +import org.bukkit.craftbukkit.libs.joptsimple.internal.Strings; + +import java.util.*; + +import org.bukkit.entity.*; + +public final class ImageMessage { + private static final char TRANSPARENT_CHAR = ' '; + private final String[] lines; + private static final Color[] colors; + + private ImageMessage(final String... lines) throws IllegalArgumentException { + Preconditions.checkNotNull((Object) lines, (Object) "Lines cannot be null"); + this.lines = lines; + } + + private ImageMessage(final BufferedImage image, final int height, final char imageCharacter) + throws IllegalArgumentException { + this(toImageMessage(toColourArray(image, height), imageCharacter)); + } + + public static ImageMessage newInstance(final BufferedImage image, final int height, final char imageCharacter) + throws IllegalArgumentException { + Preconditions.checkNotNull((Object) image, (Object) "Image cannot be null"); + Preconditions.checkArgument(height >= 0, "Height must be positive"); + return new ImageMessage(image, height, imageCharacter); + } + + public static ImageMessage newInstance(final ChatColor[][] chatColors, final char imageCharacter) { + return new ImageMessage(toImageMessage(chatColors, imageCharacter)); + } + + public static ImageMessage newInstance(final String url, final int height, final char imageCharacter) + throws IllegalArgumentException { + Preconditions.checkNotNull((Object) url, (Object) "Image URL cannot be null"); + Preconditions.checkArgument(height >= 0, "Height must be positive"); + try { + return newInstance(ImageIO.read(new URL(url)), height, imageCharacter); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); + } + } + + public static ImageMessage newInstance(final String fileName, final File folder, final int height, + final char imageCharacter) throws IllegalArgumentException { + Preconditions.checkNotNull((Object) fileName, (Object) "File name cannot be null"); + Preconditions.checkNotNull((Object) folder, (Object) "Folder cannot be null"); + try { + return newInstance(ImageIO.read(new File(folder, fileName)), height, imageCharacter); + } catch (IOException ex) { + throw new IllegalArgumentException(ex); + } + } + + public ImageMessage appendText(final String... text) { + for (int i = 0; i < Math.min(text.length, this.lines.length); ++i) { + final StringBuilder sb = new StringBuilder(); + final String[] lines = this.lines; + final int n = i; + lines[n] = sb.append(lines[n]).append(' ').append(text[i]).toString(); + } + return this; + } + + public ImageMessage appendCenteredText(final String... text) { + for (int i = 0; i < Math.min(text.length, this.lines.length); ++i) { + final String line = this.lines[i]; + this.lines[i] = line + this.center(text[i], 65 - line.length()); + } + return this; + } + + private static ChatColor[][] toColourArray(final BufferedImage image, final int height) { + final double ratio = image.getHeight() / image.getWidth(); + final BufferedImage resizedImage = resizeImage(image, (int) (height / ratio), height); + final ChatColor[][] chatImage = new ChatColor[resizedImage.getWidth()][resizedImage.getHeight()]; + for (int x = 0; x < resizedImage.getWidth(); ++x) { + for (int y = 0; y < resizedImage.getHeight(); ++y) { + final ChatColor closest = getClosestChatColor(new Color(resizedImage.getRGB(x, y), true)); + chatImage[x][y] = closest; + } + } + return chatImage; + } + + private static String[] toImageMessage(final ChatColor[][] colors, final char imageCharacter) { + final String[] results = new String[colors[0].length]; + for (int i = 0; i < colors[0].length; ++i) { + final StringBuilder line = new StringBuilder(); + for (final ChatColor[] color : colors) { + final ChatColor current = color[i]; + line.append((current != null) ? (current.toString() + imageCharacter) : ImageMessage.TRANSPARENT_CHAR); + } + results[i] = line.toString() + ChatColor.RESET; + } + return results; + } + + private static BufferedImage resizeImage(final BufferedImage image, final int width, final int height) { + final AffineTransform transform = new AffineTransform(); + transform.scale(width / image.getWidth(), height / image.getHeight()); + return new AffineTransformOp(transform, 1).filter(image, null); + } + + private static double getDistance(final Color c1, final Color c2) { + final int red = c1.getRed() - c2.getRed(); + final int green = c1.getGreen() - c2.getGreen(); + final int blue = c1.getBlue() - c2.getBlue(); + final double redMean = (c1.getRed() + c2.getRed()) / 2.0; + final double weightRed = 2.0 + redMean / 256.0; + final double weightGreen = 4.0; + final double weightBlue = 2.0 + (255.0 - redMean) / 256.0; + return weightRed * red * red + weightGreen * green * green + weightBlue * blue * blue; + } + + private static boolean areIdentical(final Color c1, final Color c2) { + return Math.abs(c1.getRed() - c2.getRed()) <= 5 && Math.abs(c1.getGreen() - c2.getGreen()) <= 5 + && Math.abs(c1.getBlue() - c2.getBlue()) <= 5; + } + + private static ChatColor getClosestChatColor(final Color color) { + if (color.getAlpha() < 128) { + return null; + } + for (int i = 0; i < ImageMessage.colors.length; ++i) { + if (areIdentical(ImageMessage.colors[i], color)) { + return ChatColor.values()[i]; + } + } + int index = 0; + double best = -1.0; + for (int j = 0; j < ImageMessage.colors.length; ++j) { + final double distance = getDistance(color, ImageMessage.colors[j]); + if (distance < best || best == -1.0) { + best = distance; + index = j; + } + } + return ChatColor.values()[index]; + } + + private String center(final String string, final int length) { + if (string.length() > length) { + return string.substring(0, length); + } + if (string.length() == length) { + return string; + } + return Strings.repeat(' ', (length - string.length()) / 2) + string; + } + + public String[] getLines() { + return Arrays.copyOf(this.lines, this.lines.length); + } + + public void sendToPlayer(final Player player) { + player.sendMessage(this.lines); + } + + static { + colors = new Color[] { new Color(0, 0, 0), new Color(0, 0, 170), new Color(0, 170, 0), new Color(0, 170, 170), + new Color(170, 0, 0), new Color(170, 0, 170), new Color(255, 170, 0), new Color(170, 170, 170), + new Color(85, 85, 85), new Color(85, 85, 255), new Color(85, 255, 85), new Color(85, 255, 255), + new Color(255, 85, 85), new Color(255, 85, 255), new Color(255, 255, 85), new Color(255, 255, 255) }; + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/ItemData.java b/src/LorexMC/us/utils/other/itemdb/ItemData.java new file mode 100644 index 0000000..026f1f8 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ItemData.java @@ -0,0 +1,106 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.configuration.serialization.*; +import org.bukkit.*; +import org.bukkit.material.*; + +import LorexMC.us.utils.internal.com.bruce.base.*; + +import org.bukkit.inventory.*; +import java.util.*; + +public class ItemData implements ConfigurationSerializable { + private final Material material; + private final short itemData; + + public ItemData(final MaterialData data) { + this(data.getItemType(), data.getData()); + } + + public ItemData(final ItemStack stack) { + this(stack.getType(), stack.getData().getData()); + } + + public ItemData(final Material material, final short itemData) { + this.material = material; + this.itemData = itemData; + } + + public ItemData(final Map map) { + Object object = map.get("itemType"); + if (!(object instanceof String)) { + throw new AssertionError("Incorrectly configurised"); + } + this.material = Material.getMaterial((String) object); + if ((object = map.get("itemData")) instanceof Short) { + this.itemData = (short) object; + return; + } + throw new AssertionError("Incorrectly configurised"); + } + + @Override + public Map serialize() { + final Map map = new LinkedHashMap(); + map.put("itemType", this.material.name()); + map.put("itemData", this.itemData); + return map; + } + + public Material getMaterial() { + return this.material; + } + + @Deprecated + public short getItemData() { + return this.itemData; + } + + public String getItemName() { + return BasePlugin.getPlugin().getItemDb().getName(new ItemStack(this.material, 1, this.itemData)); + } + + public static ItemData fromItemName(final String string) { + final ItemStack stack = BasePlugin.getPlugin().getItemDb().getItem(string); + return new ItemData(stack.getType(), stack.getData().getData()); + } + + public static ItemData fromStringValue(final String value) { + final int firstBracketIndex = value.indexOf(40); + if (firstBracketIndex == -1) { + return null; + } + final int otherBracketIndex = value.indexOf(41); + if (otherBracketIndex == -1) { + return null; + } + final String itemName = value.substring(0, firstBracketIndex); + final String itemData = value.substring(firstBracketIndex + 1, otherBracketIndex); + final Material material = Material.getMaterial(itemName); + return new ItemData(material, Short.parseShort(itemData)); + } + + @Override + public String toString() { + return String.valueOf(this.material.name()) + "(" + String.valueOf(this.itemData) + ")"; + } + + @Override + public boolean equals(final Object o) { + if (this == o) { + return true; + } + if (o == null || this.getClass() != o.getClass()) { + return false; + } + final ItemData itemData1 = (ItemData) o; + return this.itemData == itemData1.itemData && this.material == itemData1.material; + } + + @Override + public int hashCode() { + int result = (this.material != null) ? this.material.hashCode() : 0; + result = 31 * result + this.itemData; + return result; + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/ItemDb.java b/src/LorexMC/us/utils/other/itemdb/ItemDb.java new file mode 100644 index 0000000..e39a89c --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ItemDb.java @@ -0,0 +1,26 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.inventory.*; +import org.bukkit.entity.*; +import java.util.*; + +public interface ItemDb { + void reloadItemDatabase(); + + ItemStack getPotion(final String p0); + + ItemStack getPotion(final String p0, final int p1); + + ItemStack getItem(final String p0); + + ItemStack getItem(final String p0, final int p1); + + String getName(final ItemStack p0); + + @Deprecated + String getPrimaryName(final ItemStack p0); + + String getNames(final ItemStack p0); + + List getMatching(final Player p0, final String[] p1); +} diff --git a/src/LorexMC/us/utils/other/itemdb/ManagedFile.java b/src/LorexMC/us/utils/other/itemdb/ManagedFile.java new file mode 100644 index 0000000..e8f5f53 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/ManagedFile.java @@ -0,0 +1,76 @@ +package LorexMC.us.utils.other.itemdb; + +import org.bukkit.plugin.java.*; + +import LorexMC.us.utils.internal.com.bruce.base.*; + +import java.util.logging.*; +import java.nio.charset.*; +import java.math.*; +import java.security.*; +import java.nio.file.*; +import java.util.*; +import java.io.*; + +public class ManagedFile { + private static final int BUFFER_SIZE = 8192; + private final transient File file; + + public ManagedFile(final String filename, final JavaPlugin plugin) { + this.file = new File(plugin.getDataFolder(), filename); + if (!this.file.exists()) { + try { + copyResourceAscii('/' + filename, this.file); + } catch (IOException ex) { + plugin.getLogger().log(Level.SEVERE, "items.csv has not been loaded", ex); + } + } + } + + public File getFile() { + return this.file; + } + + public static void copyResourceAscii(final String resourceName, final File file) throws IOException { + try (final InputStreamReader reader = new InputStreamReader(ManagedFile.class.getResourceAsStream(resourceName), + StandardCharsets.UTF_8)) { + final MessageDigest digest = getDigest(); + try (final DigestOutputStream digestStream = new DigestOutputStream(new FileOutputStream(file), digest); + final OutputStreamWriter writer = new OutputStreamWriter(digestStream, StandardCharsets.UTF_8)) { + final char[] buffer = new char[8192]; + int length; + while ((length = reader.read(buffer)) >= 0) { + writer.write(buffer, 0, length); + } + writer.write("\n"); + writer.flush(); + digestStream.on(false); + digestStream.write(35); + digestStream.write(new BigInteger(1, digest.digest()).toString(16).getBytes(StandardCharsets.UTF_8)); + } + } + } + + public static MessageDigest getDigest() throws IOException { + try { + return MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException ex) { + throw new IOException(ex); + } + } + + public List getLines() { + try (final BufferedReader reader = Files.newBufferedReader(Paths.get(this.file.getPath(), new String[0]), + StandardCharsets.UTF_8)) { + final List lines = new ArrayList(); + String line; + while ((line = reader.readLine()) != null) { + lines.add(line); + } + return lines; + } catch (IOException ex) { + BasePlugin.getPlugin().getJavaPlugin().getLogger().log(Level.SEVERE, ex.getMessage(), ex); + return Collections.emptyList(); + } + } +} diff --git a/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java b/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java new file mode 100644 index 0000000..84d4066 --- /dev/null +++ b/src/LorexMC/us/utils/other/itemdb/SimpleItemDb.java @@ -0,0 +1,317 @@ +package LorexMC.us.utils.other.itemdb; + +import gnu.trove.map.*; +import org.bukkit.plugin.java.*; + +import com.google.common.collect.*; + +import LorexMC.us.utils.JavaUtils; +import gnu.trove.map.hash.*; + +import org.bukkit.potion.*; +import org.bukkit.*; +import java.util.regex.*; +import org.bukkit.entity.*; +import org.bukkit.inventory.*; +import org.bukkit.craftbukkit.v1_7_R4.inventory.*; +import java.util.*; +import org.apache.commons.lang3.*; + +public class SimpleItemDb implements ItemDb { + private static final Comparator STRING_LENGTH_COMPARATOR; + private final TObjectIntMap items; + private final TreeMultimap names; + private final Map primaryName; + private final TObjectShortMap durabilities; + private final ManagedFile file; + private final Pattern splitPattern; + private static final Pattern PARTS_PATTERN; + + public SimpleItemDb(final JavaPlugin plugin) { + this.items = new TObjectIntHashMap(); + this.names = TreeMultimap.create((Comparator) Ordering.arbitrary(), + (Comparator) SimpleItemDb.STRING_LENGTH_COMPARATOR); + this.primaryName = new HashMap(); + this.durabilities = new TObjectShortHashMap(); + this.splitPattern = Pattern.compile("((.*)[:+',;.](\\d+))"); + this.file = new ManagedFile("items.csv", plugin); + this.reloadItemDatabase(); + } + + @Override + public void reloadItemDatabase() { + if (this.file.getFile() == null) { + return; + } + final List lines = this.file.getLines(); + if (lines.isEmpty()) { + return; + } + this.durabilities.clear(); + this.items.clear(); + this.names.clear(); + this.primaryName.clear(); + for (String line : lines) { + line = line.trim().toLowerCase(Locale.ENGLISH); + if (line.length() > 0 && line.charAt(0) == '#') { + continue; + } + final String[] parts = SimpleItemDb.PARTS_PATTERN.split(line); + if (parts.length < 2) { + continue; + } + Material material; + try { + final int numeric = Integer.parseInt(parts[1]); + material = Material.getMaterial(numeric); + } catch (IllegalArgumentException ex) { + material = Material.getMaterial(parts[1]); + } + final short data = (parts.length > 2 && !parts[2].equals("0")) ? Short.parseShort(parts[2]) : 0; + final String itemName = parts[0].toLowerCase(Locale.ENGLISH); + this.durabilities.put(itemName, data); + this.items.put(itemName, material.getId()); + final ItemData itemData = new ItemData(material, data); + if (this.names.containsKey(itemData)) { + this.names.get(itemData).add(itemName); + } else { + this.names.put(itemData, itemName); + this.primaryName.put(itemData, itemName); + } + } + } + + @Override + public ItemStack getPotion(final String id) { + return this.getPotion(id, 1); + } + + @Override + public ItemStack getPotion(String id, final int quantity) { + int length = id.length(); + if (length <= 1) { + return null; + } + boolean splash = false; + if (length > 1 && id.endsWith("s")) { + id = id.substring(0, --length); + splash = true; + if (length <= 1) { + return null; + } + } + boolean extended = false; + if (id.endsWith("e")) { + id = id.substring(0, --length); + extended = true; + if (length <= 1) { + return null; + } + } + final Integer level = JavaUtils.tryParseInt(id.substring(length - 1, length)); + id = id.substring(0, --length); + final String lowerCase = id.toLowerCase(Locale.ENGLISH); + PotionType type = null; + switch (lowerCase) { + case "hp": { + type = PotionType.FIRE_RESISTANCE; + break; + } + case "rp": { + type = PotionType.REGEN; + break; + } + case "dp": { + type = PotionType.INSTANT_DAMAGE; + break; + } + case "swp": { + type = PotionType.SPEED; + break; + } + case "slp": { + type = PotionType.SLOWNESS; + break; + } + case "strp": { + type = PotionType.STRENGTH; + break; + } + case "wp": { + type = PotionType.WEAKNESS; + break; + } + case "pp": { + type = PotionType.POISON; + break; + } + case "frp": { + type = PotionType.FIRE_RESISTANCE; + break; + } + case "invp": { + type = PotionType.INVISIBILITY; + break; + } + case "nvp": { + type = PotionType.NIGHT_VISION; + break; + } + default: { + return null; + } + } + if (level == null || level > type.getMaxLevel()) { + return null; + } + final Potion potion = new Potion(type); + potion.setLevel(level); + potion.setSplash(splash); + potion.setHasExtendedDuration(extended); + final ItemStack result = potion.toItemStack(quantity); + result.setDurability((short) (result.getDurability() + 8192)); + return result; + } + + @Override + public ItemStack getItem(final String id) { + final ItemStack result = this.getItem(id, 1); + if (result == null) { + return null; + } + result.setAmount(result.getMaxStackSize()); + return result; + } + + @Override + public ItemStack getItem(final String id, final int quantity) { + ItemStack result = this.getPotion(id, quantity); + if (result != null) { + return result; + } + int itemId = 0; + short metaData = 0; + final Matcher parts = this.splitPattern.matcher(id); + String itemName; + if (parts.matches()) { + itemName = parts.group(2); + metaData = Short.parseShort(parts.group(3)); + } else { + itemName = id; + } + Integer last; + if ((last = JavaUtils.tryParseInt(itemName)) != null) { + itemId = last; + } else if ((last = JavaUtils.tryParseInt(id)) != null) { + itemId = last; + } else { + itemName = itemName.toLowerCase(Locale.ENGLISH); + } + if (itemId < 1) { + if (this.items.containsKey(itemName)) { + itemId = this.items.get(itemName); + if (this.durabilities.containsKey(itemName) && metaData == 0) { + metaData = this.durabilities.get(itemName); + } + } else if (Material.getMaterial(itemName.toUpperCase(Locale.ENGLISH)) != null) { + final Material bMaterial = Material.getMaterial(itemName.toUpperCase(Locale.ENGLISH)); + itemId = bMaterial.getId(); + } else { + try { + final Material bMaterial = Bukkit.getUnsafe() + .getMaterialFromInternalName(itemName.toLowerCase(Locale.ENGLISH)); + itemId = bMaterial.getId(); + } catch (Exception ex) { + return null; + } + } + } + if (itemId < 1) { + return null; + } + final Material mat = Material.getMaterial(itemId); + if (mat == null) { + return null; + } + result = new ItemStack(mat); + result.setAmount(quantity); + result.setDurability(metaData); + return result; + } + + @Override + public List getMatching(final Player player, final String[] args) { + final List items = new ArrayList(); + final PlayerInventory inventory = player.getInventory(); + if (args.length < 1 || args[0].equalsIgnoreCase("hand")) { + items.add(player.getItemInHand()); + } else if (args[0].equalsIgnoreCase("inventory") || args[0].equalsIgnoreCase("invent") + || args[0].equalsIgnoreCase("all")) { + for (final ItemStack stack : inventory.getContents()) { + if (stack != null && stack.getType() != Material.AIR) { + items.add(stack); + } + } + } else if (args[0].equalsIgnoreCase("blocks")) { + for (final ItemStack stack : inventory.getContents()) { + if (stack != null && stack.getType() != Material.AIR && stack.getType().isBlock()) { + items.add(stack); + } + } + } else { + items.add(this.getItem(args[0])); + } + if (items.isEmpty() || items.get(0).getType() == Material.AIR) { + return null; + } + return items; + } + + @Override + public String getName(final ItemStack item) { + return CraftItemStack.asNMSCopy(item).getName(); + } + + @Deprecated + @Override + public String getPrimaryName(final ItemStack item) { + ItemData itemData = new ItemData(item.getType(), item.getDurability()); + String name = this.primaryName.get(itemData); + if (name == null) { + itemData = new ItemData(item.getType(), (short) 0); + name = this.primaryName.get(itemData); + if (name == null) { + return null; + } + } + return name; + } + + @Override + public String getNames(final ItemStack item) { + ItemData itemData = new ItemData(item.getType(), item.getDurability()); + Collection nameList = this.names.get(itemData); + if (nameList == null) { + itemData = new ItemData(item.getType(), (short) 0); + nameList = this.names.get(itemData); + if (nameList == null) { + return null; + } + } + List list = new ArrayList(nameList); + if (nameList.size() > 15) { + list = list.subList(0, 14); + } + return StringUtils.join(list, ", "); + } + + static { + STRING_LENGTH_COMPARATOR = new Comparator() { + @Override + public int compare(final String o1, final String o2) { + return o1.length() - o2.length(); + } + }; + PARTS_PATTERN = Pattern.compile("[^a-z0-9]"); + } +} diff --git a/src/gnu/trove/TByteCollection.java b/src/gnu/trove/TByteCollection.java new file mode 100644 index 0000000..036aba6 --- /dev/null +++ b/src/gnu/trove/TByteCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TByteIterator; +import gnu.trove.procedure.TByteProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TByteCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + byte getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an byte value + * @return true if the collection contains the specified element. + */ + boolean contains(byte entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TByteIterator value + */ + TByteIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + byte[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an byte[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + byte[] toArray(byte[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a byte value + * @return true if the collection was modified by the add operation + */ + boolean add(byte entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an byte value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(byte entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TByteCollection are present. + * + * @param collection + * a TByteCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TByteCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of byte primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(byte[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TByteCollection to the collection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TByteCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of byte primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(byte[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TByteCollection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TByteCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of byte primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(byte[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TByteCollection from the collection. + * + * @param collection + * a TByteCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TByteCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of byte primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(byte[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TByteCollection diff --git a/src/gnu/trove/TCharCollection.java b/src/gnu/trove/TCharCollection.java new file mode 100644 index 0000000..7cfd3eb --- /dev/null +++ b/src/gnu/trove/TCharCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TCharIterator; +import gnu.trove.procedure.TCharProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TCharCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + char getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an char value + * @return true if the collection contains the specified element. + */ + boolean contains(char entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TCharIterator value + */ + TCharIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + char[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an char[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + char[] toArray(char[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a char value + * @return true if the collection was modified by the add operation + */ + boolean add(char entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an char value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(char entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TCharCollection are present. + * + * @param collection + * a TCharCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TCharCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of char primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(char[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TCharCollection to the collection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TCharCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of char primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(char[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TCharCollection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TCharCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of char primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(char[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TCharCollection from the collection. + * + * @param collection + * a TCharCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TCharCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of char primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(char[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TCharCollection diff --git a/src/gnu/trove/TCollections.java b/src/gnu/trove/TCollections.java new file mode 100644 index 0000000..8d5cff2 --- /dev/null +++ b/src/gnu/trove/TCollections.java @@ -0,0 +1,4620 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.set.*; +import gnu.trove.list.*; +import gnu.trove.map.*; +import gnu.trove.impl.unmodifiable.*; +import gnu.trove.impl.sync.*; + +import java.util.RandomAccess; + +/** + * Trove equivalent of the {@link java.util.Collections} class. + */ +@SuppressWarnings({ "UnusedDeclaration" }) +public class TCollections { + + // Disallow creation of instances of this class + private TCollections() { + } + + /////////////////////////// + // TUnmodifiableCollections + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TDoubleCollection unmodifiableCollection(TDoubleCollection c) { + return new TUnmodifiableDoubleCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TFloatCollection unmodifiableCollection(TFloatCollection c) { + return new TUnmodifiableFloatCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TIntCollection unmodifiableCollection(TIntCollection c) { + return new TUnmodifiableIntCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TLongCollection unmodifiableCollection(TLongCollection c) { + return new TUnmodifiableLongCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TByteCollection unmodifiableCollection(TByteCollection c) { + return new TUnmodifiableByteCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TShortCollection unmodifiableCollection(TShortCollection c) { + return new TUnmodifiableShortCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive collection. + * This method allows modules to provide users with "read-only" access to + * internal collections. Query operations on the returned collection "read + * through" to the specified collection, and attempts to modify the returned + * collection, whether direct or via its iterator, result in an + * UnsupportedOperationException. + *

+ * + * The returned collection does not pass the hashCode and equals + * operations through to the backing collection, but relies on Object's + * equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive collection. + */ + public static TCharCollection unmodifiableCollection(TCharCollection c) { + return new TUnmodifiableCharCollection(c); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TDoubleSet unmodifiableSet(TDoubleSet s) { + return new TUnmodifiableDoubleSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TFloatSet unmodifiableSet(TFloatSet s) { + return new TUnmodifiableFloatSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TIntSet unmodifiableSet(TIntSet s) { + return new TUnmodifiableIntSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TLongSet unmodifiableSet(TLongSet s) { + return new TUnmodifiableLongSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TByteSet unmodifiableSet(TByteSet s) { + return new TUnmodifiableByteSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TShortSet unmodifiableSet(TShortSet s) { + return new TUnmodifiableShortSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive set. This + * method allows modules to provide users with "read-only" access to internal + * sets. Query operations on the returned set "read through" to the specified + * set, and attempts to modify the returned set, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive set. + */ + public static TCharSet unmodifiableSet(TCharSet s) { + return new TUnmodifiableCharSet(s); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TDoubleList unmodifiableList(TDoubleList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessDoubleList(list) + : new TUnmodifiableDoubleList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TFloatList unmodifiableList(TFloatList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessFloatList(list) + : new TUnmodifiableFloatList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TIntList unmodifiableList(TIntList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessIntList(list) + : new TUnmodifiableIntList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TLongList unmodifiableList(TLongList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessLongList(list) + : new TUnmodifiableLongList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TByteList unmodifiableList(TByteList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessByteList(list) + : new TUnmodifiableByteList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TShortList unmodifiableList(TShortList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessShortList(list) + : new TUnmodifiableShortList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive list. This + * method allows modules to provide users with "read-only" access to internal + * lists. Query operations on the returned list "read through" to the specified + * list, and attempts to modify the returned list, whether direct or via its + * iterator, result in an UnsupportedOperationException. + *

+ * + * The returned list will be serializable if the specified list is serializable. + * Similarly, the returned list will implement {@link RandomAccess} if the + * specified list does. + * + * @param list + * the list for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive list. + */ + public static TCharList unmodifiableList(TCharList list) { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessCharList(list) + : new TUnmodifiableCharList(list)); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleDoubleMap unmodifiableMap(TDoubleDoubleMap m) { + return new TUnmodifiableDoubleDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleFloatMap unmodifiableMap(TDoubleFloatMap m) { + return new TUnmodifiableDoubleFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleIntMap unmodifiableMap(TDoubleIntMap m) { + return new TUnmodifiableDoubleIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleLongMap unmodifiableMap(TDoubleLongMap m) { + return new TUnmodifiableDoubleLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleByteMap unmodifiableMap(TDoubleByteMap m) { + return new TUnmodifiableDoubleByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleShortMap unmodifiableMap(TDoubleShortMap m) { + return new TUnmodifiableDoubleShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleCharMap unmodifiableMap(TDoubleCharMap m) { + return new TUnmodifiableDoubleCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatDoubleMap unmodifiableMap(TFloatDoubleMap m) { + return new TUnmodifiableFloatDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatFloatMap unmodifiableMap(TFloatFloatMap m) { + return new TUnmodifiableFloatFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatIntMap unmodifiableMap(TFloatIntMap m) { + return new TUnmodifiableFloatIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatLongMap unmodifiableMap(TFloatLongMap m) { + return new TUnmodifiableFloatLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatByteMap unmodifiableMap(TFloatByteMap m) { + return new TUnmodifiableFloatByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatShortMap unmodifiableMap(TFloatShortMap m) { + return new TUnmodifiableFloatShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatCharMap unmodifiableMap(TFloatCharMap m) { + return new TUnmodifiableFloatCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntDoubleMap unmodifiableMap(TIntDoubleMap m) { + return new TUnmodifiableIntDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntFloatMap unmodifiableMap(TIntFloatMap m) { + return new TUnmodifiableIntFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntIntMap unmodifiableMap(TIntIntMap m) { + return new TUnmodifiableIntIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntLongMap unmodifiableMap(TIntLongMap m) { + return new TUnmodifiableIntLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntByteMap unmodifiableMap(TIntByteMap m) { + return new TUnmodifiableIntByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntShortMap unmodifiableMap(TIntShortMap m) { + return new TUnmodifiableIntShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntCharMap unmodifiableMap(TIntCharMap m) { + return new TUnmodifiableIntCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongDoubleMap unmodifiableMap(TLongDoubleMap m) { + return new TUnmodifiableLongDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongFloatMap unmodifiableMap(TLongFloatMap m) { + return new TUnmodifiableLongFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongIntMap unmodifiableMap(TLongIntMap m) { + return new TUnmodifiableLongIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongLongMap unmodifiableMap(TLongLongMap m) { + return new TUnmodifiableLongLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongByteMap unmodifiableMap(TLongByteMap m) { + return new TUnmodifiableLongByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongShortMap unmodifiableMap(TLongShortMap m) { + return new TUnmodifiableLongShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongCharMap unmodifiableMap(TLongCharMap m) { + return new TUnmodifiableLongCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteDoubleMap unmodifiableMap(TByteDoubleMap m) { + return new TUnmodifiableByteDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteFloatMap unmodifiableMap(TByteFloatMap m) { + return new TUnmodifiableByteFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteIntMap unmodifiableMap(TByteIntMap m) { + return new TUnmodifiableByteIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteLongMap unmodifiableMap(TByteLongMap m) { + return new TUnmodifiableByteLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteByteMap unmodifiableMap(TByteByteMap m) { + return new TUnmodifiableByteByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteShortMap unmodifiableMap(TByteShortMap m) { + return new TUnmodifiableByteShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteCharMap unmodifiableMap(TByteCharMap m) { + return new TUnmodifiableByteCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortDoubleMap unmodifiableMap(TShortDoubleMap m) { + return new TUnmodifiableShortDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortFloatMap unmodifiableMap(TShortFloatMap m) { + return new TUnmodifiableShortFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortIntMap unmodifiableMap(TShortIntMap m) { + return new TUnmodifiableShortIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortLongMap unmodifiableMap(TShortLongMap m) { + return new TUnmodifiableShortLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortByteMap unmodifiableMap(TShortByteMap m) { + return new TUnmodifiableShortByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortShortMap unmodifiableMap(TShortShortMap m) { + return new TUnmodifiableShortShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortCharMap unmodifiableMap(TShortCharMap m) { + return new TUnmodifiableShortCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharDoubleMap unmodifiableMap(TCharDoubleMap m) { + return new TUnmodifiableCharDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharFloatMap unmodifiableMap(TCharFloatMap m) { + return new TUnmodifiableCharFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharIntMap unmodifiableMap(TCharIntMap m) { + return new TUnmodifiableCharIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharLongMap unmodifiableMap(TCharLongMap m) { + return new TUnmodifiableCharLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharByteMap unmodifiableMap(TCharByteMap m) { + return new TUnmodifiableCharByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharShortMap unmodifiableMap(TCharShortMap m) { + return new TUnmodifiableCharShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharCharMap unmodifiableMap(TCharCharMap m) { + return new TUnmodifiableCharCharMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TDoubleObjectMap unmodifiableMap(TDoubleObjectMap m) { + return new TUnmodifiableDoubleObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TFloatObjectMap unmodifiableMap(TFloatObjectMap m) { + return new TUnmodifiableFloatObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TIntObjectMap unmodifiableMap(TIntObjectMap m) { + return new TUnmodifiableIntObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TLongObjectMap unmodifiableMap(TLongObjectMap m) { + return new TUnmodifiableLongObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TByteObjectMap unmodifiableMap(TByteObjectMap m) { + return new TUnmodifiableByteObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TShortObjectMap unmodifiableMap(TShortObjectMap m) { + return new TUnmodifiableShortObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove primitive/Object map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TCharObjectMap unmodifiableMap(TCharObjectMap m) { + return new TUnmodifiableCharObjectMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectDoubleMap unmodifiableMap(TObjectDoubleMap m) { + return new TUnmodifiableObjectDoubleMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectFloatMap unmodifiableMap(TObjectFloatMap m) { + return new TUnmodifiableObjectFloatMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectIntMap unmodifiableMap(TObjectIntMap m) { + return new TUnmodifiableObjectIntMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectLongMap unmodifiableMap(TObjectLongMap m) { + return new TUnmodifiableObjectLongMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectByteMap unmodifiableMap(TObjectByteMap m) { + return new TUnmodifiableObjectByteMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectShortMap unmodifiableMap(TObjectShortMap m) { + return new TUnmodifiableObjectShortMap(m); + } + + /** + * Returns an unmodifiable view of the specified Trove Object/primitive map. + * This method allows modules to provide users with "read-only" access to + * internal maps. Query operations on the returned map "read through" to the + * specified map, and attempts to modify the returned map, whether direct or via + * its collection views, result in an UnsupportedOperationException. + *

+ * + * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map for which an unmodifiable view is to be returned. + * @return an unmodifiable view of the specified Trove primitive/primitive map. + */ + public static TObjectCharMap unmodifiableMap(TObjectCharMap m) { + return new TUnmodifiableObjectCharMap(m); + } + + /////////////////////////// + // TSynchronizedCollections + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TDoubleCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TDoubleIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TDoubleCollection synchronizedCollection(TDoubleCollection c) { + return new TSynchronizedDoubleCollection(c); + } + + static TDoubleCollection synchronizedCollection(TDoubleCollection c, Object mutex) { + return new TSynchronizedDoubleCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TFloatCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TFloatIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TFloatCollection synchronizedCollection(TFloatCollection c) { + return new TSynchronizedFloatCollection(c); + } + + static TFloatCollection synchronizedCollection(TFloatCollection c, Object mutex) { + return new TSynchronizedFloatCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TIntCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TIntIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TIntCollection synchronizedCollection(TIntCollection c) { + return new TSynchronizedIntCollection(c); + } + + static TIntCollection synchronizedCollection(TIntCollection c, Object mutex) { + return new TSynchronizedIntCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TLongCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TLongIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TLongCollection synchronizedCollection(TLongCollection c) { + return new TSynchronizedLongCollection(c); + } + + static TLongCollection synchronizedCollection(TLongCollection c, Object mutex) { + return new TSynchronizedLongCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TByteCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TByteIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TByteCollection synchronizedCollection(TByteCollection c) { + return new TSynchronizedByteCollection(c); + } + + static TByteCollection synchronizedCollection(TByteCollection c, Object mutex) { + return new TSynchronizedByteCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TShortCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TShortIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TShortCollection synchronizedCollection(TShortCollection c) { + return new TSynchronizedShortCollection(c); + } + + static TShortCollection synchronizedCollection(TShortCollection c, Object mutex) { + return new TSynchronizedShortCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove collection backed by the specified + * Trove collection. In order to guarantee serial access, it is critical that + * all access to the backing collection is accomplished through + * the returned collection. + *

+ * + * It is imperative that the user manually synchronize on the returned + * collection when iterating over it: + * + *

+	 *  TCharCollection c = TCollections.synchronizedCollection( myCollection );
+	 *     ...
+	 *  synchronized( c ) {
+	 *      TCharIterator i = c.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *         foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned collection does not pass the hashCode and + * equals operations through to the backing collection, but relies on + * Object's equals and hashCode methods. This is necessary to preserve + * the contracts of these operations in the case that the backing collection is + * a set or a list. + *

+ * + * The returned collection will be serializable if the specified collection is + * serializable. + * + * @param c + * the collection to be "wrapped" in a synchronized collection. + * @return a synchronized view of the specified collection. + */ + public static TCharCollection synchronizedCollection(TCharCollection c) { + return new TSynchronizedCharCollection(c); + } + + static TCharCollection synchronizedCollection(TCharCollection c, Object mutex) { + return new TSynchronizedCharCollection(c, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TDoubleSet s = TCollections.synchronizedSet( new TDoubleHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TDoubleIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TDoubleSet synchronizedSet(TDoubleSet s) { + return new TSynchronizedDoubleSet(s); + } + + static TDoubleSet synchronizedSet(TDoubleSet s, Object mutex) { + return new TSynchronizedDoubleSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TFloatSet s = TCollections.synchronizedSet( new TFloatHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TFloatIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TFloatSet synchronizedSet(TFloatSet s) { + return new TSynchronizedFloatSet(s); + } + + static TFloatSet synchronizedSet(TFloatSet s, Object mutex) { + return new TSynchronizedFloatSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TIntSet s = TCollections.synchronizedSet( new TIntHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TIntIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TIntSet synchronizedSet(TIntSet s) { + return new TSynchronizedIntSet(s); + } + + static TIntSet synchronizedSet(TIntSet s, Object mutex) { + return new TSynchronizedIntSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TLongSet s = TCollections.synchronizedSet( new TLongHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TLongIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TLongSet synchronizedSet(TLongSet s) { + return new TSynchronizedLongSet(s); + } + + static TLongSet synchronizedSet(TLongSet s, Object mutex) { + return new TSynchronizedLongSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TByteSet s = TCollections.synchronizedSet( new TByteHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TByteIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TByteSet synchronizedSet(TByteSet s) { + return new TSynchronizedByteSet(s); + } + + static TByteSet synchronizedSet(TByteSet s, Object mutex) { + return new TSynchronizedByteSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TShortSet s = TCollections.synchronizedSet( new TShortHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TShortIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TShortSet synchronizedSet(TShortSet s) { + return new TSynchronizedShortSet(s); + } + + static TShortSet synchronizedSet(TShortSet s, Object mutex) { + return new TSynchronizedShortSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove set backed by the specified set. + * In order to guarantee serial access, it is critical that all + * access to the backing set is accomplished through the returned set. + *

+ * + * It is imperative that the user manually synchronize on the returned set when + * iterating over it: + * + *

+	 *  TCharSet s = TCollections.synchronizedSet( new TCharHashSet() );
+	 *      ...
+	 *  synchronized(s) {
+	 *      TCharIterator i = s.iterator(); // Must be in the synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned set will be serializable if the specified set is serializable. + * + * @param s + * the set to be "wrapped" in a synchronized set. + * @return a synchronized view of the specified set. + */ + public static TCharSet synchronizedSet(TCharSet s) { + return new TSynchronizedCharSet(s); + } + + static TCharSet synchronizedSet(TCharSet s, Object mutex) { + return new TSynchronizedCharSet(s, mutex); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TDoubleList list = TCollections.synchronizedList( new TDoubleArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TDoubleIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TDoubleList synchronizedList(TDoubleList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list) + : new TSynchronizedDoubleList(list)); + } + + static TDoubleList synchronizedList(TDoubleList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list, mutex) + : new TSynchronizedDoubleList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TFloatList list = TCollections.synchronizedList( new TFloatArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TFloatIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TFloatList synchronizedList(TFloatList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list) + : new TSynchronizedFloatList(list)); + } + + static TFloatList synchronizedList(TFloatList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list, mutex) + : new TSynchronizedFloatList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TIntList list = TCollections.synchronizedList( new TIntArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TIntIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TIntList synchronizedList(TIntList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list) + : new TSynchronizedIntList(list)); + } + + static TIntList synchronizedList(TIntList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list, mutex) + : new TSynchronizedIntList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TLongList list = TCollections.synchronizedList( new TLongArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TLongIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TLongList synchronizedList(TLongList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list) + : new TSynchronizedLongList(list)); + } + + static TLongList synchronizedList(TLongList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list, mutex) + : new TSynchronizedLongList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TByteList list = TCollections.synchronizedList( new TByteArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TByteIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TByteList synchronizedList(TByteList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list) + : new TSynchronizedByteList(list)); + } + + static TByteList synchronizedList(TByteList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list, mutex) + : new TSynchronizedByteList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TShortList list = TCollections.synchronizedList( new TShortArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TShortIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TShortList synchronizedList(TShortList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list) + : new TSynchronizedShortList(list)); + } + + static TShortList synchronizedList(TShortList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list, mutex) + : new TSynchronizedShortList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove list backed by the specified list. + * In order to guarantee serial access, it is critical that all + * access to the backing list is accomplished through the returned list. + *

+ * + * It is imperative that the user manually synchronize on the returned list when + * iterating over it: + * + *

+	 *  TCharList list = TCollections.synchronizedList( new TCharArrayList() );
+	 *      ...
+	 *  synchronized( list ) {
+	 *      TCharIterator i = list.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned list will be serializable if the specified list is serializable. + * + * @param list + * the list to be "wrapped" in a synchronized list. + * @return a synchronized view of the specified list. + */ + public static TCharList synchronizedList(TCharList list) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list) + : new TSynchronizedCharList(list)); + } + + static TCharList synchronizedList(TCharList list, Object mutex) { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list, mutex) + : new TSynchronizedCharList(list, mutex)); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleDoubleMap m = TCollections.synchronizedMap( new TDoubleDoubleHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleDoubleMap synchronizedMap(TDoubleDoubleMap m) { + return new TSynchronizedDoubleDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleFloatMap m = TCollections.synchronizedMap( new TDoubleFloatHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleFloatMap synchronizedMap(TDoubleFloatMap m) { + return new TSynchronizedDoubleFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleIntMap m = TCollections.synchronizedMap( new TDoubleIntHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleIntMap synchronizedMap(TDoubleIntMap m) { + return new TSynchronizedDoubleIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleLongMap m = TCollections.synchronizedMap( new TDoubleLongHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleLongMap synchronizedMap(TDoubleLongMap m) { + return new TSynchronizedDoubleLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleByteMap m = TCollections.synchronizedMap( new TDoubleByteHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleByteMap synchronizedMap(TDoubleByteMap m) { + return new TSynchronizedDoubleByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleShortMap m = TCollections.synchronizedMap( new TDoubleShortHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleShortMap synchronizedMap(TDoubleShortMap m) { + return new TSynchronizedDoubleShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleCharMap m = TCollections.synchronizedMap( new TDoubleCharHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleCharMap synchronizedMap(TDoubleCharMap m) { + return new TSynchronizedDoubleCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatDoubleMap m = TCollections.synchronizedMap( new TFloatDoubleHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatDoubleMap synchronizedMap(TFloatDoubleMap m) { + return new TSynchronizedFloatDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatFloatMap m = TCollections.synchronizedMap( new TFloatFloatHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatFloatMap synchronizedMap(TFloatFloatMap m) { + return new TSynchronizedFloatFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatIntMap m = TCollections.synchronizedMap( new TFloatIntHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatIntMap synchronizedMap(TFloatIntMap m) { + return new TSynchronizedFloatIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatLongMap m = TCollections.synchronizedMap( new TFloatLongHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatLongMap synchronizedMap(TFloatLongMap m) { + return new TSynchronizedFloatLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatByteMap m = TCollections.synchronizedMap( new TFloatByteHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatByteMap synchronizedMap(TFloatByteMap m) { + return new TSynchronizedFloatByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatShortMap m = TCollections.synchronizedMap( new TFloatShortHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatShortMap synchronizedMap(TFloatShortMap m) { + return new TSynchronizedFloatShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatCharMap m = TCollections.synchronizedMap( new TFloatCharHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatCharMap synchronizedMap(TFloatCharMap m) { + return new TSynchronizedFloatCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntDoubleMap m = TCollections.synchronizedMap( new TIntDoubleHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntDoubleMap synchronizedMap(TIntDoubleMap m) { + return new TSynchronizedIntDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntFloatMap m = TCollections.synchronizedMap( new TIntFloatHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntFloatMap synchronizedMap(TIntFloatMap m) { + return new TSynchronizedIntFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntIntMap m = TCollections.synchronizedMap( new TIntIntHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntIntMap synchronizedMap(TIntIntMap m) { + return new TSynchronizedIntIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntLongMap m = TCollections.synchronizedMap( new TIntLongHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntLongMap synchronizedMap(TIntLongMap m) { + return new TSynchronizedIntLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntByteMap m = TCollections.synchronizedMap( new TIntByteHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntByteMap synchronizedMap(TIntByteMap m) { + return new TSynchronizedIntByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntShortMap m = TCollections.synchronizedMap( new TIntShortHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntShortMap synchronizedMap(TIntShortMap m) { + return new TSynchronizedIntShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntCharMap m = TCollections.synchronizedMap( new TIntCharHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntCharMap synchronizedMap(TIntCharMap m) { + return new TSynchronizedIntCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongDoubleMap m = TCollections.synchronizedMap( new TLongDoubleHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongDoubleMap synchronizedMap(TLongDoubleMap m) { + return new TSynchronizedLongDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongFloatMap m = TCollections.synchronizedMap( new TLongFloatHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongFloatMap synchronizedMap(TLongFloatMap m) { + return new TSynchronizedLongFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongIntMap m = TCollections.synchronizedMap( new TLongIntHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongIntMap synchronizedMap(TLongIntMap m) { + return new TSynchronizedLongIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongLongMap m = TCollections.synchronizedMap( new TLongLongHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongLongMap synchronizedMap(TLongLongMap m) { + return new TSynchronizedLongLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongByteMap m = TCollections.synchronizedMap( new TLongByteHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongByteMap synchronizedMap(TLongByteMap m) { + return new TSynchronizedLongByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongShortMap m = TCollections.synchronizedMap( new TLongShortHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongShortMap synchronizedMap(TLongShortMap m) { + return new TSynchronizedLongShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongCharMap m = TCollections.synchronizedMap( new TLongCharHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongCharMap synchronizedMap(TLongCharMap m) { + return new TSynchronizedLongCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteDoubleMap m = TCollections.synchronizedMap( new TByteDoubleHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteDoubleMap synchronizedMap(TByteDoubleMap m) { + return new TSynchronizedByteDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteFloatMap m = TCollections.synchronizedMap( new TByteFloatHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteFloatMap synchronizedMap(TByteFloatMap m) { + return new TSynchronizedByteFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteIntMap m = TCollections.synchronizedMap( new TByteIntHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteIntMap synchronizedMap(TByteIntMap m) { + return new TSynchronizedByteIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteLongMap m = TCollections.synchronizedMap( new TByteLongHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteLongMap synchronizedMap(TByteLongMap m) { + return new TSynchronizedByteLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteByteMap m = TCollections.synchronizedMap( new TByteByteHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteByteMap synchronizedMap(TByteByteMap m) { + return new TSynchronizedByteByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteShortMap m = TCollections.synchronizedMap( new TByteShortHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteShortMap synchronizedMap(TByteShortMap m) { + return new TSynchronizedByteShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteCharMap m = TCollections.synchronizedMap( new TByteCharHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteCharMap synchronizedMap(TByteCharMap m) { + return new TSynchronizedByteCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortDoubleMap m = TCollections.synchronizedMap( new TShortDoubleHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortDoubleMap synchronizedMap(TShortDoubleMap m) { + return new TSynchronizedShortDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortFloatMap m = TCollections.synchronizedMap( new TShortFloatHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortFloatMap synchronizedMap(TShortFloatMap m) { + return new TSynchronizedShortFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortIntMap m = TCollections.synchronizedMap( new TShortIntHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortIntMap synchronizedMap(TShortIntMap m) { + return new TSynchronizedShortIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortLongMap m = TCollections.synchronizedMap( new TShortLongHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortLongMap synchronizedMap(TShortLongMap m) { + return new TSynchronizedShortLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortByteMap m = TCollections.synchronizedMap( new TShortByteHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortByteMap synchronizedMap(TShortByteMap m) { + return new TSynchronizedShortByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortShortMap m = TCollections.synchronizedMap( new TShortShortHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortShortMap synchronizedMap(TShortShortMap m) { + return new TSynchronizedShortShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortCharMap m = TCollections.synchronizedMap( new TShortCharHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortCharMap synchronizedMap(TShortCharMap m) { + return new TSynchronizedShortCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharDoubleMap m = TCollections.synchronizedMap( new TCharDoubleHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharDoubleMap synchronizedMap(TCharDoubleMap m) { + return new TSynchronizedCharDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharFloatMap m = TCollections.synchronizedMap( new TCharFloatHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharFloatMap synchronizedMap(TCharFloatMap m) { + return new TSynchronizedCharFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharIntMap m = TCollections.synchronizedMap( new TCharIntHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharIntMap synchronizedMap(TCharIntMap m) { + return new TSynchronizedCharIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharLongMap m = TCollections.synchronizedMap( new TCharLongHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharLongMap synchronizedMap(TCharLongMap m) { + return new TSynchronizedCharLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharByteMap m = TCollections.synchronizedMap( new TCharByteHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharByteMap synchronizedMap(TCharByteMap m) { + return new TSynchronizedCharByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharShortMap m = TCollections.synchronizedMap( new TCharShortHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharShortMap synchronizedMap(TCharShortMap m) { + return new TSynchronizedCharShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharCharMap m = TCollections.synchronizedMap( new TCharCharHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharCharMap synchronizedMap(TCharCharMap m) { + return new TSynchronizedCharCharMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TDoubleObjectMap m = TCollections.synchronizedMap( new TDoubleObjectHashMap() );
+	 *      ...
+	 *  TDoubleSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TDoubleIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TDoubleObjectMap synchronizedMap(TDoubleObjectMap m) { + return new TSynchronizedDoubleObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TFloatObjectMap m = TCollections.synchronizedMap( new TFloatObjectHashMap() );
+	 *      ...
+	 *  TFloatSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TFloatIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TFloatObjectMap synchronizedMap(TFloatObjectMap m) { + return new TSynchronizedFloatObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TIntObjectMap m = TCollections.synchronizedMap( new TIntObjectHashMap() );
+	 *      ...
+	 *  TIntSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TIntIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TIntObjectMap synchronizedMap(TIntObjectMap m) { + return new TSynchronizedIntObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TLongObjectMap m = TCollections.synchronizedMap( new TLongObjectHashMap() );
+	 *      ...
+	 *  TLongSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TLongIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TLongObjectMap synchronizedMap(TLongObjectMap m) { + return new TSynchronizedLongObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TByteObjectMap m = TCollections.synchronizedMap( new TByteObjectHashMap() );
+	 *      ...
+	 *  TByteSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TByteIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TByteObjectMap synchronizedMap(TByteObjectMap m) { + return new TSynchronizedByteObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TShortObjectMap m = TCollections.synchronizedMap( new TShortObjectHashMap() );
+	 *      ...
+	 *  TShortSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TShortIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TShortObjectMap synchronizedMap(TShortObjectMap m) { + return new TSynchronizedShortObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TCharObjectMap m = TCollections.synchronizedMap( new TCharObjectHashMap() );
+	 *      ...
+	 *  TCharSet s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      TCharIterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TCharObjectMap synchronizedMap(TCharObjectMap m) { + return new TSynchronizedCharObjectMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectDoubleMap m = TCollections.synchronizedMap( new TObjectDoubleHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectDoubleMap synchronizedMap(TObjectDoubleMap m) { + return new TSynchronizedObjectDoubleMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectFloatMap m = TCollections.synchronizedMap( new TObjectFloatHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectFloatMap synchronizedMap(TObjectFloatMap m) { + return new TSynchronizedObjectFloatMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectIntMap m = TCollections.synchronizedMap( new TObjectIntHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectIntMap synchronizedMap(TObjectIntMap m) { + return new TSynchronizedObjectIntMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectLongMap m = TCollections.synchronizedMap( new TObjectLongHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectLongMap synchronizedMap(TObjectLongMap m) { + return new TSynchronizedObjectLongMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectByteMap m = TCollections.synchronizedMap( new TObjectByteHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectByteMap synchronizedMap(TObjectByteMap m) { + return new TSynchronizedObjectByteMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectShortMap m = TCollections.synchronizedMap( new TObjectShortHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectShortMap synchronizedMap(TObjectShortMap m) { + return new TSynchronizedObjectShortMap(m); + } + + /** + * Returns a synchronized (thread-safe) Trove map backed by the specified map. + * In order to guarantee serial access, it is critical that all + * access to the backing map is accomplished through the returned map. + *

+ * + * It is imperative that the user manually synchronize on the returned map when + * iterating over any of its collection views: + * + *

+	 *  TObjectCharMap m = TCollections.synchronizedMap( new TObjectCharHashMap() );
+	 *      ...
+	 *  Set s = m.keySet();  // Needn't be in synchronized block
+	 *      ...
+	 *  synchronized( m ) {  // Synchronizing on m, not s!
+	 *      Iterator i = s.iterator(); // Must be in synchronized block
+	 *      while ( i.hasNext() )
+	 *          foo( i.next() );
+	 *  }
+	 * 
+ * + * Failure to follow this advice may result in non-deterministic behavior. + * + *

+ * The returned map will be serializable if the specified map is serializable. + * + * @param m + * the map to be "wrapped" in a synchronized map. + * @return a synchronized view of the specified map. + */ + public static TObjectCharMap synchronizedMap(TObjectCharMap m) { + return new TSynchronizedObjectCharMap(m); + } +} \ No newline at end of file diff --git a/src/gnu/trove/TDecorators.java b/src/gnu/trove/TDecorators.java new file mode 100644 index 0000000..a0bf2c0 --- /dev/null +++ b/src/gnu/trove/TDecorators.java @@ -0,0 +1,965 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +import java.util.*; + +import gnu.trove.list.*; +import gnu.trove.map.*; +import gnu.trove.set.*; +import gnu.trove.decorator.*; + +/** + * This is a static utility class that provides functions for simplifying + * creation of decorators. + * + * @author Robert D. Eden + * @author Jeff Randall + * @since Trove 2.1 + */ +public class TDecorators { + // Hide the constructor + private TDecorators() { + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleDoubleMap map) { + return new TDoubleDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleFloatMap map) { + return new TDoubleFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleIntMap map) { + return new TDoubleIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleLongMap map) { + return new TDoubleLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleByteMap map) { + return new TDoubleByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleShortMap map) { + return new TDoubleShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleCharMap map) { + return new TDoubleCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatDoubleMap map) { + return new TFloatDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatFloatMap map) { + return new TFloatFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatIntMap map) { + return new TFloatIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatLongMap map) { + return new TFloatLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatByteMap map) { + return new TFloatByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatShortMap map) { + return new TFloatShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatCharMap map) { + return new TFloatCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntDoubleMap map) { + return new TIntDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntFloatMap map) { + return new TIntFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntIntMap map) { + return new TIntIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntLongMap map) { + return new TIntLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntByteMap map) { + return new TIntByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntShortMap map) { + return new TIntShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntCharMap map) { + return new TIntCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongDoubleMap map) { + return new TLongDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongFloatMap map) { + return new TLongFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongIntMap map) { + return new TLongIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongLongMap map) { + return new TLongLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongByteMap map) { + return new TLongByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongShortMap map) { + return new TLongShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongCharMap map) { + return new TLongCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteDoubleMap map) { + return new TByteDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteFloatMap map) { + return new TByteFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteIntMap map) { + return new TByteIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteLongMap map) { + return new TByteLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteByteMap map) { + return new TByteByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteShortMap map) { + return new TByteShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteCharMap map) { + return new TByteCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortDoubleMap map) { + return new TShortDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortFloatMap map) { + return new TShortFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortIntMap map) { + return new TShortIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortLongMap map) { + return new TShortLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortByteMap map) { + return new TShortByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortShortMap map) { + return new TShortShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortCharMap map) { + return new TShortCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharDoubleMap map) { + return new TCharDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharFloatMap map) { + return new TCharFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharIntMap map) { + return new TCharIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharLongMap map) { + return new TCharLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharByteMap map) { + return new TCharByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharShortMap map) { + return new TCharShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharCharMap map) { + return new TCharCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectDoubleMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectDoubleMap map) { + return new TObjectDoubleMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectFloatMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectFloatMap map) { + return new TObjectFloatMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectIntMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectIntMap map) { + return new TObjectIntMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectLongMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectLongMap map) { + return new TObjectLongMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectByteMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectByteMap map) { + return new TObjectByteMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectShortMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectShortMap map) { + return new TObjectShortMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TObjectCharMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TObjectCharMap map) { + return new TObjectCharMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TDoubleObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TDoubleObjectMap map) { + return new TDoubleObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TFloatObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TFloatObjectMap map) { + return new TFloatObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TIntObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TIntObjectMap map) { + return new TIntObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TLongObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TLongObjectMap map) { + return new TLongObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TByteObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TByteObjectMap map) { + return new TByteObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TShortObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TShortObjectMap map) { + return new TShortObjectMapDecorator(map); + } + + /** + * Wrap the given map in a decorator that uses the standard {@link java.util.Map + * Map} interface. + * + * @param map + * the TCharObjectMap to be wrapped + * @return the wrapped map. + */ + public static Map wrap(TCharObjectMap map) { + return new TCharObjectMapDecorator(map); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TDoubleSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TDoubleSet set) { + return new TDoubleSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TFloatSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TFloatSet set) { + return new TFloatSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TIntSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TIntSet set) { + return new TIntSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TLongSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TLongSet set) { + return new TLongSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TByteSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TByteSet set) { + return new TByteSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TShortSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TShortSet set) { + return new TShortSetDecorator(set); + } + + /** + * Wrap the given set in a decorator that uses the standard {@link java.util.Set + * Set} interface. + * + * @param set + * the TCharSet to be wrapped + * @return the wrapped set. + */ + public static Set wrap(TCharSet set) { + return new TCharSetDecorator(set); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TDoubleList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TDoubleList list) { + return new TDoubleListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TFloatList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TFloatList list) { + return new TFloatListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TIntList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TIntList list) { + return new TIntListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TLongList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TLongList list) { + return new TLongListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TByteList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TByteList list) { + return new TByteListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TShortList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TShortList list) { + return new TShortListDecorator(list); + } + + /** + * Wrap the given list in a decorator that uses the standard + * {@link java.util.List ListCommand} interface. + * + * @param list + * the TCharList to be wrapped + * @return the wrapped list. + */ + public static List wrap(TCharList list) { + return new TCharListDecorator(list); + } +} \ No newline at end of file diff --git a/src/gnu/trove/TDoubleCollection.java b/src/gnu/trove/TDoubleCollection.java new file mode 100644 index 0000000..464a809 --- /dev/null +++ b/src/gnu/trove/TDoubleCollection.java @@ -0,0 +1,314 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.procedure.TDoubleProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TDoubleCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + double getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an double value + * @return true if the collection contains the specified element. + */ + boolean contains(double entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TDoubleIterator value + */ + TDoubleIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + double[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an double[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + double[] toArray(double[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a double value + * @return true if the collection was modified by the add operation + */ + boolean add(double entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an double value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(double entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TDoubleCollection are present. + * + * @param collection + * a TDoubleCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TDoubleCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of double primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(double[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TDoubleCollection to the collection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TDoubleCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of double primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(double[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TDoubleCollection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TDoubleCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of double primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(double[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TDoubleCollection from the + * collection. + * + * @param collection + * a TDoubleCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TDoubleCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of double primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(double[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TDoubleCollection diff --git a/src/gnu/trove/TFloatCollection.java b/src/gnu/trove/TFloatCollection.java new file mode 100644 index 0000000..2df97f6 --- /dev/null +++ b/src/gnu/trove/TFloatCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.procedure.TFloatProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TFloatCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + float getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an float value + * @return true if the collection contains the specified element. + */ + boolean contains(float entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TFloatIterator value + */ + TFloatIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + float[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an float[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + float[] toArray(float[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a float value + * @return true if the collection was modified by the add operation + */ + boolean add(float entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an float value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(float entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TFloatCollection are present. + * + * @param collection + * a TFloatCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TFloatCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of float primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(float[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TFloatCollection to the collection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TFloatCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of float primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(float[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TFloatCollection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TFloatCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of float primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(float[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TFloatCollection from the collection. + * + * @param collection + * a TFloatCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TFloatCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of float primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(float[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TFloatCollection diff --git a/src/gnu/trove/TIntCollection.java b/src/gnu/trove/TIntCollection.java new file mode 100644 index 0000000..7c7330e --- /dev/null +++ b/src/gnu/trove/TIntCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.procedure.TIntProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TIntCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + int getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an int value + * @return true if the collection contains the specified element. + */ + boolean contains(int entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TIntIterator value + */ + TIntIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + int[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an int[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + int[] toArray(int[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a int value + * @return true if the collection was modified by the add operation + */ + boolean add(int entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an int value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(int entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TIntCollection are present. + * + * @param collection + * a TIntCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TIntCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of int primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(int[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TIntCollection to the collection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TIntCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of int primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(int[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TIntCollection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TIntCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of int primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(int[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TIntCollection from the collection. + * + * @param collection + * a TIntCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TIntCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of int primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(int[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TIntCollection diff --git a/src/gnu/trove/TLongCollection.java b/src/gnu/trove/TLongCollection.java new file mode 100644 index 0000000..690ec1f --- /dev/null +++ b/src/gnu/trove/TLongCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TLongIterator; +import gnu.trove.procedure.TLongProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TLongCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + long getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an long value + * @return true if the collection contains the specified element. + */ + boolean contains(long entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TLongIterator value + */ + TLongIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + long[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an long[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + long[] toArray(long[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a long value + * @return true if the collection was modified by the add operation + */ + boolean add(long entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an long value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(long entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TLongCollection are present. + * + * @param collection + * a TLongCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TLongCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of long primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(long[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TLongCollection to the collection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TLongCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of long primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(long[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TLongCollection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TLongCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of long primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(long[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TLongCollection from the collection. + * + * @param collection + * a TLongCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TLongCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of long primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(long[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TLongCollection diff --git a/src/gnu/trove/TShortCollection.java b/src/gnu/trove/TShortCollection.java new file mode 100644 index 0000000..5737766 --- /dev/null +++ b/src/gnu/trove/TShortCollection.java @@ -0,0 +1,313 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TShortIterator; +import gnu.trove.procedure.TShortProcedure; + +import java.util.Collection; + +/** + * An interface that mimics the Collection interface. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_Collection.template,v 1.1.2.2 2009/09/15 02:38:30 + * upholderoftruth Exp $ + */ + +public interface TShortCollection { + static final long serialVersionUID = 1L; + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + short getNoEntryValue(); + + /** + * Returns the number of elements in this collection (its cardinality). If this + * collection contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this collection (its cardinality) + */ + int size(); + + /** + * Returns true if this collection contains no elements. + * + * @return true if this collection contains no elements + */ + boolean isEmpty(); + + /** + * Returns true if this collection contains the specified element. + * + * @param entry + * an short value + * @return true if the collection contains the specified element. + */ + boolean contains(short entry); + + /** + * Creates an iterator over the values of the collection. The iterator supports + * element deletion. + * + * @return an TShortIterator value + */ + TShortIterator iterator(); + + /** + * Returns an array containing all of the elements in this collection. If this + * collection makes any guarantees as to what order its elements are returned by + * its iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this collection. (In other words, this method must allocate a new array + * even if this collection is backed by an array). The caller is thus free to + * modify the returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this collection + */ + short[] toArray(); + + /** + * Returns an array containing elements in this collection. + * + *

+ * If this collection fits in the specified array with room to spare (i.e., the + * array has more elements than this collection), the element in the array + * immediately following the end of the collection is collection to + * {@link #getNoEntryValue()}. (This is useful in determining the + * length of this collection only if the caller knows that this + * collection does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the collection size, the array will be + * filled with elements in Iterator order until it is full and exclude the + * remainder. + * + *

+ * If this collection makes any guarantees as to what order its elements are + * returned by its iterator, this method must return the elements in the same + * order. + * + * @param dest + * the array into which the elements of this collection are to be + * stored. + * @return an short[] containing all the elements in this collection + * @throws NullPointerException + * if the specified array is null + */ + short[] toArray(short[] dest); + + /** + * Inserts a value into the collection. + * + * @param entry + * a short value + * @return true if the collection was modified by the add operation + */ + boolean add(short entry); + + /** + * Removes entry from the collection. + * + * @param entry + * an short value + * @return true if the collection was modified by the remove operation. + */ + boolean remove(short entry); + + /** + * Tests the collection to determine if all of the elements in + * collection are present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(Collection collection); + + /** + * Tests the collection to determine if all of the elements in + * TShortCollection are present. + * + * @param collection + * a TShortCollection value + * @return true if all elements were present in the collection. + */ + boolean containsAll(TShortCollection collection); + + /** + * Tests the collection to determine if all of the elements in array + * are present. + * + * @param array + * as array of short primitives. + * @return true if all elements were present in the collection. + */ + boolean containsAll(short[] array); + + /** + * Adds all of the elements in collection to the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TShortCollection to the collection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(TShortCollection collection); + + /** + * Adds all of the elements in the array to the collection. + * + * @param array + * a array of short primitives. + * @return true if the collection was modified by the add all operation. + */ + boolean addAll(short[] array); + + /** + * Removes any values in the collection which are not contained in + * collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(Collection collection); + + /** + * Removes any values in the collection which are not contained in + * TShortCollection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(TShortCollection collection); + + /** + * Removes any values in the collection which are not contained in + * array. + * + * @param array + * an array of short primitives. + * @return true if the collection was modified by the retain all operation + */ + boolean retainAll(short[] array); + + /** + * Removes all of the elements in collection from the collection. + * + * @param collection + * a Collection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TShortCollection from the collection. + * + * @param collection + * a TShortCollection value + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(TShortCollection collection); + + /** + * Removes all of the elements in array from the collection. + * + * @param array + * an array of short primitives. + * @return true if the collection was modified by the remove all operation. + */ + boolean removeAll(short[] array); + + /** + * Empties the collection. + */ + void clear(); + + /** + * Executes procedure for each element in the collection. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the collection terminated because the + * procedure returned false for some value. + */ + boolean forEach(TShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this collection for equality. Returns + * true if the specified object is also a collection, the two + * collection have the same size, and every member of the specified collection + * is contained in this collection (or equivalently, every member of this + * collection is contained in the specified collection). This definition ensures + * that the equals method works properly across different implementations of the + * collection interface. + * + * @param o + * object to be compared for equality with this collection + * @return true if the specified object is equal to this collection + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this collection. The hash code of a + * collection is defined to be the sum of the hash codes of the elements in the + * collection. This ensures that s1.equals(s2) implies that + * s1.hashCode()==s2.hashCode() for any two collection s1 and + * s2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this collection + * @see Object#equals(Object) + * @see Collection#equals(Object) + */ + @Override + int hashCode(); + +} // TShortCollection diff --git a/src/gnu/trove/Version.java b/src/gnu/trove/Version.java new file mode 100644 index 0000000..cfba900 --- /dev/null +++ b/src/gnu/trove/Version.java @@ -0,0 +1,57 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove; + +/** + * Simple class meant as a possible main class (via manifest) to report the + * implementation version of the trove4j jar. + *

+ * This may be useful to ask feedback WITH build version information + *

+ * The Main-Class entry in the manifest.mf should be set during the build as + * well as the Implementation-Version manifest attribute should be set as well. + *

+ * Created by IntelliJ IDEA. User: Johan Parent Date: 3/03/11 Time: 22:10 + */ +public class Version { + public static void main(String[] args) { + System.out.println(getVersion()); + } + + /** + * Returns the implementation version of trove4j. Intended for applications + * wanting to return the version of trove4j they are using + *

+ * NOTE: this method will only return a useful version when working with a + * trove4j jar as it requires a manifest file + * + * @return + */ + public static String getVersion() { + String version = Version.class.getPackage().getImplementationVersion(); + // + if (version != null) { + return "trove4j version " + version; + } + + return "Sorry no Implementation-Version manifest attribute available"; + } +} diff --git a/src/gnu/trove/decorator/TByteByteMapDecorator.java b/src/gnu/trove/decorator/TByteByteMapDecorator.java new file mode 100644 index 0000000..0559231 --- /dev/null +++ b/src/gnu/trove/decorator/TByteByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteByteMap; +import gnu.trove.iterator.TByteByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteByteMap to wrap. + */ + public TByteByteMapDecorator(TByteByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteByteMap instance. + */ + public TByteByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Byte key, Byte value) { + byte k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteByteMapDecorator.this.containsKey(k) && TByteByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteCharMapDecorator.java b/src/gnu/trove/decorator/TByteCharMapDecorator.java new file mode 100644 index 0000000..5545811 --- /dev/null +++ b/src/gnu/trove/decorator/TByteCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteCharMap; +import gnu.trove.iterator.TByteCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteCharMap to wrap. + */ + public TByteCharMapDecorator(TByteCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteCharMap instance. + */ + public TByteCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Byte key, Character value) { + byte k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteCharMapDecorator.this.containsKey(k) && TByteCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteDoubleMapDecorator.java b/src/gnu/trove/decorator/TByteDoubleMapDecorator.java new file mode 100644 index 0000000..1e73ca7 --- /dev/null +++ b/src/gnu/trove/decorator/TByteDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteDoubleMap; +import gnu.trove.iterator.TByteDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteDoubleMap to wrap. + */ + public TByteDoubleMapDecorator(TByteDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteDoubleMap instance. + */ + public TByteDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Byte key, Double value) { + byte k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteDoubleMapDecorator.this.containsKey(k) && TByteDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteFloatMapDecorator.java b/src/gnu/trove/decorator/TByteFloatMapDecorator.java new file mode 100644 index 0000000..3a21ac5 --- /dev/null +++ b/src/gnu/trove/decorator/TByteFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteFloatMap; +import gnu.trove.iterator.TByteFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteFloatMap to wrap. + */ + public TByteFloatMapDecorator(TByteFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteFloatMap instance. + */ + public TByteFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Byte key, Float value) { + byte k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteFloatMapDecorator.this.containsKey(k) && TByteFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteIntMapDecorator.java b/src/gnu/trove/decorator/TByteIntMapDecorator.java new file mode 100644 index 0000000..f9534fd --- /dev/null +++ b/src/gnu/trove/decorator/TByteIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteIntMap; +import gnu.trove.iterator.TByteIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteIntMap to wrap. + */ + public TByteIntMapDecorator(TByteIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteIntMap instance. + */ + public TByteIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Byte key, Integer value) { + byte k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteIntMapDecorator.this.containsKey(k) && TByteIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteListDecorator.java b/src/gnu/trove/decorator/TByteListDecorator.java new file mode 100644 index 0000000..1945773 --- /dev/null +++ b/src/gnu/trove/decorator/TByteListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TByteList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteList conform to the java.util.List API. + * This class simply decorates an underlying TByteList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TByteListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TByteList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TByteList to wrap. + */ + public TByteListDecorator(TByteList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TByteList instance. + */ + public TByteList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Byte get(int index) { + byte value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(value); + } + + @Override + public Byte set(int index, Byte value) { + byte previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(previous_value); + } + + @Override + public void add(int index, Byte value) { + list.insert(index, value.byteValue()); + } + + @Override + public Byte remove(int index) { + byte previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Byte.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TByteList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TByteLongMapDecorator.java b/src/gnu/trove/decorator/TByteLongMapDecorator.java new file mode 100644 index 0000000..c7e1ace --- /dev/null +++ b/src/gnu/trove/decorator/TByteLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteLongMap; +import gnu.trove.iterator.TByteLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteLongMap to wrap. + */ + public TByteLongMapDecorator(TByteLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteLongMap instance. + */ + public TByteLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Byte key, Long value) { + byte k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteLongMapDecorator.this.containsKey(k) && TByteLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteObjectMapDecorator.java b/src/gnu/trove/decorator/TByteObjectMapDecorator.java new file mode 100644 index 0000000..50d5efe --- /dev/null +++ b/src/gnu/trove/decorator/TByteObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteObjectMap; +import gnu.trove.iterator.TByteObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteObjectMap to wrap. + */ + public TByteObjectMapDecorator(TByteObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteObjectMap instance. + */ + public TByteObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Byte value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Byte key, V value) { + byte k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey((Byte) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey((Byte) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteObjectMapDecorator.this.containsKey(k) && TByteObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte k = it.key(); + final Byte key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(((Byte) key).byteValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Byte key) { + return key.byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TByteObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TByteSetDecorator.java b/src/gnu/trove/decorator/TByteSetDecorator.java new file mode 100644 index 0000000..3713400 --- /dev/null +++ b/src/gnu/trove/decorator/TByteSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TByteSet; +import gnu.trove.iterator.TByteIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteSet conform to the java.util.Set API. + * This class simply decorates an underlying TByteSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TByteSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TByteSet to wrap. + */ + public TByteSetDecorator(TByteSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TByteSet instance. + */ + public TByteSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Byte value) { + return value != null && _set.add(value.byteValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Byte) { + byte v = ((Byte) val).byteValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Byte && _set.remove(((Byte) value).byteValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TByteIterator it = _set.iterator(); + + @Override + public Byte next() { + return Byte.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Byte)) + return false; + return _set.contains(((Byte) o).byteValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TByteSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TByteHashSetDecorator diff --git a/src/gnu/trove/decorator/TByteShortMapDecorator.java b/src/gnu/trove/decorator/TByteShortMapDecorator.java new file mode 100644 index 0000000..9441551 --- /dev/null +++ b/src/gnu/trove/decorator/TByteShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TByteShortMap; +import gnu.trove.iterator.TByteShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TByteShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TByteShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TByteShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TByteShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TByteShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TByteShortMap to wrap. + */ + public TByteShortMapDecorator(TByteShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TByteShortMap instance. + */ + public TByteShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Byte key, Short value) { + byte k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + byte k; + if (key != null) { + if (key instanceof Byte) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TByteShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TByteShortMapDecorator.this.containsKey(k) && TByteShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TByteShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + byte ik = it.key(); + final Byte key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Byte getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Byte key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TByteShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Byte && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Byte wrapKey(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected byte unwrapKey(Object key) { + return ((Byte) key).byteValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TByteShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TByteShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharByteMapDecorator.java b/src/gnu/trove/decorator/TCharByteMapDecorator.java new file mode 100644 index 0000000..1b6a22e --- /dev/null +++ b/src/gnu/trove/decorator/TCharByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharByteMap; +import gnu.trove.iterator.TCharByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharByteMap to wrap. + */ + public TCharByteMapDecorator(TCharByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharByteMap instance. + */ + public TCharByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Character key, Byte value) { + char k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharByteMapDecorator.this.containsKey(k) && TCharByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharCharMapDecorator.java b/src/gnu/trove/decorator/TCharCharMapDecorator.java new file mode 100644 index 0000000..adeccad --- /dev/null +++ b/src/gnu/trove/decorator/TCharCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharCharMap; +import gnu.trove.iterator.TCharCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharCharMap to wrap. + */ + public TCharCharMapDecorator(TCharCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharCharMap instance. + */ + public TCharCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Character key, Character value) { + char k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharCharMapDecorator.this.containsKey(k) && TCharCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharDoubleMapDecorator.java b/src/gnu/trove/decorator/TCharDoubleMapDecorator.java new file mode 100644 index 0000000..fdfc906 --- /dev/null +++ b/src/gnu/trove/decorator/TCharDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharDoubleMap; +import gnu.trove.iterator.TCharDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharDoubleMap to wrap. + */ + public TCharDoubleMapDecorator(TCharDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharDoubleMap instance. + */ + public TCharDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Character key, Double value) { + char k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharDoubleMapDecorator.this.containsKey(k) && TCharDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharFloatMapDecorator.java b/src/gnu/trove/decorator/TCharFloatMapDecorator.java new file mode 100644 index 0000000..a11dc2d --- /dev/null +++ b/src/gnu/trove/decorator/TCharFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharFloatMap; +import gnu.trove.iterator.TCharFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharFloatMap to wrap. + */ + public TCharFloatMapDecorator(TCharFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharFloatMap instance. + */ + public TCharFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Character key, Float value) { + char k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharFloatMapDecorator.this.containsKey(k) && TCharFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharIntMapDecorator.java b/src/gnu/trove/decorator/TCharIntMapDecorator.java new file mode 100644 index 0000000..07b25c8 --- /dev/null +++ b/src/gnu/trove/decorator/TCharIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharIntMap; +import gnu.trove.iterator.TCharIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharIntMap to wrap. + */ + public TCharIntMapDecorator(TCharIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharIntMap instance. + */ + public TCharIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Character key, Integer value) { + char k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharIntMapDecorator.this.containsKey(k) && TCharIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharListDecorator.java b/src/gnu/trove/decorator/TCharListDecorator.java new file mode 100644 index 0000000..6caa4ab --- /dev/null +++ b/src/gnu/trove/decorator/TCharListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TCharList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharList conform to the java.util.List API. + * This class simply decorates an underlying TCharList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TCharListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TCharList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TCharList to wrap. + */ + public TCharListDecorator(TCharList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TCharList instance. + */ + public TCharList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Character get(int index) { + char value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(value); + } + + @Override + public Character set(int index, Character value) { + char previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(previous_value); + } + + @Override + public void add(int index, Character value) { + list.insert(index, value.charValue()); + } + + @Override + public Character remove(int index) { + char previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Character.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TCharList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TCharLongMapDecorator.java b/src/gnu/trove/decorator/TCharLongMapDecorator.java new file mode 100644 index 0000000..9c8de19 --- /dev/null +++ b/src/gnu/trove/decorator/TCharLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharLongMap; +import gnu.trove.iterator.TCharLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharLongMap to wrap. + */ + public TCharLongMapDecorator(TCharLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharLongMap instance. + */ + public TCharLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Character key, Long value) { + char k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharLongMapDecorator.this.containsKey(k) && TCharLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharObjectMapDecorator.java b/src/gnu/trove/decorator/TCharObjectMapDecorator.java new file mode 100644 index 0000000..55a4910 --- /dev/null +++ b/src/gnu/trove/decorator/TCharObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharObjectMap; +import gnu.trove.iterator.TCharObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharObjectMap to wrap. + */ + public TCharObjectMapDecorator(TCharObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharObjectMap instance. + */ + public TCharObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Character value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Character key, V value) { + char k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey((Character) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey((Character) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharObjectMapDecorator.this.containsKey(k) && TCharObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char k = it.key(); + final Character key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(((Character) key).charValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Character key) { + return key.charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TCharObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TCharSetDecorator.java b/src/gnu/trove/decorator/TCharSetDecorator.java new file mode 100644 index 0000000..8209ea9 --- /dev/null +++ b/src/gnu/trove/decorator/TCharSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TCharSet; +import gnu.trove.iterator.TCharIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharSet conform to the java.util.Set API. + * This class simply decorates an underlying TCharSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TCharSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TCharSet to wrap. + */ + public TCharSetDecorator(TCharSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TCharSet instance. + */ + public TCharSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Character value) { + return value != null && _set.add(value.charValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Character) { + char v = ((Character) val).charValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Character && _set.remove(((Character) value).charValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TCharIterator it = _set.iterator(); + + @Override + public Character next() { + return Character.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Character)) + return false; + return _set.contains(((Character) o).charValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TCharSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TCharHashSetDecorator diff --git a/src/gnu/trove/decorator/TCharShortMapDecorator.java b/src/gnu/trove/decorator/TCharShortMapDecorator.java new file mode 100644 index 0000000..4cbbfb1 --- /dev/null +++ b/src/gnu/trove/decorator/TCharShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TCharShortMap; +import gnu.trove.iterator.TCharShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TCharShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TCharShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TCharShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TCharShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TCharShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TCharShortMap to wrap. + */ + public TCharShortMapDecorator(TCharShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TCharShortMap instance. + */ + public TCharShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Character key, Short value) { + char k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + char k; + if (key != null) { + if (key instanceof Character) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TCharShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TCharShortMapDecorator.this.containsKey(k) && TCharShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TCharShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + char ik = it.key(); + final Character key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Character getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Character key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TCharShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Character && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Character wrapKey(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected char unwrapKey(Object key) { + return ((Character) key).charValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TCharShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TCharShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleByteMapDecorator.java b/src/gnu/trove/decorator/TDoubleByteMapDecorator.java new file mode 100644 index 0000000..0ff4c96 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleByteMap; +import gnu.trove.iterator.TDoubleByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleByteMap to wrap. + */ + public TDoubleByteMapDecorator(TDoubleByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleByteMap instance. + */ + public TDoubleByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Double key, Byte value) { + double k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleByteMapDecorator.this.containsKey(k) && TDoubleByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleCharMapDecorator.java b/src/gnu/trove/decorator/TDoubleCharMapDecorator.java new file mode 100644 index 0000000..07dbd1f --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleCharMap; +import gnu.trove.iterator.TDoubleCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleCharMap to wrap. + */ + public TDoubleCharMapDecorator(TDoubleCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleCharMap instance. + */ + public TDoubleCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Double key, Character value) { + double k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleCharMapDecorator.this.containsKey(k) && TDoubleCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java b/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java new file mode 100644 index 0000000..5ffaf32 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleDoubleMapDecorator.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleDoubleMap; +import gnu.trove.iterator.TDoubleDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleDoubleMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TDoubleDoubleMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleDoubleMap to wrap. + */ + public TDoubleDoubleMapDecorator(TDoubleDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleDoubleMap instance. + */ + public TDoubleDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Double key, Double value) { + double k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleDoubleMapDecorator.this.containsKey(k) + && TDoubleDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java b/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java new file mode 100644 index 0000000..ec00a08 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleFloatMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleFloatMap; +import gnu.trove.iterator.TDoubleFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleFloatMap to wrap. + */ + public TDoubleFloatMapDecorator(TDoubleFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleFloatMap instance. + */ + public TDoubleFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Double key, Float value) { + double k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleFloatMapDecorator.this.containsKey(k) + && TDoubleFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleIntMapDecorator.java b/src/gnu/trove/decorator/TDoubleIntMapDecorator.java new file mode 100644 index 0000000..afbc5fc --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.iterator.TDoubleIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleIntMap to wrap. + */ + public TDoubleIntMapDecorator(TDoubleIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleIntMap instance. + */ + public TDoubleIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Double key, Integer value) { + double k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleIntMapDecorator.this.containsKey(k) && TDoubleIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleListDecorator.java b/src/gnu/trove/decorator/TDoubleListDecorator.java new file mode 100644 index 0000000..f950ae9 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TDoubleList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleList conform to the java.util.List + * API. This class simply decorates an underlying TDoubleList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TDoubleListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TDoubleList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TDoubleList to wrap. + */ + public TDoubleListDecorator(TDoubleList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TDoubleList instance. + */ + public TDoubleList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Double get(int index) { + double value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(value); + } + + @Override + public Double set(int index, Double value) { + double previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(previous_value); + } + + @Override + public void add(int index, Double value) { + list.insert(index, value.doubleValue()); + } + + @Override + public Double remove(int index) { + double previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Double.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TDoubleList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TDoubleLongMapDecorator.java b/src/gnu/trove/decorator/TDoubleLongMapDecorator.java new file mode 100644 index 0000000..63762e4 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleLongMap; +import gnu.trove.iterator.TDoubleLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleLongMap to wrap. + */ + public TDoubleLongMapDecorator(TDoubleLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleLongMap instance. + */ + public TDoubleLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Double key, Long value) { + double k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleLongMapDecorator.this.containsKey(k) && TDoubleLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java b/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java new file mode 100644 index 0000000..51ee6e5 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleObjectMapDecorator.java @@ -0,0 +1,376 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleObjectMap; +import gnu.trove.iterator.TDoubleObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleObjectMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TDoubleObjectMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleObjectMap to wrap. + */ + public TDoubleObjectMapDecorator(TDoubleObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleObjectMap instance. + */ + public TDoubleObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Double value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Double key, V value) { + double k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey((Double) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey((Double) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleObjectMapDecorator.this.containsKey(k) + && TDoubleObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double k = it.key(); + final Double key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(((Double) key).doubleValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Double key) { + return key.doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TDoubleObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TDoubleSetDecorator.java b/src/gnu/trove/decorator/TDoubleSetDecorator.java new file mode 100644 index 0000000..48a8918 --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TDoubleSet; +import gnu.trove.iterator.TDoubleIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleSet conform to the java.util.Set API. + * This class simply decorates an underlying TDoubleSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TDoubleSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TDoubleSet to wrap. + */ + public TDoubleSetDecorator(TDoubleSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TDoubleSet instance. + */ + public TDoubleSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Double value) { + return value != null && _set.add(value.doubleValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Double) { + double v = ((Double) val).doubleValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Double && _set.remove(((Double) value).doubleValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TDoubleIterator it = _set.iterator(); + + @Override + public Double next() { + return Double.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Double)) + return false; + return _set.contains(((Double) o).doubleValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TDoubleSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TDoubleHashSetDecorator diff --git a/src/gnu/trove/decorator/TDoubleShortMapDecorator.java b/src/gnu/trove/decorator/TDoubleShortMapDecorator.java new file mode 100644 index 0000000..83d0bac --- /dev/null +++ b/src/gnu/trove/decorator/TDoubleShortMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TDoubleShortMap; +import gnu.trove.iterator.TDoubleShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TDoubleShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TDoubleShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TDoubleShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TDoubleShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TDoubleShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TDoubleShortMap to wrap. + */ + public TDoubleShortMapDecorator(TDoubleShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TDoubleShortMap instance. + */ + public TDoubleShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Double key, Short value) { + double k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + double k; + if (key != null) { + if (key instanceof Double) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TDoubleShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TDoubleShortMapDecorator.this.containsKey(k) + && TDoubleShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TDoubleShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + double ik = it.key(); + final Double key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Double getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Double key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TDoubleShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Double && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Double wrapKey(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected double unwrapKey(Object key) { + return ((Double) key).doubleValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TDoubleShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TDoubleShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatByteMapDecorator.java b/src/gnu/trove/decorator/TFloatByteMapDecorator.java new file mode 100644 index 0000000..57b7bc9 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatByteMap; +import gnu.trove.iterator.TFloatByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatByteMap to wrap. + */ + public TFloatByteMapDecorator(TFloatByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatByteMap instance. + */ + public TFloatByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Float key, Byte value) { + float k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatByteMapDecorator.this.containsKey(k) && TFloatByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatCharMapDecorator.java b/src/gnu/trove/decorator/TFloatCharMapDecorator.java new file mode 100644 index 0000000..6947065 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatCharMap; +import gnu.trove.iterator.TFloatCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatCharMap to wrap. + */ + public TFloatCharMapDecorator(TFloatCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatCharMap instance. + */ + public TFloatCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Float key, Character value) { + float k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatCharMapDecorator.this.containsKey(k) && TFloatCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java b/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java new file mode 100644 index 0000000..3e59e2a --- /dev/null +++ b/src/gnu/trove/decorator/TFloatDoubleMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatDoubleMap; +import gnu.trove.iterator.TFloatDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatDoubleMap to wrap. + */ + public TFloatDoubleMapDecorator(TFloatDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatDoubleMap instance. + */ + public TFloatDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Float key, Double value) { + float k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatDoubleMapDecorator.this.containsKey(k) + && TFloatDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatFloatMapDecorator.java b/src/gnu/trove/decorator/TFloatFloatMapDecorator.java new file mode 100644 index 0000000..8f9296f --- /dev/null +++ b/src/gnu/trove/decorator/TFloatFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatFloatMap; +import gnu.trove.iterator.TFloatFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatFloatMap to wrap. + */ + public TFloatFloatMapDecorator(TFloatFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatFloatMap instance. + */ + public TFloatFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Float key, Float value) { + float k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatFloatMapDecorator.this.containsKey(k) && TFloatFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatIntMapDecorator.java b/src/gnu/trove/decorator/TFloatIntMapDecorator.java new file mode 100644 index 0000000..c9166c1 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatIntMap; +import gnu.trove.iterator.TFloatIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatIntMap to wrap. + */ + public TFloatIntMapDecorator(TFloatIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatIntMap instance. + */ + public TFloatIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Float key, Integer value) { + float k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatIntMapDecorator.this.containsKey(k) && TFloatIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatListDecorator.java b/src/gnu/trove/decorator/TFloatListDecorator.java new file mode 100644 index 0000000..d9838aa --- /dev/null +++ b/src/gnu/trove/decorator/TFloatListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TFloatList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatList conform to the java.util.List + * API. This class simply decorates an underlying TFloatList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TFloatListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TFloatList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TFloatList to wrap. + */ + public TFloatListDecorator(TFloatList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TFloatList instance. + */ + public TFloatList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Float get(int index) { + float value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(value); + } + + @Override + public Float set(int index, Float value) { + float previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(previous_value); + } + + @Override + public void add(int index, Float value) { + list.insert(index, value.floatValue()); + } + + @Override + public Float remove(int index) { + float previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Float.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TFloatList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TFloatLongMapDecorator.java b/src/gnu/trove/decorator/TFloatLongMapDecorator.java new file mode 100644 index 0000000..9a33c27 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatLongMap; +import gnu.trove.iterator.TFloatLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatLongMap to wrap. + */ + public TFloatLongMapDecorator(TFloatLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatLongMap instance. + */ + public TFloatLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Float key, Long value) { + float k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatLongMapDecorator.this.containsKey(k) && TFloatLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatObjectMapDecorator.java b/src/gnu/trove/decorator/TFloatObjectMapDecorator.java new file mode 100644 index 0000000..e3e18af --- /dev/null +++ b/src/gnu/trove/decorator/TFloatObjectMapDecorator.java @@ -0,0 +1,375 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatObjectMap; +import gnu.trove.iterator.TFloatObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatObjectMap to wrap. + */ + public TFloatObjectMapDecorator(TFloatObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatObjectMap instance. + */ + public TFloatObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Float value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Float key, V value) { + float k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey((Float) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey((Float) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatObjectMapDecorator.this.containsKey(k) + && TFloatObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float k = it.key(); + final Float key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(((Float) key).floatValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Float key) { + return key.floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TFloatObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TFloatSetDecorator.java b/src/gnu/trove/decorator/TFloatSetDecorator.java new file mode 100644 index 0000000..0f20ce0 --- /dev/null +++ b/src/gnu/trove/decorator/TFloatSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TFloatSet; +import gnu.trove.iterator.TFloatIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatSet conform to the java.util.Set API. + * This class simply decorates an underlying TFloatSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TFloatSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TFloatSet to wrap. + */ + public TFloatSetDecorator(TFloatSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TFloatSet instance. + */ + public TFloatSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Float value) { + return value != null && _set.add(value.floatValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Float) { + float v = ((Float) val).floatValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Float && _set.remove(((Float) value).floatValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TFloatIterator it = _set.iterator(); + + @Override + public Float next() { + return Float.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Float)) + return false; + return _set.contains(((Float) o).floatValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TFloatSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TFloatHashSetDecorator diff --git a/src/gnu/trove/decorator/TFloatShortMapDecorator.java b/src/gnu/trove/decorator/TFloatShortMapDecorator.java new file mode 100644 index 0000000..84ed98c --- /dev/null +++ b/src/gnu/trove/decorator/TFloatShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TFloatShortMap; +import gnu.trove.iterator.TFloatShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TFloatShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TFloatShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TFloatShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TFloatShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TFloatShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TFloatShortMap to wrap. + */ + public TFloatShortMapDecorator(TFloatShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TFloatShortMap instance. + */ + public TFloatShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Float key, Short value) { + float k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + float k; + if (key != null) { + if (key instanceof Float) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TFloatShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TFloatShortMapDecorator.this.containsKey(k) && TFloatShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TFloatShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + float ik = it.key(); + final Float key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Float getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Float key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TFloatShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Float && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Float wrapKey(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected float unwrapKey(Object key) { + return ((Float) key).floatValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TFloatShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TFloatShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntByteMapDecorator.java b/src/gnu/trove/decorator/TIntByteMapDecorator.java new file mode 100644 index 0000000..f6541ad --- /dev/null +++ b/src/gnu/trove/decorator/TIntByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntByteMap; +import gnu.trove.iterator.TIntByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntByteMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntByteMap to wrap. + */ + public TIntByteMapDecorator(TIntByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntByteMap instance. + */ + public TIntByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Integer key, Byte value) { + int k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntByteMapDecorator.this.containsKey(k) && TIntByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntCharMapDecorator.java b/src/gnu/trove/decorator/TIntCharMapDecorator.java new file mode 100644 index 0000000..56c8a56 --- /dev/null +++ b/src/gnu/trove/decorator/TIntCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntCharMap; +import gnu.trove.iterator.TIntCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntCharMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntCharMap to wrap. + */ + public TIntCharMapDecorator(TIntCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntCharMap instance. + */ + public TIntCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Integer key, Character value) { + int k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntCharMapDecorator.this.containsKey(k) && TIntCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntDoubleMapDecorator.java b/src/gnu/trove/decorator/TIntDoubleMapDecorator.java new file mode 100644 index 0000000..e070654 --- /dev/null +++ b/src/gnu/trove/decorator/TIntDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntDoubleMap; +import gnu.trove.iterator.TIntDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntDoubleMap to wrap. + */ + public TIntDoubleMapDecorator(TIntDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntDoubleMap instance. + */ + public TIntDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Integer key, Double value) { + int k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntDoubleMapDecorator.this.containsKey(k) && TIntDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntFloatMapDecorator.java b/src/gnu/trove/decorator/TIntFloatMapDecorator.java new file mode 100644 index 0000000..cea602b --- /dev/null +++ b/src/gnu/trove/decorator/TIntFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntFloatMap; +import gnu.trove.iterator.TIntFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntFloatMap to wrap. + */ + public TIntFloatMapDecorator(TIntFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntFloatMap instance. + */ + public TIntFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Integer key, Float value) { + int k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntFloatMapDecorator.this.containsKey(k) && TIntFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntIntMapDecorator.java b/src/gnu/trove/decorator/TIntIntMapDecorator.java new file mode 100644 index 0000000..f939706 --- /dev/null +++ b/src/gnu/trove/decorator/TIntIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntIntMap; +import gnu.trove.iterator.TIntIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntIntMap conform to the java.util.Map API. + * This class simply decorates an underlying TIntIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntIntMap to wrap. + */ + public TIntIntMapDecorator(TIntIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntIntMap instance. + */ + public TIntIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Integer key, Integer value) { + int k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntIntMapDecorator.this.containsKey(k) && TIntIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntListDecorator.java b/src/gnu/trove/decorator/TIntListDecorator.java new file mode 100644 index 0000000..e07e9b5 --- /dev/null +++ b/src/gnu/trove/decorator/TIntListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TIntList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntList conform to the java.util.List API. + * This class simply decorates an underlying TIntList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TIntListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TIntList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TIntList to wrap. + */ + public TIntListDecorator(TIntList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TIntList instance. + */ + public TIntList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Integer get(int index) { + int value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(value); + } + + @Override + public Integer set(int index, Integer value) { + int previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(previous_value); + } + + @Override + public void add(int index, Integer value) { + list.insert(index, value.intValue()); + } + + @Override + public Integer remove(int index) { + int previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Integer.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TIntList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TIntLongMapDecorator.java b/src/gnu/trove/decorator/TIntLongMapDecorator.java new file mode 100644 index 0000000..44b8cbd --- /dev/null +++ b/src/gnu/trove/decorator/TIntLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntLongMap; +import gnu.trove.iterator.TIntLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntLongMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntLongMap to wrap. + */ + public TIntLongMapDecorator(TIntLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntLongMap instance. + */ + public TIntLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Integer key, Long value) { + int k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntLongMapDecorator.this.containsKey(k) && TIntLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntObjectMapDecorator.java b/src/gnu/trove/decorator/TIntObjectMapDecorator.java new file mode 100644 index 0000000..f1122d8 --- /dev/null +++ b/src/gnu/trove/decorator/TIntObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.iterator.TIntObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntObjectMap to wrap. + */ + public TIntObjectMapDecorator(TIntObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntObjectMap instance. + */ + public TIntObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Integer value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Integer key, V value) { + int k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey((Integer) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey((Integer) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntObjectMapDecorator.this.containsKey(k) && TIntObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int k = it.key(); + final Integer key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(((Integer) key).intValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Integer key) { + return key.intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TIntObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TIntSetDecorator.java b/src/gnu/trove/decorator/TIntSetDecorator.java new file mode 100644 index 0000000..fa721c2 --- /dev/null +++ b/src/gnu/trove/decorator/TIntSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TIntSet; +import gnu.trove.iterator.TIntIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntSet conform to the java.util.Set API. + * This class simply decorates an underlying TIntSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TIntSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TIntSet to wrap. + */ + public TIntSetDecorator(TIntSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TIntSet instance. + */ + public TIntSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Integer value) { + return value != null && _set.add(value.intValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Integer) { + int v = ((Integer) val).intValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Integer && _set.remove(((Integer) value).intValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TIntIterator it = _set.iterator(); + + @Override + public Integer next() { + return Integer.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Integer)) + return false; + return _set.contains(((Integer) o).intValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TIntSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TIntHashSetDecorator diff --git a/src/gnu/trove/decorator/TIntShortMapDecorator.java b/src/gnu/trove/decorator/TIntShortMapDecorator.java new file mode 100644 index 0000000..f963a73 --- /dev/null +++ b/src/gnu/trove/decorator/TIntShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TIntShortMap; +import gnu.trove.iterator.TIntShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TIntShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TIntShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TIntShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TIntShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TIntShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TIntShortMap to wrap. + */ + public TIntShortMapDecorator(TIntShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TIntShortMap instance. + */ + public TIntShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Integer key, Short value) { + int k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + int k; + if (key != null) { + if (key instanceof Integer) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TIntShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TIntShortMapDecorator.this.containsKey(k) && TIntShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TIntShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + int ik = it.key(); + final Integer key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Integer getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Integer key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TIntShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Integer && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Integer wrapKey(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected int unwrapKey(Object key) { + return ((Integer) key).intValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TIntShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TIntShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongByteMapDecorator.java b/src/gnu/trove/decorator/TLongByteMapDecorator.java new file mode 100644 index 0000000..6195e49 --- /dev/null +++ b/src/gnu/trove/decorator/TLongByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongByteMap; +import gnu.trove.iterator.TLongByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongByteMap to wrap. + */ + public TLongByteMapDecorator(TLongByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongByteMap instance. + */ + public TLongByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Long key, Byte value) { + long k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongByteMapDecorator.this.containsKey(k) && TLongByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongCharMapDecorator.java b/src/gnu/trove/decorator/TLongCharMapDecorator.java new file mode 100644 index 0000000..d1be8f0 --- /dev/null +++ b/src/gnu/trove/decorator/TLongCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongCharMap; +import gnu.trove.iterator.TLongCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongCharMap to wrap. + */ + public TLongCharMapDecorator(TLongCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongCharMap instance. + */ + public TLongCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Long key, Character value) { + long k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongCharMapDecorator.this.containsKey(k) && TLongCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongDoubleMapDecorator.java b/src/gnu/trove/decorator/TLongDoubleMapDecorator.java new file mode 100644 index 0000000..909049b --- /dev/null +++ b/src/gnu/trove/decorator/TLongDoubleMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongDoubleMap; +import gnu.trove.iterator.TLongDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongDoubleMap to wrap. + */ + public TLongDoubleMapDecorator(TLongDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongDoubleMap instance. + */ + public TLongDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Long key, Double value) { + long k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongDoubleMapDecorator.this.containsKey(k) && TLongDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongFloatMapDecorator.java b/src/gnu/trove/decorator/TLongFloatMapDecorator.java new file mode 100644 index 0000000..7fe66d1 --- /dev/null +++ b/src/gnu/trove/decorator/TLongFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongFloatMap; +import gnu.trove.iterator.TLongFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongFloatMap to wrap. + */ + public TLongFloatMapDecorator(TLongFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongFloatMap instance. + */ + public TLongFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Long key, Float value) { + long k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongFloatMapDecorator.this.containsKey(k) && TLongFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongIntMapDecorator.java b/src/gnu/trove/decorator/TLongIntMapDecorator.java new file mode 100644 index 0000000..a255164 --- /dev/null +++ b/src/gnu/trove/decorator/TLongIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongIntMap; +import gnu.trove.iterator.TLongIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongIntMap and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongIntMap to wrap. + */ + public TLongIntMapDecorator(TLongIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongIntMap instance. + */ + public TLongIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Long key, Integer value) { + long k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongIntMapDecorator.this.containsKey(k) && TLongIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongListDecorator.java b/src/gnu/trove/decorator/TLongListDecorator.java new file mode 100644 index 0000000..dcd9faa --- /dev/null +++ b/src/gnu/trove/decorator/TLongListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TLongList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongList conform to the java.util.List API. + * This class simply decorates an underlying TLongList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TLongListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TLongList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TLongList to wrap. + */ + public TLongListDecorator(TLongList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TLongList instance. + */ + public TLongList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Long get(int index) { + long value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(value); + } + + @Override + public Long set(int index, Long value) { + long previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(previous_value); + } + + @Override + public void add(int index, Long value) { + list.insert(index, value.longValue()); + } + + @Override + public Long remove(int index) { + long previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Long.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TLongList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TLongLongMapDecorator.java b/src/gnu/trove/decorator/TLongLongMapDecorator.java new file mode 100644 index 0000000..38fe65c --- /dev/null +++ b/src/gnu/trove/decorator/TLongLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongLongMap; +import gnu.trove.iterator.TLongLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongLongMap to wrap. + */ + public TLongLongMapDecorator(TLongLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongLongMap instance. + */ + public TLongLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Long key, Long value) { + long k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongLongMapDecorator.this.containsKey(k) && TLongLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongObjectMapDecorator.java b/src/gnu/trove/decorator/TLongObjectMapDecorator.java new file mode 100644 index 0000000..c59e71f --- /dev/null +++ b/src/gnu/trove/decorator/TLongObjectMapDecorator.java @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongObjectMap; +import gnu.trove.iterator.TLongObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongObjectMap to wrap. + */ + public TLongObjectMapDecorator(TLongObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongObjectMap instance. + */ + public TLongObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Long value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Long key, V value) { + long k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey((Long) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey((Long) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongObjectMapDecorator.this.containsKey(k) && TLongObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long k = it.key(); + final Long key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(((Long) key).longValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Long key) { + return key.longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TLongObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TLongSetDecorator.java b/src/gnu/trove/decorator/TLongSetDecorator.java new file mode 100644 index 0000000..7b4f331 --- /dev/null +++ b/src/gnu/trove/decorator/TLongSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TLongSet; +import gnu.trove.iterator.TLongIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongSet conform to the java.util.Set API. + * This class simply decorates an underlying TLongSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TLongSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TLongSet to wrap. + */ + public TLongSetDecorator(TLongSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TLongSet instance. + */ + public TLongSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Long value) { + return value != null && _set.add(value.longValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Long) { + long v = ((Long) val).longValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Long && _set.remove(((Long) value).longValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TLongIterator it = _set.iterator(); + + @Override + public Long next() { + return Long.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Long)) + return false; + return _set.contains(((Long) o).longValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TLongSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TLongHashSetDecorator diff --git a/src/gnu/trove/decorator/TLongShortMapDecorator.java b/src/gnu/trove/decorator/TLongShortMapDecorator.java new file mode 100644 index 0000000..1fba4f7 --- /dev/null +++ b/src/gnu/trove/decorator/TLongShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TLongShortMap; +import gnu.trove.iterator.TLongShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TLongShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TLongShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TLongShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TLongShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TLongShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TLongShortMap to wrap. + */ + public TLongShortMapDecorator(TLongShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TLongShortMap instance. + */ + public TLongShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Long key, Short value) { + long k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + long k; + if (key != null) { + if (key instanceof Long) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TLongShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TLongShortMapDecorator.this.containsKey(k) && TLongShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TLongShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + long ik = it.key(); + final Long key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Long getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Long key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TLongShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Long && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Long wrapKey(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected long unwrapKey(Object key) { + return ((Long) key).longValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TLongShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TLongShortHashMapDecorator diff --git a/src/gnu/trove/decorator/TObjectByteMapDecorator.java b/src/gnu/trove/decorator/TObjectByteMapDecorator.java new file mode 100644 index 0000000..16cf2dc --- /dev/null +++ b/src/gnu/trove/decorator/TObjectByteMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectByteMap; +import gnu.trove.iterator.TObjectByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectByteMap to wrap. + */ + public TObjectByteMapDecorator(TObjectByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectByteMap instance. + */ + public TObjectByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Byte value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Byte put(K key, Byte value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + byte v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Byte remove(Object key) { + byte v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectByteMapDecorator.this.containsKey(k) && TObjectByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Byte v = wrapValue(it.value()); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectByteMapDecorator diff --git a/src/gnu/trove/decorator/TObjectCharMapDecorator.java b/src/gnu/trove/decorator/TObjectCharMapDecorator.java new file mode 100644 index 0000000..f01e5ae --- /dev/null +++ b/src/gnu/trove/decorator/TObjectCharMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectCharMap; +import gnu.trove.iterator.TObjectCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectCharMap to wrap. + */ + public TObjectCharMapDecorator(TObjectCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectCharMap instance. + */ + public TObjectCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Character value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Character put(K key, Character value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + char v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Character remove(Object key) { + char v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectCharMapDecorator.this.containsKey(k) && TObjectCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Character v = wrapValue(it.value()); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectCharMapDecorator diff --git a/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java b/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java new file mode 100644 index 0000000..333a226 --- /dev/null +++ b/src/gnu/trove/decorator/TObjectDoubleMapDecorator.java @@ -0,0 +1,367 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.iterator.TObjectDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectDoubleMap conform to the + * java.util.Map API. This class simply decorates an underlying + * TObjectDoubleMap and translates the Object-based APIs into their Trove + * primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectDoubleMap to wrap. + */ + public TObjectDoubleMapDecorator(TObjectDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectDoubleMap instance. + */ + public TObjectDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Double value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Double put(K key, Double value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + double v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Double remove(Object key) { + double v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectDoubleMapDecorator.this.containsKey(k) + && TObjectDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Double v = wrapValue(it.value()); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectDoubleMapDecorator diff --git a/src/gnu/trove/decorator/TObjectFloatMapDecorator.java b/src/gnu/trove/decorator/TObjectFloatMapDecorator.java new file mode 100644 index 0000000..3b53d6d --- /dev/null +++ b/src/gnu/trove/decorator/TObjectFloatMapDecorator.java @@ -0,0 +1,366 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.iterator.TObjectFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectFloatMap to wrap. + */ + public TObjectFloatMapDecorator(TObjectFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectFloatMap instance. + */ + public TObjectFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Float value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Float put(K key, Float value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + float v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Float remove(Object key) { + float v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectFloatMapDecorator.this.containsKey(k) + && TObjectFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Float v = wrapValue(it.value()); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectFloatMapDecorator diff --git a/src/gnu/trove/decorator/TObjectIntMapDecorator.java b/src/gnu/trove/decorator/TObjectIntMapDecorator.java new file mode 100644 index 0000000..c03782e --- /dev/null +++ b/src/gnu/trove/decorator/TObjectIntMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectIntMap; +import gnu.trove.iterator.TObjectIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectIntMap to wrap. + */ + public TObjectIntMapDecorator(TObjectIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectIntMap instance. + */ + public TObjectIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Integer value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(K key, Integer value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + int v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Integer remove(Object key) { + int v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectIntMapDecorator.this.containsKey(k) && TObjectIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Integer v = wrapValue(it.value()); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectIntMapDecorator diff --git a/src/gnu/trove/decorator/TObjectLongMapDecorator.java b/src/gnu/trove/decorator/TObjectLongMapDecorator.java new file mode 100644 index 0000000..b714c92 --- /dev/null +++ b/src/gnu/trove/decorator/TObjectLongMapDecorator.java @@ -0,0 +1,365 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.iterator.TObjectLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectLongMap to wrap. + */ + public TObjectLongMapDecorator(TObjectLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectLongMap instance. + */ + public TObjectLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Long value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Long put(K key, Long value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + long v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Long remove(Object key) { + long v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectLongMapDecorator.this.containsKey(k) && TObjectLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Long v = wrapValue(it.value()); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectLongMapDecorator diff --git a/src/gnu/trove/decorator/TObjectShortMapDecorator.java b/src/gnu/trove/decorator/TObjectShortMapDecorator.java new file mode 100644 index 0000000..80d6c2a --- /dev/null +++ b/src/gnu/trove/decorator/TObjectShortMapDecorator.java @@ -0,0 +1,366 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TObjectShortMap; +import gnu.trove.iterator.TObjectShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TObjectShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TObjectShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TObjectShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** + * the wrapped primitive map + */ + protected TObjectShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TObjectShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TObjectShortMap to wrap. + */ + public TObjectShortMapDecorator(TObjectShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TObjectShortMap instance. + */ + public TObjectShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Short value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Short put(K key, Short value) { + if (value == null) + return wrapValue(_map.put(key, _map.getNoEntryValue())); + return wrapValue(_map.put(key, unwrapValue(value))); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + short v = _map.get(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public Short remove(Object key) { + short v = _map.remove(key); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TObjectShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TObjectShortMapDecorator.this.containsKey(k) + && TObjectShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TObjectShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + final K key = it.key(); + final Short v = wrapValue(it.value()); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public K getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + K key = ((Map.Entry) o).getKey(); + _map.remove(key); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TObjectShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return _map.containsKey(key); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return this._map.size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TObjectShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TObjectShortMapDecorator diff --git a/src/gnu/trove/decorator/TShortByteMapDecorator.java b/src/gnu/trove/decorator/TShortByteMapDecorator.java new file mode 100644 index 0000000..307df19 --- /dev/null +++ b/src/gnu/trove/decorator/TShortByteMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortByteMap; +import gnu.trove.iterator.TShortByteIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortByteMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortByteMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortByteMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortByteMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortByteMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortByteMap to wrap. + */ + public TShortByteMapDecorator(TShortByteMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortByteMap instance. + */ + public TShortByteMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Byte(0) if none + * was found. + */ + @Override + public Byte put(Short key, Byte value) { + short k; + byte v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + byte retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Byte get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Byte remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + byte v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortByteMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortByteMapDecorator.this.containsKey(k) && TShortByteMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortByteIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + byte iv = it.value(); + final Byte v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Byte val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Byte getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Byte setValue(Byte value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortByteMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Byte && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Byte wrapValue(byte k) { + return Byte.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected byte unwrapValue(Object value) { + return ((Byte) value).byteValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortByteMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortByteHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortCharMapDecorator.java b/src/gnu/trove/decorator/TShortCharMapDecorator.java new file mode 100644 index 0000000..59cdfe6 --- /dev/null +++ b/src/gnu/trove/decorator/TShortCharMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortCharMap; +import gnu.trove.iterator.TShortCharIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortCharMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortCharMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortCharMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortCharMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortCharMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortCharMap to wrap. + */ + public TShortCharMapDecorator(TShortCharMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortCharMap instance. + */ + public TShortCharMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Character(0) if + * none was found. + */ + @Override + public Character put(Short key, Character value) { + short k; + char v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + char retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Character get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Character remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + char v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortCharMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortCharMapDecorator.this.containsKey(k) && TShortCharMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortCharIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + char iv = it.value(); + final Character v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Character val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Character getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Character setValue(Character value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortCharMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Character && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Character wrapValue(char k) { + return Character.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected char unwrapValue(Object value) { + return ((Character) value).charValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortCharMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortCharHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortDoubleMapDecorator.java b/src/gnu/trove/decorator/TShortDoubleMapDecorator.java new file mode 100644 index 0000000..54ee734 --- /dev/null +++ b/src/gnu/trove/decorator/TShortDoubleMapDecorator.java @@ -0,0 +1,423 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortDoubleMap; +import gnu.trove.iterator.TShortDoubleIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortDoubleMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortDoubleMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortDoubleMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortDoubleMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortDoubleMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortDoubleMap to wrap. + */ + public TShortDoubleMapDecorator(TShortDoubleMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortDoubleMap instance. + */ + public TShortDoubleMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Double(0) if none + * was found. + */ + @Override + public Double put(Short key, Double value) { + short k; + double v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + double retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Double get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Double remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + double v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortDoubleMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortDoubleMapDecorator.this.containsKey(k) + && TShortDoubleMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortDoubleIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + double iv = it.value(); + final Double v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Double val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Double getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Double setValue(Double value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortDoubleMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Double && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Double wrapValue(double k) { + return Double.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected double unwrapValue(Object value) { + return ((Double) value).doubleValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortDoubleMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortDoubleHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortFloatMapDecorator.java b/src/gnu/trove/decorator/TShortFloatMapDecorator.java new file mode 100644 index 0000000..fef28be --- /dev/null +++ b/src/gnu/trove/decorator/TShortFloatMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortFloatMap; +import gnu.trove.iterator.TShortFloatIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortFloatMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortFloatMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortFloatMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortFloatMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortFloatMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortFloatMap to wrap. + */ + public TShortFloatMapDecorator(TShortFloatMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortFloatMap instance. + */ + public TShortFloatMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Float(0) if none + * was found. + */ + @Override + public Float put(Short key, Float value) { + short k; + float v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + float retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Float get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Float remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + float v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortFloatMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortFloatMapDecorator.this.containsKey(k) && TShortFloatMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortFloatIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + float iv = it.value(); + final Float v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Float val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Float getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Float setValue(Float value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortFloatMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Float && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Float wrapValue(float k) { + return Float.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected float unwrapValue(Object value) { + return ((Float) value).floatValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortFloatMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortFloatHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortIntMapDecorator.java b/src/gnu/trove/decorator/TShortIntMapDecorator.java new file mode 100644 index 0000000..e4f4284 --- /dev/null +++ b/src/gnu/trove/decorator/TShortIntMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortIntMap; +import gnu.trove.iterator.TShortIntIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortIntMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortIntMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortIntMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortIntMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortIntMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortIntMap to wrap. + */ + public TShortIntMapDecorator(TShortIntMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortIntMap instance. + */ + public TShortIntMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Integer(0) if + * none was found. + */ + @Override + public Integer put(Short key, Integer value) { + short k; + int v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + int retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Integer get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Integer remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + int v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortIntMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortIntMapDecorator.this.containsKey(k) && TShortIntMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortIntIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + int iv = it.value(); + final Integer v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Integer val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Integer getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Integer setValue(Integer value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortIntMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Integer && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Integer wrapValue(int k) { + return Integer.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected int unwrapValue(Object value) { + return ((Integer) value).intValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortIntMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortIntHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortListDecorator.java b/src/gnu/trove/decorator/TShortListDecorator.java new file mode 100644 index 0000000..51f8332 --- /dev/null +++ b/src/gnu/trove/decorator/TShortListDecorator.java @@ -0,0 +1,137 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.list.TShortList; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.AbstractList; +import java.util.List; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortList conform to the java.util.List + * API. This class simply decorates an underlying TShortList and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * + * @author Robert D. Eden + */ +public class TShortListDecorator extends AbstractList implements List, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive list */ + protected TShortList list; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortListDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param list + * the TShortList to wrap. + */ + public TShortListDecorator(TShortList list) { + super(); + this.list = list; + } + + /** + * Returns a reference to the list wrapped by this decorator. + * + * @return the wrapped TShortList instance. + */ + public TShortList getList() { + return list; + } + + @Override + public int size() { + return list.size(); + } + + @Override + public Short get(int index) { + short value = list.get(index); + if (value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(value); + } + + @Override + public Short set(int index, Short value) { + short previous_value = list.set(index, value); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(previous_value); + } + + @Override + public void add(int index, Short value) { + list.insert(index, value.shortValue()); + } + + @Override + public Short remove(int index) { + short previous_value = list.removeAt(index); + if (previous_value == list.getNoEntryValue()) + return null; + else + return Short.valueOf(previous_value); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + list = (TShortList) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(list); + } + +} diff --git a/src/gnu/trove/decorator/TShortLongMapDecorator.java b/src/gnu/trove/decorator/TShortLongMapDecorator.java new file mode 100644 index 0000000..4c87e0b --- /dev/null +++ b/src/gnu/trove/decorator/TShortLongMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortLongMap; +import gnu.trove.iterator.TShortLongIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortLongMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortLongMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortLongMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortLongMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortLongMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortLongMap to wrap. + */ + public TShortLongMapDecorator(TShortLongMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortLongMap instance. + */ + public TShortLongMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Long(0) if none + * was found. + */ + @Override + public Long put(Short key, Long value) { + short k; + long v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + long retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Long get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Long remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + long v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortLongMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortLongMapDecorator.this.containsKey(k) && TShortLongMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortLongIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + long iv = it.value(); + final Long v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Long val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Long getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Long setValue(Long value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortLongMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Long && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Long wrapValue(long k) { + return Long.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected long unwrapValue(Object value) { + return ((Long) value).longValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortLongMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortLongHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortObjectMapDecorator.java b/src/gnu/trove/decorator/TShortObjectMapDecorator.java new file mode 100644 index 0000000..ec3e311 --- /dev/null +++ b/src/gnu/trove/decorator/TShortObjectMapDecorator.java @@ -0,0 +1,375 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortObjectMap; +import gnu.trove.iterator.TShortObjectIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortObjectMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortObjectMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortObjectMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortObjectMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortObjectMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortObjectMap to wrap. + */ + public TShortObjectMapDecorator(TShortObjectMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortObjectMap instance. + */ + public TShortObjectMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Short value + * @param value + * an Object value + * @return the previous value associated with key, or null if + * none was found. + */ + @Override + public V put(Short key, V value) { + short k; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + return _map.put(k, value); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public V get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey((Short) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.get(k); + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or Integer(0) if it was not found in the map + */ + @Override + public V remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey((Short) key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + return _map.remove(k); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortObjectMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortObjectMapDecorator.this.containsKey(k) + && TShortObjectMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortObjectIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short k = it.key(); + final Short key = (k == _map.getNoEntryKey()) ? null : wrapKey(k); + final V v = it.value(); + return new Map.Entry() { + private V val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public V setValue(V value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortObjectMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return _map.containsValue(val); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(((Short) key).shortValue()); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Short key) { + return key.shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + // noinspection unchecked + _map = (TShortObjectMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortObjectHashMapDecorator diff --git a/src/gnu/trove/decorator/TShortSetDecorator.java b/src/gnu/trove/decorator/TShortSetDecorator.java new file mode 100644 index 0000000..20484ce --- /dev/null +++ b/src/gnu/trove/decorator/TShortSetDecorator.java @@ -0,0 +1,230 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.set.TShortSet; +import gnu.trove.iterator.TShortIterator; + +import java.io.*; +import java.util.AbstractSet; +import java.util.Iterator; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortSet conform to the java.util.Set API. + * This class simply decorates an underlying TShortSet and translates the + * Object-based APIs into their Trove primitive analogs. + *

+ *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ *

+ * Created: Tue Sep 24 22:08:17 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortSetDecorator extends AbstractSet implements Set, Externalizable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive set */ + protected TShortSet _set; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortSetDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive set. + * + * @param set + * the TShortSet to wrap. + */ + public TShortSetDecorator(TShortSet set) { + super(); + this._set = set; + } + + /** + * Returns a reference to the set wrapped by this decorator. + * + * @return the wrapped TShortSet instance. + */ + public TShortSet getSet() { + return _set; + } + + /** + * Inserts a value into the set. + * + * @param value + * true if the set was modified by the insertion + */ + @Override + public boolean add(Short value) { + return value != null && _set.add(value.shortValue()); + } + + /** + * Compares this set with another set for equality of their stored entries. + * + * @param other + * an Object value + * @return true if the sets are identical + */ + @Override + public boolean equals(Object other) { + if (_set.equals(other)) { + return true; // comparing two trove sets + } else if (other instanceof Set) { + Set that = (Set) other; + if (that.size() != _set.size()) { + return false; // different sizes, no need to compare + } else { // now we have to do it the hard way + Iterator it = that.iterator(); + for (int i = that.size(); i-- > 0;) { + Object val = it.next(); + if (val instanceof Short) { + short v = ((Short) val).shortValue(); + if (_set.contains(v)) { + // match, ok to continue + } else { + return false; // no match: we're done + } + } else { + return false; // different type in other set + } + } + return true; // all entries match + } + } else { + return false; + } + } + + /** + * Empties the set. + */ + @Override + public void clear() { + this._set.clear(); + } + + /** + * Deletes a value from the set. + * + * @param value + * an Object value + * @return true if the set was modified + */ + @Override + public boolean remove(Object value) { + return value instanceof Short && _set.remove(((Short) value).shortValue()); + } + + /** + * Creates an iterator over the values of the set. + * + * @return an iterator with support for removals in the underlying set + */ + @Override + public Iterator iterator() { + return new Iterator() { + private final TShortIterator it = _set.iterator(); + + @Override + public Short next() { + return Short.valueOf(it.next()); + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + /** + * Returns the number of entries in the set. + * + * @return the set's size. + */ + @Override + public int size() { + return this._set.size(); + } + + /** + * Indicates whether set has any entries. + * + * @return true if the set is empty + */ + @Override + public boolean isEmpty() { + return this._set.size() == 0; + } + + /** + * {@inheritDoc} + */ + @Override + public boolean contains(Object o) { + if (!(o instanceof Short)) + return false; + return _set.contains(((Short) o).shortValue()); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SET + _set = (TShortSet) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SET + out.writeObject(_set); + } +} // TShortHashSetDecorator diff --git a/src/gnu/trove/decorator/TShortShortMapDecorator.java b/src/gnu/trove/decorator/TShortShortMapDecorator.java new file mode 100644 index 0000000..5bb87a9 --- /dev/null +++ b/src/gnu/trove/decorator/TShortShortMapDecorator.java @@ -0,0 +1,422 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.decorator; + +import gnu.trove.map.TShortShortMap; +import gnu.trove.iterator.TShortShortIterator; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Wrapper class to make a TShortShortMap conform to the java.util.Map + * API. This class simply decorates an underlying TShortShortMap and translates + * the Object-based APIs into their Trove primitive analogs. + *

+ * Note that wrapping and unwrapping primitive values is extremely inefficient. + * If possible, users of this class should override the appropriate methods in + * this class and use a table of canonical values. + *

+ * Created: Mon Sep 23 22:07:40 PDT 2002 + * + * @author Eric D. Friedman + * @author Robert D. Eden + * @author Jeff Randall + */ +public class TShortShortMapDecorator extends AbstractMap + implements Map, Externalizable, Cloneable { + + static final long serialVersionUID = 1L; + + /** the wrapped primitive map */ + protected TShortShortMap _map; + + /** + * FOR EXTERNALIZATION ONLY!! + */ + public TShortShortMapDecorator() { + } + + /** + * Creates a wrapper that decorates the specified primitive map. + * + * @param map + * the TShortShortMap to wrap. + */ + public TShortShortMapDecorator(TShortShortMap map) { + super(); + this._map = map; + } + + /** + * Returns a reference to the map wrapped by this decorator. + * + * @return the wrapped TShortShortMap instance. + */ + public TShortShortMap getMap() { + return _map; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or Short(0) if none + * was found. + */ + @Override + public Short put(Short key, Short value) { + short k; + short v; + if (key == null) { + k = _map.getNoEntryKey(); + } else { + k = unwrapKey(key); + } + if (value == null) { + v = _map.getNoEntryValue(); + } else { + v = unwrapValue(value); + } + short retval = _map.put(k, v); + if (retval == _map.getNoEntryValue()) { + return null; + } + return wrapValue(retval); + } + + /** + * Retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + public Short get(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.get(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Empties the map. + */ + @Override + public void clear() { + this._map.clear(); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return the removed value, or null if it was not found in the map + */ + @Override + public Short remove(Object key) { + short k; + if (key != null) { + if (key instanceof Short) { + k = unwrapKey(key); + } else { + return null; + } + } else { + k = _map.getNoEntryKey(); + } + short v = _map.remove(k); + // There may be a false positive since primitive maps + // cannot return null, so we have to do an extra + // check here. + if (v == _map.getNoEntryValue()) { + return null; + } else { + return wrapValue(v); + } + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new AbstractSet>() { + @Override + public int size() { + return _map.size(); + } + + @Override + public boolean isEmpty() { + return TShortShortMapDecorator.this.isEmpty(); + } + + @Override + public boolean contains(Object o) { + if (o instanceof Map.Entry) { + Object k = ((Map.Entry) o).getKey(); + Object v = ((Map.Entry) o).getValue(); + return TShortShortMapDecorator.this.containsKey(k) && TShortShortMapDecorator.this.get(k).equals(v); + } else { + return false; + } + } + + @Override + public Iterator> iterator() { + return new Iterator>() { + private final TShortShortIterator it = _map.iterator(); + + @Override + public Map.Entry next() { + it.advance(); + short ik = it.key(); + final Short key = (ik == _map.getNoEntryKey()) ? null : wrapKey(ik); + short iv = it.value(); + final Short v = (iv == _map.getNoEntryValue()) ? null : wrapValue(iv); + return new Map.Entry() { + private Short val = v; + + @Override + public boolean equals(Object o) { + return o instanceof Map.Entry && ((Map.Entry) o).getKey().equals(key) + && ((Map.Entry) o).getValue().equals(val); + } + + @Override + public Short getKey() { + return key; + } + + @Override + public Short getValue() { + return val; + } + + @Override + public int hashCode() { + return key.hashCode() + val.hashCode(); + } + + @Override + public Short setValue(Short value) { + val = value; + return put(key, value); + } + }; + } + + @Override + public boolean hasNext() { + return it.hasNext(); + } + + @Override + public void remove() { + it.remove(); + } + }; + } + + @Override + public boolean add(Map.Entry o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(Object o) { + boolean modified = false; + if (contains(o)) { + // noinspection unchecked + Short key = ((Map.Entry) o).getKey(); + _map.remove(unwrapKey(key)); + modified = true; + } + return modified; + } + + @Override + public boolean addAll(Collection> c) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + TShortShortMapDecorator.this.clear(); + } + }; + } + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + return val instanceof Short && _map.containsValue(unwrapValue(val)); + } + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + if (key == null) + return _map.containsKey(_map.getNoEntryKey()); + return key instanceof Short && _map.containsKey(unwrapKey(key)); + } + + /** + * Returns the number of entries in the map. + * + * @return the map's size. + */ + @Override + public int size() { + return this._map.size(); + } + + /** + * Indicates whether map has any entries. + * + * @return true if the map is empty + */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** + * Copies the key/value mappings in map into this map. Note that this + * will be a deep copy, as storage is by primitive value. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + Iterator> it = map.entrySet().iterator(); + for (int i = map.size(); i-- > 0;) { + Entry e = it.next(); + this.put(e.getKey(), e.getValue()); + } + } + + /** + * Wraps a key + * + * @param k + * key in the underlying map + * @return an Object representation of the key + */ + protected Short wrapKey(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a key + * + * @param key + * wrapped key + * @return an unwrapped representation of the key + */ + protected short unwrapKey(Object key) { + return ((Short) key).shortValue(); + } + + /** + * Wraps a value + * + * @param k + * value in the underlying map + * @return an Object representation of the value + */ + protected Short wrapValue(short k) { + return Short.valueOf(k); + } + + /** + * Unwraps a value + * + * @param value + * wrapped value + * @return an unwrapped representation of the value + */ + protected short unwrapValue(Object value) { + return ((Short) value).shortValue(); + } + + // Implements Externalizable + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // MAP + _map = (TShortShortMap) in.readObject(); + } + + // Implements Externalizable + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // MAP + out.writeObject(_map); + } + +} // TShortShortHashMapDecorator diff --git a/src/gnu/trove/function/TByteFunction.java b/src/gnu/trove/function/TByteFunction.java new file mode 100644 index 0000000..b49e333 --- /dev/null +++ b/src/gnu/trove/function/TByteFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one byte primitive. + */ +public interface TByteFunction { + /** + * Execute this function with value + * + * @param value + * a byte input + * @return a byte result + */ + public byte execute(byte value); +} diff --git a/src/gnu/trove/function/TCharFunction.java b/src/gnu/trove/function/TCharFunction.java new file mode 100644 index 0000000..15a4441 --- /dev/null +++ b/src/gnu/trove/function/TCharFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one char primitive. + */ +public interface TCharFunction { + /** + * Execute this function with value + * + * @param value + * a char input + * @return a char result + */ + public char execute(char value); +} diff --git a/src/gnu/trove/function/TDoubleFunction.java b/src/gnu/trove/function/TDoubleFunction.java new file mode 100644 index 0000000..1c92410 --- /dev/null +++ b/src/gnu/trove/function/TDoubleFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one double primitive. + */ +public interface TDoubleFunction { + /** + * Execute this function with value + * + * @param value + * a double input + * @return a double result + */ + public double execute(double value); +} diff --git a/src/gnu/trove/function/TFloatFunction.java b/src/gnu/trove/function/TFloatFunction.java new file mode 100644 index 0000000..999ce5f --- /dev/null +++ b/src/gnu/trove/function/TFloatFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one float primitive. + */ +public interface TFloatFunction { + /** + * Execute this function with value + * + * @param value + * a float input + * @return a float result + */ + public float execute(float value); +} diff --git a/src/gnu/trove/function/TIntFunction.java b/src/gnu/trove/function/TIntFunction.java new file mode 100644 index 0000000..7246f93 --- /dev/null +++ b/src/gnu/trove/function/TIntFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one int primitive. + */ +public interface TIntFunction { + /** + * Execute this function with value + * + * @param value + * a int input + * @return a int result + */ + public int execute(int value); +} diff --git a/src/gnu/trove/function/TLongFunction.java b/src/gnu/trove/function/TLongFunction.java new file mode 100644 index 0000000..dbd6663 --- /dev/null +++ b/src/gnu/trove/function/TLongFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one long primitive. + */ +public interface TLongFunction { + /** + * Execute this function with value + * + * @param value + * a long input + * @return a long result + */ + public long execute(long value); +} diff --git a/src/gnu/trove/function/TObjectFunction.java b/src/gnu/trove/function/TObjectFunction.java new file mode 100644 index 0000000..6ecd144 --- /dev/null +++ b/src/gnu/trove/function/TObjectFunction.java @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +/** + * Interface for functions that accept and return one Object reference. + *

+ * Created: Mon Nov 5 22:19:36 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectFunction.java,v 1.1.2.1 2009/09/06 17:02:19 + * upholderoftruth Exp $ + */ + +public interface TObjectFunction { + + /** + * Execute this function with value + * + * @param value + * an Object input + * @return an Object result + */ + public R execute(T value); +}// TObjectFunction diff --git a/src/gnu/trove/function/TShortFunction.java b/src/gnu/trove/function/TShortFunction.java new file mode 100644 index 0000000..f1e20a3 --- /dev/null +++ b/src/gnu/trove/function/TShortFunction.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.function; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for functions that accept and return one short primitive. + */ +public interface TShortFunction { + /** + * Execute this function with value + * + * @param value + * a short input + * @return a short result + */ + public short execute(short value); +} diff --git a/src/gnu/trove/impl/Constants.java b/src/gnu/trove/impl/Constants.java new file mode 100644 index 0000000..56b45a4 --- /dev/null +++ b/src/gnu/trove/impl/Constants.java @@ -0,0 +1,227 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// +package gnu.trove.impl; + +/** + * Central location for constants needed by various implementations. + */ +public class Constants { + + private static final boolean VERBOSE; + static { + boolean verbose = false; + try { + verbose = System.getProperty("gnu.trove.verbose", null) != null; + } catch (SecurityException ex) { + // ignore + } + VERBOSE = verbose; + } + + /** the default capacity for new collections */ + public static final int DEFAULT_CAPACITY = 10; + + /** the load above which rehashing occurs. */ + public static final float DEFAULT_LOAD_FACTOR = 0.5f; + + /** the default value that represents for byte types. */ + public static final byte DEFAULT_BYTE_NO_ENTRY_VALUE; + static { + byte value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.byte", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Byte.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Byte.MIN_VALUE; + else + value = Byte.valueOf(property); + + if (value > Byte.MAX_VALUE) + value = Byte.MAX_VALUE; + else if (value < Byte.MIN_VALUE) + value = Byte.MIN_VALUE; + DEFAULT_BYTE_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_BYTE_NO_ENTRY_VALUE: " + DEFAULT_BYTE_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for short types. */ + public static final short DEFAULT_SHORT_NO_ENTRY_VALUE; + static { + short value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.short", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Short.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Short.MIN_VALUE; + else + value = Short.valueOf(property); + + if (value > Short.MAX_VALUE) + value = Short.MAX_VALUE; + else if (value < Short.MIN_VALUE) + value = Short.MIN_VALUE; + DEFAULT_SHORT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_SHORT_NO_ENTRY_VALUE: " + DEFAULT_SHORT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for char types. */ + public static final char DEFAULT_CHAR_NO_ENTRY_VALUE; + static { + char value; + String property = "\0"; + try { + property = System.getProperty("gnu.trove.no_entry.char", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Character.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Character.MIN_VALUE; + else + value = property.toCharArray()[0]; + + if (value > Character.MAX_VALUE) + value = Character.MAX_VALUE; + else if (value < Character.MIN_VALUE) + value = Character.MIN_VALUE; + DEFAULT_CHAR_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_CHAR_NO_ENTRY_VALUE: " + Integer.valueOf(value)); + } + } + + /** the default value that represents for int types. */ + public static final int DEFAULT_INT_NO_ENTRY_VALUE; + static { + int value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.int", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Integer.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Integer.MIN_VALUE; + else + value = Integer.valueOf(property); + DEFAULT_INT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_INT_NO_ENTRY_VALUE: " + DEFAULT_INT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for long types. */ + public static final long DEFAULT_LONG_NO_ENTRY_VALUE; + static { + long value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.long", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Long.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Long.MIN_VALUE; + else + value = Long.valueOf(property); + DEFAULT_LONG_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_LONG_NO_ENTRY_VALUE: " + DEFAULT_LONG_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for float types. */ + public static final float DEFAULT_FLOAT_NO_ENTRY_VALUE; + static { + float value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.float", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Float.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Float.MIN_VALUE; + // Value from Float.MIN_NORMAL (introduced in 1.6) + else if ("MIN_NORMAL".equalsIgnoreCase(property)) + value = 0x1.0p-126f; + else if ("NEGATIVE_INFINITY".equalsIgnoreCase(property)) + value = Float.NEGATIVE_INFINITY; + else if ("POSITIVE_INFINITY".equalsIgnoreCase(property)) + value = Float.POSITIVE_INFINITY; + // else if ( "NaN".equalsIgnoreCase( property ) ) value = Float.NaN; + else + value = Float.valueOf(property); + DEFAULT_FLOAT_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_FLOAT_NO_ENTRY_VALUE: " + DEFAULT_FLOAT_NO_ENTRY_VALUE); + } + } + + /** the default value that represents for double types. */ + public static final double DEFAULT_DOUBLE_NO_ENTRY_VALUE; + static { + double value; + String property = "0"; + try { + property = System.getProperty("gnu.trove.no_entry.double", property); + } catch (SecurityException ex) { + // ignore + } + if ("MAX_VALUE".equalsIgnoreCase(property)) + value = Double.MAX_VALUE; + else if ("MIN_VALUE".equalsIgnoreCase(property)) + value = Double.MIN_VALUE; + // Value from Double.MIN_NORMAL (introduced in 1.6) + else if ("MIN_NORMAL".equalsIgnoreCase(property)) + value = 0x1.0p-1022; + else if ("NEGATIVE_INFINITY".equalsIgnoreCase(property)) + value = Double.NEGATIVE_INFINITY; + else if ("POSITIVE_INFINITY".equalsIgnoreCase(property)) + value = Double.POSITIVE_INFINITY; + // else if ( "NaN".equalsIgnoreCase( property ) ) value = Double.NaN; + else + value = Double.valueOf(property); + DEFAULT_DOUBLE_NO_ENTRY_VALUE = value; + if (VERBOSE) { + System.out.println("DEFAULT_DOUBLE_NO_ENTRY_VALUE: " + DEFAULT_DOUBLE_NO_ENTRY_VALUE); + } + } +} diff --git a/src/gnu/trove/impl/HashFunctions.java b/src/gnu/trove/impl/HashFunctions.java new file mode 100644 index 0000000..fcfc899 --- /dev/null +++ b/src/gnu/trove/impl/HashFunctions.java @@ -0,0 +1,85 @@ +// Copyright (c) 1999 CERN - European Organization for Nuclear Research. + +// Permission to use, copy, modify, distribute and sell this software and +// its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and that +// both that copyright notice and this permission notice appear in +// supporting documentation. CERN makes no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without expressed or implied warranty. + +package gnu.trove.impl; + +/** + * Provides various hash functions. + * + * @author wolfgang.hoschek@cern.ch + * @version 1.0, 09/24/99 + */ +public final class HashFunctions { + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(double value) { + assert !Double.isNaN(value) : "Values of NaN are not supported."; + + long bits = Double.doubleToLongBits(value); + return (int) (bits ^ (bits >>> 32)); + // return (int) Double.doubleToLongBits(value*663608941.737); + // this avoids excessive hashCollisions in the case values are + // of the form (1.0, 2.0, 3.0, ...) + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(float value) { + assert !Float.isNaN(value) : "Values of NaN are not supported."; + + return Float.floatToIntBits(value * 663608941.737f); + // this avoids excessive hashCollisions in the case values are + // of the form (1.0, 2.0, 3.0, ...) + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(int value) { + return value; + } + + /** + * Returns a hashcode for the specified value. + * + * @return a hash code value for the specified value. + */ + public static int hash(long value) { + return ((int) (value ^ (value >>> 32))); + } + + /** + * Returns a hashcode for the specified object. + * + * @return a hash code value for the specified object. + */ + public static int hash(Object object) { + return object == null ? 0 : object.hashCode(); + } + + /** + * In profiling, it has been found to be faster to have our own local + * implementation of "ceil" rather than to call to {@link Math#ceil(double)}. + */ + public static int fastCeil(float v) { + int possible_result = (int) v; + if (v - possible_result > 0) + possible_result++; + return possible_result; + } +} diff --git a/src/gnu/trove/impl/PrimeFinder.java b/src/gnu/trove/impl/PrimeFinder.java new file mode 100644 index 0000000..9d0509d --- /dev/null +++ b/src/gnu/trove/impl/PrimeFinder.java @@ -0,0 +1,151 @@ +// Copyright (c) 1999 CERN - European Organization for Nuclear Research. + +// Permission to use, copy, modify, distribute and sell this software +// and its documentation for any purpose is hereby granted without fee, +// provided that the above copyright notice appear in all copies and +// that both that copyright notice and this permission notice appear in +// supporting documentation. CERN makes no representations about the +// suitability of this software for any purpose. It is provided "as is" +// without expressed or implied warranty. +package gnu.trove.impl; + +import java.util.Arrays; + +/* + * Modified for Trove to use the java.util.Arrays sort/search + * algorithms instead of those provided with colt. + */ + +/** + * Used to keep hash table capacities prime numbers. Not of interest for users; + * only for implementors of hashtables. + * + *

+ * Choosing prime numbers as hash table capacities is a good idea to keep them + * working fast, particularly under hash table expansions. + * + *

+ * However, JDK 1.2, JGL 3.1 and many other toolkits do nothing to keep + * capacities prime. This class provides efficient means to choose prime + * capacities. + * + *

+ * Choosing a prime is O(log 300) (binary search in a list of 300 + * ints). Memory requirements: 1 KB static memory. + * + * @author wolfgang.hoschek@cern.ch + * @version 1.0, 09/24/99 + */ +public final class PrimeFinder { + /** + * The largest prime this class can generate; currently equal to + * Integer.MAX_VALUE. + */ + public static final int largestPrime = Integer.MAX_VALUE; // yes, it is prime. + + /** + * The prime number list consists of 11 chunks. + * + * Each chunk contains prime numbers. + * + * A chunk starts with a prime P1. The next element is a prime P2. P2 is the + * smallest prime for which holds: P2 >= 2*P1. + * + * The next element is P3, for which the same holds with respect to P2, and so + * on. + * + * Chunks are chosen such that for any desired capacity >= 1000 the list + * includes a prime number <= desired capacity * 1.11. + * + * Therefore, primes can be retrieved which are quite close to any desired + * capacity, which in turn avoids wasting memory. + * + * For example, the list includes + * 1039,1117,1201,1277,1361,1439,1523,1597,1759,1907,2081. + * + * So if you need a prime >= 1040, you will find a prime <= 1040*1.11=1154. + * + * Chunks are chosen such that they are optimized for a hashtable growthfactor + * of 2.0; + * + * If your hashtable has such a growthfactor then, after initially "rounding to + * a prime" upon hashtable construction, it will later expand to prime + * capacities such that there exist no better primes. + * + * In total these are about 32*10=320 numbers -> 1 KB of static memory needed. + * + * If you are stingy, then delete every second or fourth chunk. + */ + + private static final int[] primeCapacities = { + // chunk #0 + largestPrime, + + // chunk #1 + 5, 11, 23, 47, 97, 197, 397, 797, 1597, 3203, 6421, 12853, 25717, 51437, 102877, 205759, 411527, 823117, + 1646237, 3292489, 6584983, 13169977, 26339969, 52679969, 105359939, 210719881, 421439783, 842879579, + 1685759167, + + // chunk #2 + 433, 877, 1759, 3527, 7057, 14143, 28289, 56591, 113189, 226379, 452759, 905551, 1811107, 3622219, 7244441, + 14488931, 28977863, 57955739, 115911563, 231823147, 463646329, 927292699, 1854585413, + + // chunk #3 + 953, 1907, 3821, 7643, 15287, 30577, 61169, 122347, 244703, 489407, 978821, 1957651, 3915341, 7830701, + 15661423, 31322867, 62645741, 125291483, 250582987, 501165979, 1002331963, 2004663929, + + // chunk #4 + 1039, 2081, 4177, 8363, 16729, 33461, 66923, 133853, 267713, 535481, 1070981, 2141977, 4283963, 8567929, + 17135863, 34271747, 68543509, 137087021, 274174111, 548348231, 1096696463, + + // chunk #5 + 31, 67, 137, 277, 557, 1117, 2237, 4481, 8963, 17929, 35863, 71741, 143483, 286973, 573953, 1147921, + 2295859, 4591721, 9183457, 18366923, 36733847, 73467739, 146935499, 293871013, 587742049, 1175484103, + + // chunk #6 + 599, 1201, 2411, 4831, 9677, 19373, 38747, 77509, 155027, 310081, 620171, 1240361, 2480729, 4961459, + 9922933, 19845871, 39691759, 79383533, 158767069, 317534141, 635068283, 1270136683, + + // chunk #7 + 311, 631, 1277, 2557, 5119, 10243, 20507, 41017, 82037, 164089, 328213, 656429, 1312867, 2625761, 5251529, + 10503061, 21006137, 42012281, 84024581, 168049163, 336098327, 672196673, 1344393353, + + // chunk #8 + 3, 7, 17, 37, 79, 163, 331, 673, 1361, 2729, 5471, 10949, 21911, 43853, 87719, 175447, 350899, 701819, + 1403641, 2807303, 5614657, 11229331, 22458671, 44917381, 89834777, 179669557, 359339171, 718678369, + 1437356741, + + // chunk #9 + 43, 89, 179, 359, 719, 1439, 2879, 5779, 11579, 23159, 46327, 92657, 185323, 370661, 741337, 1482707, + 2965421, 5930887, 11861791, 23723597, 47447201, 94894427, 189788857, 379577741, 759155483, 1518310967, + + // chunk #10 + 379, 761, 1523, 3049, 6101, 12203, 24407, 48817, 97649, 195311, 390647, 781301, 1562611, 3125257, 6250537, + 12501169, 25002389, 50004791, 100009607, 200019221, 400038451, 800076929, 1600153859 }; + + static { // initializer + // The above prime numbers are formatted for human readability. + // To find numbers fast, we sort them once and for all. + + Arrays.sort(primeCapacities); + } + + /** + * Returns a prime number which is >= desiredCapacity and very + * close to desiredCapacity (within 11% if + * desiredCapacity >= 1000). + * + * @param desiredCapacity + * the capacity desired by the user. + * @return the capacity which should be used for a hashtable. + */ + public static final int nextPrime(int desiredCapacity) { + int i = Arrays.binarySearch(primeCapacities, desiredCapacity); + if (i < 0) { + // desired capacity not found, choose next prime greater + // than desired capacity + i = -i - 1; // remember the semantics of binarySearch... + } + return primeCapacities[i]; + } +} diff --git a/src/gnu/trove/impl/hash/TByteByteHash.java b/src/gnu/trove/impl/hash/TByteByteHash.java new file mode 100644 index 0000000..72de7d2 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteByteHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TByteByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TByteByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteByteHash(int initialCapacity, float loadFactor, byte no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TByteByteHash diff --git a/src/gnu/trove/impl/hash/TByteCharHash.java b/src/gnu/trove/impl/hash/TByteCharHash.java new file mode 100644 index 0000000..8bf34be --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteCharHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TByteCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TByteCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteCharHash(int initialCapacity, float loadFactor, byte no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TByteCharHash diff --git a/src/gnu/trove/impl/hash/TByteDoubleHash.java b/src/gnu/trove/impl/hash/TByteDoubleHash.java new file mode 100644 index 0000000..1da09ee --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteDoubleHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteDoubleHash(int initialCapacity, float loadFactor, byte no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TByteDoubleHash diff --git a/src/gnu/trove/impl/hash/TByteFloatHash.java b/src/gnu/trove/impl/hash/TByteFloatHash.java new file mode 100644 index 0000000..7f4c542 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteFloatHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteFloatHash(int initialCapacity, float loadFactor, byte no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TByteFloatHash diff --git a/src/gnu/trove/impl/hash/TByteHash.java b/src/gnu/trove/impl/hash/TByteHash.java new file mode 100644 index 0000000..71c59c9 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TByteHash instance with the default capacity and + * load factor. + */ + public TByteHash() { + super(); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteHash(int initialCapacity, float loadFactor, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte val) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TByteHash diff --git a/src/gnu/trove/impl/hash/TByteIntHash.java b/src/gnu/trove/impl/hash/TByteIntHash.java new file mode 100644 index 0000000..c5e3820 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteIntHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteIntHash(int initialCapacity, float loadFactor, byte no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TByteIntHash diff --git a/src/gnu/trove/impl/hash/TByteLongHash.java b/src/gnu/trove/impl/hash/TByteLongHash.java new file mode 100644 index 0000000..36295bd --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteLongHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = 0; + } + + /** + * Creates a new TByteLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteLongHash(int initialCapacity, float loadFactor, byte no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TByteLongHash diff --git a/src/gnu/trove/impl/hash/TByteShortHash.java b/src/gnu/trove/impl/hash/TByteShortHash.java new file mode 100644 index 0000000..51c1597 --- /dev/null +++ b/src/gnu/trove/impl/hash/TByteShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for byte/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TByteShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of bytes */ + public transient byte[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TByteShortHash() { + super(); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TByteShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TByteShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (byte) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TByteShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TByteShortHash(int initialCapacity, float loadFactor, byte no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new byte[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean contains(byte val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TByteProcedure procedure) { + byte[] states = _states; + byte[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an byte value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(byte key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an byte value + * @return an int value + */ + protected int insertKey(byte val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(byte val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, byte val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(byte key) { + int hash, probe, index, length; + + final byte[] states = _states; + final byte[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TByteShortHash diff --git a/src/gnu/trove/impl/hash/TCharByteHash.java b/src/gnu/trove/impl/hash/TCharByteHash.java new file mode 100644 index 0000000..35c7524 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharByteHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TCharByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TCharByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharByteHash(int initialCapacity, float loadFactor, char no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TCharByteHash diff --git a/src/gnu/trove/impl/hash/TCharCharHash.java b/src/gnu/trove/impl/hash/TCharCharHash.java new file mode 100644 index 0000000..2674cca --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharCharHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TCharCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TCharCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharCharHash(int initialCapacity, float loadFactor, char no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TCharCharHash diff --git a/src/gnu/trove/impl/hash/TCharDoubleHash.java b/src/gnu/trove/impl/hash/TCharDoubleHash.java new file mode 100644 index 0000000..880f918 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharDoubleHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharDoubleHash(int initialCapacity, float loadFactor, char no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TCharDoubleHash diff --git a/src/gnu/trove/impl/hash/TCharFloatHash.java b/src/gnu/trove/impl/hash/TCharFloatHash.java new file mode 100644 index 0000000..e911645 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharFloatHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharFloatHash(int initialCapacity, float loadFactor, char no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TCharFloatHash diff --git a/src/gnu/trove/impl/hash/TCharHash.java b/src/gnu/trove/impl/hash/TCharHash.java new file mode 100644 index 0000000..7b1c501 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TCharHash instance with the default capacity and + * load factor. + */ + public TCharHash() { + super(); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharHash(int initialCapacity, float loadFactor, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char val) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TCharHash diff --git a/src/gnu/trove/impl/hash/TCharIntHash.java b/src/gnu/trove/impl/hash/TCharIntHash.java new file mode 100644 index 0000000..1305ba7 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharIntHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharIntHash(int initialCapacity, float loadFactor, char no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TCharIntHash diff --git a/src/gnu/trove/impl/hash/TCharLongHash.java b/src/gnu/trove/impl/hash/TCharLongHash.java new file mode 100644 index 0000000..dec1ba5 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharLongHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = 0; + } + + /** + * Creates a new TCharLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharLongHash(int initialCapacity, float loadFactor, char no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TCharLongHash diff --git a/src/gnu/trove/impl/hash/TCharShortHash.java b/src/gnu/trove/impl/hash/TCharShortHash.java new file mode 100644 index 0000000..29c6325 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCharShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for char/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TCharShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of chars */ + public transient char[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TCharShortHash() { + super(); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TCharShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TCharShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (char) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TCharShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TCharShortHash(int initialCapacity, float loadFactor, char no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new char[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an char value + * @return a boolean value + */ + public boolean contains(char val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TCharProcedure procedure) { + byte[] states = _states; + char[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an char value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(char key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an char value + * @return an int value + */ + protected int insertKey(char val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(char val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, char val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(char key) { + int hash, probe, index, length; + + final byte[] states = _states; + final char[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TCharShortHash diff --git a/src/gnu/trove/impl/hash/TCustomObjectHash.java b/src/gnu/trove/impl/hash/TCustomObjectHash.java new file mode 100644 index 0000000..32a4847 --- /dev/null +++ b/src/gnu/trove/impl/hash/TCustomObjectHash.java @@ -0,0 +1,125 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.strategy.HashingStrategy; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; + +/** + * An open addressed hashing implementation for Object types. + * + * @author Rob Eden + * @author Eric D. Friedman + * @author Jeff Randall + * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +@SuppressWarnings({ "UnusedDeclaration" }) +abstract public class TCustomObjectHash extends TObjectHash { + static final long serialVersionUID = 8766048185963756400L; + + protected HashingStrategy strategy; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomObjectHash() { + } + + /** + * Creates a new TManualObjectHash instance with the default + * capacity and load factor. + */ + public TCustomObjectHash(HashingStrategy strategy) { + super(); + + this.strategy = strategy; + } + + /** + * Creates a new TManualObjectHash instance whose capacity is the + * next highest prime above initialCapacity + 1 unless that value is + * already prime. + * + * @param initialCapacity + * an int value + */ + public TCustomObjectHash(HashingStrategy strategy, int initialCapacity) { + super(initialCapacity); + + this.strategy = strategy; + } + + /** + * Creates a new TManualObjectHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TCustomObjectHash(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(initialCapacity, loadFactor); + + this.strategy = strategy; + } + + @Override + protected int hash(Object obj) { + // noinspection unchecked + return strategy.computeHashCode((T) obj); + } + + @Override + protected boolean equals(Object one, Object two) { + // noinspection unchecked + return two != REMOVED && strategy.equals((T) one, (T) two); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + // noinspection unchecked + strategy = (HashingStrategy) in.readObject(); + } +} // TCustomObjectHash diff --git a/src/gnu/trove/impl/hash/TDoubleByteHash.java b/src/gnu/trove/impl/hash/TDoubleByteHash.java new file mode 100644 index 0000000..4b59192 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TDoubleByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TDoubleByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleByteHash(int initialCapacity, float loadFactor, double no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TDoubleByteHash diff --git a/src/gnu/trove/impl/hash/TDoubleCharHash.java b/src/gnu/trove/impl/hash/TDoubleCharHash.java new file mode 100644 index 0000000..dde1f90 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TDoubleCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TDoubleCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleCharHash(int initialCapacity, float loadFactor, double no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TDoubleCharHash diff --git a/src/gnu/trove/impl/hash/TDoubleDoubleHash.java b/src/gnu/trove/impl/hash/TDoubleDoubleHash.java new file mode 100644 index 0000000..af43a94 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleDoubleHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleDoubleHash instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleDoubleHash(int initialCapacity, float loadFactor, double no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TDoubleDoubleHash diff --git a/src/gnu/trove/impl/hash/TDoubleFloatHash.java b/src/gnu/trove/impl/hash/TDoubleFloatHash.java new file mode 100644 index 0000000..145dbbd --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleFloatHash(int initialCapacity, float loadFactor, double no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TDoubleFloatHash diff --git a/src/gnu/trove/impl/hash/TDoubleHash.java b/src/gnu/trove/impl/hash/TDoubleHash.java new file mode 100644 index 0000000..17cb9d2 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TDoubleHash instance with the default capacity and + * load factor. + */ + public TDoubleHash() { + super(); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleHash(int initialCapacity, float loadFactor, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double val) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TDoubleHash diff --git a/src/gnu/trove/impl/hash/TDoubleIntHash.java b/src/gnu/trove/impl/hash/TDoubleIntHash.java new file mode 100644 index 0000000..459e0ae --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleIntHash(int initialCapacity, float loadFactor, double no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TDoubleIntHash diff --git a/src/gnu/trove/impl/hash/TDoubleLongHash.java b/src/gnu/trove/impl/hash/TDoubleLongHash.java new file mode 100644 index 0000000..191b996 --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TDoubleLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleLongHash(int initialCapacity, float loadFactor, double no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TDoubleLongHash diff --git a/src/gnu/trove/impl/hash/TDoubleShortHash.java b/src/gnu/trove/impl/hash/TDoubleShortHash.java new file mode 100644 index 0000000..354a04b --- /dev/null +++ b/src/gnu/trove/impl/hash/TDoubleShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for double/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TDoubleShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of doubles */ + public transient double[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TDoubleShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TDoubleShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TDoubleShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TDoubleShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TDoubleShortHash(int initialCapacity, float loadFactor, double no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new double[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an double value + * @return a boolean value + */ + public boolean contains(double val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TDoubleProcedure procedure) { + byte[] states = _states; + double[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an double value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(double key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an double value + * @return an int value + */ + protected int insertKey(double val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(double val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, double val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(double key) { + int hash, probe, index, length; + + final byte[] states = _states; + final double[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TDoubleShortHash diff --git a/src/gnu/trove/impl/hash/TFloatByteHash.java b/src/gnu/trove/impl/hash/TFloatByteHash.java new file mode 100644 index 0000000..aa5bc98 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TFloatByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TFloatByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatByteHash(int initialCapacity, float loadFactor, float no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TFloatByteHash diff --git a/src/gnu/trove/impl/hash/TFloatCharHash.java b/src/gnu/trove/impl/hash/TFloatCharHash.java new file mode 100644 index 0000000..f510a78 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TFloatCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TFloatCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatCharHash(int initialCapacity, float loadFactor, float no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TFloatCharHash diff --git a/src/gnu/trove/impl/hash/TFloatDoubleHash.java b/src/gnu/trove/impl/hash/TFloatDoubleHash.java new file mode 100644 index 0000000..2a66bf8 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatDoubleHash(int initialCapacity, float loadFactor, float no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TFloatDoubleHash diff --git a/src/gnu/trove/impl/hash/TFloatFloatHash.java b/src/gnu/trove/impl/hash/TFloatFloatHash.java new file mode 100644 index 0000000..6eaffee --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatFloatHash(int initialCapacity, float loadFactor, float no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TFloatFloatHash diff --git a/src/gnu/trove/impl/hash/TFloatHash.java b/src/gnu/trove/impl/hash/TFloatHash.java new file mode 100644 index 0000000..0561b88 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TFloatHash instance with the default capacity and + * load factor. + */ + public TFloatHash() { + super(); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatHash(int initialCapacity, float loadFactor, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float val) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TFloatHash diff --git a/src/gnu/trove/impl/hash/TFloatIntHash.java b/src/gnu/trove/impl/hash/TFloatIntHash.java new file mode 100644 index 0000000..e0fa7d3 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatIntHash(int initialCapacity, float loadFactor, float no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TFloatIntHash diff --git a/src/gnu/trove/impl/hash/TFloatLongHash.java b/src/gnu/trove/impl/hash/TFloatLongHash.java new file mode 100644 index 0000000..e766b89 --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TFloatLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatLongHash(int initialCapacity, float loadFactor, float no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TFloatLongHash diff --git a/src/gnu/trove/impl/hash/TFloatShortHash.java b/src/gnu/trove/impl/hash/TFloatShortHash.java new file mode 100644 index 0000000..f49413e --- /dev/null +++ b/src/gnu/trove/impl/hash/TFloatShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for float/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TFloatShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of floats */ + public transient float[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TFloatShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TFloatShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TFloatShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TFloatShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TFloatShortHash(int initialCapacity, float loadFactor, float no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new float[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an float value + * @return a boolean value + */ + public boolean contains(float val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TFloatProcedure procedure) { + byte[] states = _states; + float[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an float value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(float key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an float value + * @return an int value + */ + protected int insertKey(float val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(float val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, float val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(float key) { + int hash, probe, index, length; + + final byte[] states = _states; + final float[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TFloatShortHash diff --git a/src/gnu/trove/impl/hash/THash.java b/src/gnu/trove/impl/hash/THash.java new file mode 100644 index 0000000..855d75b --- /dev/null +++ b/src/gnu/trove/impl/hash/THash.java @@ -0,0 +1,406 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.PrimeFinder; + +import java.io.Externalizable; +import java.io.ObjectOutput; +import java.io.IOException; +import java.io.ObjectInput; + +/** + * Base class for hashtables that use open addressing to resolve collisions. + * + * Created: Wed Nov 28 21:11:16 2001 + * + * @author Eric D. Friedman + * @author Rob Eden (auto-compaction) + * @author Jeff Randall + * + * @version $Id: THash.java,v 1.1.2.4 2010/03/02 00:55:34 robeden Exp $ + */ +abstract public class THash implements Externalizable { + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = -1792948471915530295L; + + /** the load above which rehashing occurs. */ + protected static final float DEFAULT_LOAD_FACTOR = Constants.DEFAULT_LOAD_FACTOR; + + /** + * the default initial capacity for the hash table. This is one less than a + * prime value because one is added to it when searching for a prime capacity to + * account for the free slot required by open addressing. Thus, the real default + * capacity is 11. + */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the current number of occupied slots in the hash. */ + protected transient int _size; + + /** the current number of free slots in the hash. */ + protected transient int _free; + + /** + * Determines how full the internal table can become before rehashing is + * required. This must be a value in the range: 0.0 < loadFactor < 1.0. The + * default value is 0.5, which is about as large as you can get in open + * addressing without hurting performance. Cf. Knuth, Volume 3., Chapter 6. + */ + protected float _loadFactor; + + /** + * The maximum number of elements allowed without allocating more space. + */ + protected int _maxSize; + + /** + * The number of removes that should be performed before an auto-compaction + * occurs. + */ + protected int _autoCompactRemovesRemaining; + + /** + * The auto-compaction factor for the table. + * + * @see #setAutoCompactionFactor + */ + protected float _autoCompactionFactor; + + /** @see #tempDisableAutoCompaction */ + protected transient boolean _autoCompactTemporaryDisable = false; + + /** + * Creates a new THash instance with the default capacity and load + * factor. + */ + public THash() { + this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new THash instance with a prime capacity at or near + * the specified capacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THash(int initialCapacity) { + this(initialCapacity, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new THash instance with a prime capacity at or near + * the minimum needed to hold initialCapacity elements with load factor + * loadFactor without triggering a rehash. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THash(int initialCapacity, float loadFactor) { + super(); + _loadFactor = loadFactor; + + // Through testing, the load factor (especially the default load factor) has + // been + // found to be a pretty good starting auto-compaction factor. + _autoCompactionFactor = loadFactor; + + setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); + } + + /** + * Tells whether this set is currently holding any elements. + * + * @return a boolean value + */ + public boolean isEmpty() { + return 0 == _size; + } + + /** + * Returns the number of distinct elements in this collection. + * + * @return an int value + */ + public int size() { + return _size; + } + + /** @return the current physical capacity of the hash table. */ + abstract public int capacity(); + + /** + * Ensure that this hashtable has sufficient capacity to hold + * desiredCapacity additional elements without + * requiring a rehash. This is a tuning method you can call + * before doing a large insert. + * + * @param desiredCapacity an int value + */ + public void ensureCapacity(int desiredCapacity) { + if (desiredCapacity > (_maxSize - size())) { + rehash(PrimeFinder.nextPrime( + Math.max(size() + 1, HashFunctions.fastCeil((desiredCapacity + size()) / _loadFactor) + 1))); + computeMaxSize(capacity()); + } + } + + /** + * Compresses the hashtable to the minimum prime size (as defined by + * PrimeFinder) that will hold all of the elements currently in the table. If + * you have done a lot of remove operations and plan to do a lot of + * queries or insertions or iteration, it is a good idea to invoke this method. + * Doing so will accomplish two things: + *

+ *

    + *
  1. You'll free memory allocated to the table but no longer needed because of + * the remove()s.
  2. + *

    + *

  3. You'll get better query/insert/iterator performance because there won't + * be any REMOVED slots to skip over when probing for indices in the + * table.
  4. + *
+ */ + public void compact() { + // need at least one free spot for open addressing + rehash(PrimeFinder.nextPrime(Math.max(_size + 1, HashFunctions.fastCeil(size() / _loadFactor) + 1))); + computeMaxSize(capacity()); + + // If auto-compaction is enabled, re-determine the compaction interval + if (_autoCompactionFactor != 0) { + computeNextAutoCompactionAmount(size()); + } + } + + /** + * The auto-compaction factor controls whether and when a table performs a + * {@link #compact} automatically after a certain number of remove operations. + * If the value is non-zero, the number of removes that need to occur for + * auto-compaction is the size of table at the time of the previous compaction + * (or the initial capacity) multiplied by this factor. + *

+ * Setting this value to zero will disable auto-compaction. + * + * @param factor + * a float that indicates the auto-compaction factor + */ + public void setAutoCompactionFactor(float factor) { + if (factor < 0) { + throw new IllegalArgumentException("Factor must be >= 0: " + factor); + } + + _autoCompactionFactor = factor; + } + + /** + * @see #setAutoCompactionFactor + * + * @return a <float that represents the auto-compaction factor. + */ + public float getAutoCompactionFactor() { + return _autoCompactionFactor; + } + + /** + * This simply calls {@link #compact compact}. It is included for symmetry with + * other collection classes. Note that the name of this method is somewhat + * misleading (which is why we prefer compact) as the load factor may + * require capacity above and beyond the size of this collection. + * + * @see #compact + */ + public final void trimToSize() { + compact(); + } + + /** + * Delete the record at index. Reduces the size of the collection by + * one. + * + * @param index + * an int value + */ + protected void removeAt(int index) { + _size--; + + // If auto-compaction is enabled, see if we need to compact + if (_autoCompactionFactor != 0) { + _autoCompactRemovesRemaining--; + + if (!_autoCompactTemporaryDisable && _autoCompactRemovesRemaining <= 0) { + // Do the compact + // NOTE: this will cause the next compaction interval to be calculated + compact(); + } + } + } + + /** Empties the collection. */ + public void clear() { + _size = 0; + _free = capacity(); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + protected int setUp(int initialCapacity) { + int capacity; + + capacity = PrimeFinder.nextPrime(initialCapacity); + computeMaxSize(capacity); + computeNextAutoCompactionAmount(initialCapacity); + + return capacity; + } + + /** + * Rehashes the set. + * + * @param newCapacity + * an int value + */ + protected abstract void rehash(int newCapacity); + + /** + * Temporarily disables auto-compaction. MUST be followed by calling + * {@link #reenableAutoCompaction}. + */ + public void tempDisableAutoCompaction() { + _autoCompactTemporaryDisable = true; + } + + /** + * Re-enable auto-compaction after it was disabled via + * {@link #tempDisableAutoCompaction()}. + * + * @param check_for_compaction + * True if compaction should be performed if needed before returning. + * If false, no compaction will be performed. + */ + public void reenableAutoCompaction(boolean check_for_compaction) { + _autoCompactTemporaryDisable = false; + + if (check_for_compaction && _autoCompactRemovesRemaining <= 0 && _autoCompactionFactor != 0) { + + // Do the compact + // NOTE: this will cause the next compaction interval to be calculated + compact(); + } + } + + /** + * Computes the values of maxSize. There will always be at least one free slot + * required. + * + * @param capacity + * an int value + */ + protected void computeMaxSize(int capacity) { + // need at least one free slot for open addressing + _maxSize = Math.min(capacity - 1, (int) (capacity * _loadFactor)); + _free = capacity - _size; // reset the free element count + } + + /** + * Computes the number of removes that need to happen before the next + * auto-compaction will occur. + * + * @param size + * an int that sets the auto-compaction limit. + */ + protected void computeNextAutoCompactionAmount(int size) { + if (_autoCompactionFactor != 0) { + // NOTE: doing the round ourselves has been found to be faster than using + // Math.round. + _autoCompactRemovesRemaining = (int) ((size * _autoCompactionFactor) + 0.5f); + } + } + + /** + * After an insert, this hook is called to adjust the size/free values of the + * set and to perform rehashing if necessary. + * + * @param usedFreeSlot + * the slot + */ + protected final void postInsertHook(boolean usedFreeSlot) { + if (usedFreeSlot) { + _free--; + } + + // rehash whenever we exhaust the available space in the table + if (++_size > _maxSize || _free == 0) { + // choose a new capacity suited to the new state of the table + // if we've grown beyond our maximum size, double capacity; + // if we've exhausted the free spots, rehash to the same capacity, + // which will free up any stale removed slots for reuse. + int newCapacity = _size > _maxSize ? PrimeFinder.nextPrime(capacity() << 1) : capacity(); + rehash(newCapacity); + computeMaxSize(capacity()); + } + } + + protected int calculateGrownCapacity() { + return capacity() << 1; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LOAD FACTOR + out.writeFloat(_loadFactor); + + // AUTO COMPACTION LOAD FACTOR + out.writeFloat(_autoCompactionFactor); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LOAD FACTOR + float old_factor = _loadFactor; + _loadFactor = in.readFloat(); + + // AUTO COMPACTION LOAD FACTOR + _autoCompactionFactor = in.readFloat(); + + // If we change the laod factor from the default, re-setup + if (old_factor != _loadFactor) { + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + } +}// THash \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/THashIterator.java b/src/gnu/trove/impl/hash/THashIterator.java new file mode 100644 index 0000000..4d1812d --- /dev/null +++ b/src/gnu/trove/impl/hash/THashIterator.java @@ -0,0 +1,170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.iterator.TIterator; + +import java.util.ConcurrentModificationException; +import java.util.Iterator; +import java.util.NoSuchElementException; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public abstract class THashIterator implements TIterator, Iterator { + + private final TObjectHash _object_hash; + + /** the data structure this iterator traverses */ + protected final THash _hash; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** + * Create an instance of THashIterator over the values of the TObjectHash + * + * @param hash + * the object + */ + protected THashIterator(TObjectHash hash) { + _hash = hash; + _expectedSize = _hash.size(); + _index = _hash.capacity(); + _object_hash = hash; + } + + /** + * Moves the iterator to the next Object and returns it. + * + * @return an Object value + * @throws ConcurrentModificationException + * if the structure was changed using a method that isn't on this + * iterator. + * @throws NoSuchElementException + * if this is called on an exhausted iterator. + */ + @Override + public V next() { + moveToNextIndex(); + return objectAtIndex(_index); + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + _hash.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = _object_hash._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + + /** + * Returns the object at the specified index. Subclasses should implement this + * to return the appropriate object for the given index. + * + * @param index + * the index of the value to return. + * @return an Object value + */ + abstract protected V objectAtIndex(int index); +} // THashIterator diff --git a/src/gnu/trove/impl/hash/THashPrimitiveIterator.java b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java new file mode 100644 index 0000000..bafd58c --- /dev/null +++ b/src/gnu/trove/impl/hash/THashPrimitiveIterator.java @@ -0,0 +1,139 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.iterator.TPrimitiveIterator; + +import java.util.ConcurrentModificationException; +import java.util.NoSuchElementException; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public abstract class THashPrimitiveIterator implements TPrimitiveIterator { + + /** the data structure this iterator traverses */ + protected final TPrimitiveHash _hash; + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + /** the index used for iteration. */ + protected int _index; + + /** + * Creates a TPrimitiveIterator for the specified collection. + * + * @param hash + * the TPrimitiveHash we want to iterate over. + */ + public THashPrimitiveIterator(TPrimitiveHash hash) { + _hash = hash; + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + byte[] states = _hash._states; + int i = _index; + while (i-- > 0 && (states[i] != TPrimitiveHash.FULL)) { + ; + } + return i; + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + _hash.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + +} // TPrimitiveIterator \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/TIntByteHash.java b/src/gnu/trove/impl/hash/TIntByteHash.java new file mode 100644 index 0000000..42a2bd5 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TIntByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TIntByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntByteHash(int initialCapacity, float loadFactor, int no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TIntByteHash diff --git a/src/gnu/trove/impl/hash/TIntCharHash.java b/src/gnu/trove/impl/hash/TIntCharHash.java new file mode 100644 index 0000000..de790ed --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TIntCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TIntCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntCharHash(int initialCapacity, float loadFactor, int no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TIntCharHash diff --git a/src/gnu/trove/impl/hash/TIntDoubleHash.java b/src/gnu/trove/impl/hash/TIntDoubleHash.java new file mode 100644 index 0000000..75c982a --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntDoubleHash(int initialCapacity, float loadFactor, int no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TIntDoubleHash diff --git a/src/gnu/trove/impl/hash/TIntFloatHash.java b/src/gnu/trove/impl/hash/TIntFloatHash.java new file mode 100644 index 0000000..e8f79fb --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntFloatHash(int initialCapacity, float loadFactor, int no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TIntFloatHash diff --git a/src/gnu/trove/impl/hash/TIntHash.java b/src/gnu/trove/impl/hash/TIntHash.java new file mode 100644 index 0000000..bb95028 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TIntHash instance with the default capacity and + * load factor. + */ + public TIntHash() { + super(); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntHash(int initialCapacity, float loadFactor, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int val) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TIntHash diff --git a/src/gnu/trove/impl/hash/TIntIntHash.java b/src/gnu/trove/impl/hash/TIntIntHash.java new file mode 100644 index 0000000..a7f284f --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntIntHash(int initialCapacity, float loadFactor, int no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TIntIntHash diff --git a/src/gnu/trove/impl/hash/TIntLongHash.java b/src/gnu/trove/impl/hash/TIntLongHash.java new file mode 100644 index 0000000..b9b28c0 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TIntLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntLongHash(int initialCapacity, float loadFactor, int no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TIntLongHash diff --git a/src/gnu/trove/impl/hash/TIntShortHash.java b/src/gnu/trove/impl/hash/TIntShortHash.java new file mode 100644 index 0000000..3dfb674 --- /dev/null +++ b/src/gnu/trove/impl/hash/TIntShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for int/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TIntShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of ints */ + public transient int[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TIntShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TIntShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TIntShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TIntShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TIntShortHash(int initialCapacity, float loadFactor, int no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new int[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an int value + * @return a boolean value + */ + public boolean contains(int val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TIntProcedure procedure) { + byte[] states = _states; + int[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an int value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(int key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an int value + * @return an int value + */ + protected int insertKey(int val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(int val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, int val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(int key) { + int hash, probe, index, length; + + final byte[] states = _states; + final int[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TIntShortHash diff --git a/src/gnu/trove/impl/hash/TLongByteHash.java b/src/gnu/trove/impl/hash/TLongByteHash.java new file mode 100644 index 0000000..6ee089a --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongByteHash() { + super(); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TLongByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TLongByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongByteHash(int initialCapacity, float loadFactor, long no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TLongByteHash diff --git a/src/gnu/trove/impl/hash/TLongCharHash.java b/src/gnu/trove/impl/hash/TLongCharHash.java new file mode 100644 index 0000000..8da7eeb --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongCharHash() { + super(); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TLongCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TLongCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongCharHash(int initialCapacity, float loadFactor, long no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TLongCharHash diff --git a/src/gnu/trove/impl/hash/TLongDoubleHash.java b/src/gnu/trove/impl/hash/TLongDoubleHash.java new file mode 100644 index 0000000..2294f65 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongDoubleHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongDoubleHash(int initialCapacity, float loadFactor, long no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TLongDoubleHash diff --git a/src/gnu/trove/impl/hash/TLongFloatHash.java b/src/gnu/trove/impl/hash/TLongFloatHash.java new file mode 100644 index 0000000..fd47b15 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongFloatHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongFloatHash(int initialCapacity, float loadFactor, long no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TLongFloatHash diff --git a/src/gnu/trove/impl/hash/TLongHash.java b/src/gnu/trove/impl/hash/TLongHash.java new file mode 100644 index 0000000..f3eee49 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TLongHash instance with the default capacity and + * load factor. + */ + public TLongHash() { + super(); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongHash(int initialCapacity, float loadFactor, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long val) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TLongHash diff --git a/src/gnu/trove/impl/hash/TLongIntHash.java b/src/gnu/trove/impl/hash/TLongIntHash.java new file mode 100644 index 0000000..4ccb921 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongIntHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongIntHash(int initialCapacity, float loadFactor, long no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TLongIntHash diff --git a/src/gnu/trove/impl/hash/TLongLongHash.java b/src/gnu/trove/impl/hash/TLongLongHash.java new file mode 100644 index 0000000..0ce5034 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongLongHash() { + super(); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = 0; + } + + /** + * Creates a new TLongLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongLongHash(int initialCapacity, float loadFactor, long no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TLongLongHash diff --git a/src/gnu/trove/impl/hash/TLongShortHash.java b/src/gnu/trove/impl/hash/TLongShortHash.java new file mode 100644 index 0000000..547bb85 --- /dev/null +++ b/src/gnu/trove/impl/hash/TLongShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for long/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TLongShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of longs */ + public transient long[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TLongShortHash() { + super(); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TLongShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TLongShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TLongShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TLongShortHash(int initialCapacity, float loadFactor, long no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new long[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an long value + * @return a boolean value + */ + public boolean contains(long val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TLongProcedure procedure) { + byte[] states = _states; + long[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an long value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(long key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an long value + * @return an int value + */ + protected int insertKey(long val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(long val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, long val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(long key) { + int hash, probe, index, length; + + final byte[] states = _states; + final long[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TLongShortHash diff --git a/src/gnu/trove/impl/hash/TObjectHash.java b/src/gnu/trove/impl/hash/TObjectHash.java new file mode 100644 index 0000000..3235d4f --- /dev/null +++ b/src/gnu/trove/impl/hash/TObjectHash.java @@ -0,0 +1,630 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TObjectProcedure; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * An open addressed hashing implementation for Object types. + *

+ * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TObjectHash.java,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TObjectHash extends THash { + + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = -3461112548087185871L; + + /** + * the set of Objects + */ + public transient Object[] _set; + + public static final Object REMOVED = new Object(), FREE = new Object(); + + /** + * Indicates whether the last insertKey() call used a FREE slot. This field + * should be inspected right after call insertKey() + */ + protected boolean consumeFreeSlot; + + /** + * Creates a new TObjectHash instance with the default capacity and + * load factor. + */ + public TObjectHash() { + super(); + } + + /** + * Creates a new TObjectHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TObjectHash(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TObjectHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TObjectHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + @Override + public int capacity() { + return _set.length; + } + + @Override + protected void removeAt(int index) { + _set[index] = REMOVED; + super.removeAt(index); + } + + /** + * initializes the Object set of this hash table. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new Object[capacity]; + Arrays.fill(_set, FREE); + return capacity; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEach(TObjectProcedure procedure) { + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute((T) set[i])) { + return false; + } + } + return true; + } + + /** + * Searches the set for obj + * + * @param obj + * an Object value + * @return a boolean value + */ + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object obj) { + return index(obj) >= 0; + } + + /** + * Locates the index of obj. + * + * @param obj + * an Object value + * @return the index of obj or -1 if it isn't in the set. + */ + protected int index(Object obj) { + if (obj == null) + return indexForNull(); + + // From here on we know obj to be non-null + final int hash = hash(obj) & 0x7fffffff; + int index = hash % _set.length; + Object cur = _set[index]; + + if (cur == FREE) { + return -1; + } + + if (cur == obj || equals(obj, cur)) { + return index; + } + + return indexRehashed(obj, index, hash, cur); + } + + /** + * Locates the index of non-null obj. + * + * @param obj + * target key, know to be non-null + * @param index + * we start from + * @param hash + * @param cur + * @return + */ + private int indexRehashed(Object obj, int index, int hash, Object cur) { + final Object[] set = _set; + final int length = set.length; + + // NOTE: here it has to be REMOVED or FULL (some user-given value) + // see Knuth, p. 529 + int probe = 1 + (hash % (length - 2)); + + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + cur = set[index]; + // + if (cur == FREE) + return -1; + + // + if ((cur == obj || equals(obj, cur))) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index null. + *

+ * null specific loop exploiting several properties to simplify the iteration + * logic - the null value hashes to 0 we so we can iterate from the beginning. - + * the probe value is 1 for this case - object identity can be used to match + * this case + *

+ * --> this result a simpler loop + * + * @return + */ + private int indexForNull() { + int index = 0; + for (Object o : _set) { + if (o == null) + return index; + + if (o == FREE) + return -1; + + index++; + } + + return -1; + } + + /** + * Alias introduced to avoid breaking the API. The new method name insertKey() + * reflects the changes made to the logic. + * + * @param obj + * @return + * @deprecated use {@link #insertKey} instead + */ + @Deprecated + protected int insertionIndex(T obj) { + return insertKey(obj); + } + + /** + * Locates the index at which key can be inserted. if there is already + * a value equal()ing key in the set, returns that value's index as + * -index - 1. + *

+ * If a slot is found the value is inserted. When a FREE slot is used the + * consumeFreeSlot field is set to true. This field should be used in the method + * invoking insertKey() to pass to postInsertHook() + * + * @param key + * an Object value + * @return the index of a FREE slot at which key can be inserted or, if key is + * already stored in the hash, the negative value of that index, minus + * 1: -index -1. + */ + protected int insertKey(T key) { + consumeFreeSlot = false; + + if (key == null) + return insertKeyForNull(); + + final int hash = hash(key) & 0x7fffffff; + int index = hash % _set.length; + Object cur = _set[index]; + + if (cur == FREE) { + consumeFreeSlot = true; + _set[index] = key; // insert value + return index; // empty, all done + } + + if (cur == key || equals(key, cur)) { + return -index - 1; // already stored + } + + return insertKeyRehash(key, index, hash, cur); + } + + /** + * Looks for a slot using double hashing for a non-null key values and inserts + * the value in the slot + * + * @param key + * non-null key value + * @param index + * natural index + * @param hash + * @param cur + * value of first matched slot + * @return + */ + private int insertKeyRehash(T key, int index, int hash, Object cur) { + final Object[] set = _set; + final int length = set.length; + // already FULL or REMOVED, must probe + // compute the double hash + final int probe = 1 + (hash % (length - 2)); + + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (cur == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + cur = set[index]; + + // A FREE slot stops the search + if (cur == FREE) { + if (firstRemoved != -1) { + _set[firstRemoved] = key; + return firstRemoved; + } else { + consumeFreeSlot = true; + _set[index] = key; // insert value + return index; + } + } + + if (cur == key || equals(key, cur)) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + _set[firstRemoved] = key; + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + /** + * Looks for a slot using double hashing for a null key value and inserts the + * value. + *

+ * null specific loop exploiting several properties to simplify the iteration + * logic - the null value hashes to 0 we so we can iterate from the beginning. - + * the probe value is 1 for this case - object identity can be used to match + * this case + * + * @return + */ + private int insertKeyForNull() { + int index = 0; + int firstRemoved = -1; + + // Look for a slot containing the 'null' value as key + for (Object o : _set) { + // Locate first removed + if (o == REMOVED && firstRemoved == -1) + firstRemoved = index; + + if (o == FREE) { + if (firstRemoved != -1) { + _set[firstRemoved] = null; + return firstRemoved; + } else { + consumeFreeSlot = true; + _set[index] = null; // insert value + return index; + } + } + + if (o == null) { + return -index - 1; + } + + index++; + } + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + _set[firstRemoved] = null; + return firstRemoved; + } + + // We scanned the entire key set and found nothing, is set full? + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("Could not find insertion index for null key. Key set full!?!!"); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final void throwObjectContractViolation(Object o1, Object o2) throws IllegalArgumentException { + throw buildObjectContractViolation(o1, o2, ""); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @param size + * @param oldSize + * @param oldKeys + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final void throwObjectContractViolation(Object o1, Object o2, int size, int oldSize, Object[] oldKeys) + throws IllegalArgumentException { + String extra = dumpExtraInfo(o1, o2, size(), oldSize, oldKeys); + + throw buildObjectContractViolation(o1, o2, extra); + } + + /** + * Convenience methods for subclasses to use in throwing exceptions about badly + * behaved user objects employed as keys. We have to throw an + * IllegalArgumentException with a rather verbose message telling the user that + * they need to fix their object implementation to conform to the general + * contract for java.lang.Object. + * + * + * @param o1 + * the first of the equal elements with unequal hash codes. + * @param o2 + * the second of the equal elements with unequal hash codes. + * @throws IllegalArgumentException + * the whole point of this method. + */ + protected final IllegalArgumentException buildObjectContractViolation(Object o1, Object o2, String extra) { + return new IllegalArgumentException("Equal objects must have equal hashcodes. " + + "During rehashing, Trove discovered that the following two objects claim " + + "to be equal (as in java.lang.Object.equals()) but their hashCodes (or " + + "those calculated by your TObjectHashingStrategy) are not equal." + + "This violates the general contract of java.lang.Object.hashCode(). See " + + "bullet point two in that method's documentation. object #1 =" + objectInfo(o1) + "; object #2 =" + + objectInfo(o2) + "\n" + extra); + } + + protected boolean equals(Object notnull, Object two) { + if (two == null || two == REMOVED) + return false; + + return notnull.equals(two); + } + + protected int hash(Object notnull) { + return notnull.hashCode(); + } + + protected static String reportPotentialConcurrentMod(int newSize, int oldSize) { + // Note that we would not be able to detect concurrent paired of put()-remove() + // operations with this simple check + if (newSize != oldSize) + return "[Warning] apparent concurrent modification of the key set. " + + "Size before and after rehash() do not match " + oldSize + " vs " + newSize; + + return ""; + } + + /** + * + * @param newVal + * the key being inserted + * @param oldVal + * the key already stored at that position + * @param currentSize + * size of the key set during rehashing + * @param oldSize + * size of the key set before rehashing + * @param oldKeys + * the old key set + */ + protected String dumpExtraInfo(Object newVal, Object oldVal, int currentSize, int oldSize, Object[] oldKeys) { + StringBuilder b = new StringBuilder(); + // + b.append(dumpKeyTypes(newVal, oldVal)); + + b.append(reportPotentialConcurrentMod(currentSize, oldSize)); + b.append(detectKeyLoss(oldKeys, oldSize)); + + // Is de same object already present? Double insert? + if (newVal == oldVal) { + b.append("Inserting same object twice, rehashing bug. Object= ").append(oldVal); + } + + return b.toString(); + } + + /** + * Detect inconsistent hashCode() and/or equals() methods + * + * @param keys + * @param oldSize + * @return + */ + private static String detectKeyLoss(Object[] keys, int oldSize) { + StringBuilder buf = new StringBuilder(); + Set k = makeKeySet(keys); + if (k.size() != oldSize) { + buf.append("\nhashCode() and/or equals() have inconsistent implementation"); + buf.append("\nKey set lost entries, now got ").append(k.size()).append(" instead of ").append(oldSize); + buf.append(". This can manifest itself as an apparent duplicate key."); + } + + return buf.toString(); + } + + private static Set makeKeySet(Object[] keys) { + Set types = new HashSet(); + for (Object o : keys) { + if (o != FREE && o != REMOVED) { + types.add(o); + } + } + + return types; + } + + private static String equalsSymmetryInfo(Object a, Object b) { + StringBuilder buf = new StringBuilder(); + if (a == b) { + return "a == b"; + } + + if (a.getClass() != b.getClass()) { + buf.append("Class of objects differ a=").append(a.getClass()).append(" vs b=").append(b.getClass()); + + boolean aEb = a.equals(b); + boolean bEa = b.equals(a); + if (aEb != bEa) { + buf.append("\nequals() of a or b object are asymmetric"); + buf.append("\na.equals(b) =").append(aEb); + buf.append("\nb.equals(a) =").append(bEa); + } + } + + return buf.toString(); + } + + protected static String objectInfo(Object o) { + return (o == null ? "class null" : o.getClass()) + " id= " + System.identityHashCode(o) + " hashCode= " + + (o == null ? 0 : o.hashCode()) + " toString= " + String.valueOf(o); + } + + private String dumpKeyTypes(Object newVal, Object oldVal) { + StringBuilder buf = new StringBuilder(); + Set> types = new HashSet>(); + for (Object o : _set) { + if (o != FREE && o != REMOVED) { + if (o != null) + types.add(o.getClass()); + else + types.add(null); + } + } + + if (types.size() > 1) { + buf.append("\nMore than one type used for keys. Watch out for asymmetric equals(). " + + "Read about the 'Liskov substitution principle' and the implications for equals() in java."); + + buf.append("\nKey types: ").append(types); + buf.append(equalsSymmetryInfo(newVal, oldVal)); + } + + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + } +} // TObjectHash diff --git a/src/gnu/trove/impl/hash/TPrimitiveHash.java b/src/gnu/trove/impl/hash/TPrimitiveHash.java new file mode 100644 index 0000000..f62f750 --- /dev/null +++ b/src/gnu/trove/impl/hash/TPrimitiveHash.java @@ -0,0 +1,134 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.impl.HashFunctions; + +/** + * The base class for hashtables of primitive values. Since there is no notion + * of object equality for primitives, it isn't possible to use a `REMOVED' + * object to track deletions in an open-addressed table. So, we have to resort + * to using a parallel `bookkeeping' array of bytes, in which flags can be set + * to indicate that a particular slot in the hash table is FREE, FULL, or + * REMOVED. + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: TPrimitiveHash.java,v 1.1.2.6 2010/03/01 23:39:07 robeden Exp $ + */ +abstract public class TPrimitiveHash extends THash { + @SuppressWarnings({ "UnusedDeclaration" }) + static final long serialVersionUID = 1L; + + /** + * flags indicating whether each position in the hash is FREE, FULL, or REMOVED + */ + public transient byte[] _states; + + /* constants used for state flags */ + + /** flag indicating that a slot in the hashtable is available */ + public static final byte FREE = 0; + + /** flag indicating that a slot in the hashtable is occupied */ + public static final byte FULL = 1; + + /** + * flag indicating that the value of a slot in the hashtable was deleted + */ + public static final byte REMOVED = 2; + + /** + * Creates a new THash instance with the default capacity and load + * factor. + */ + public TPrimitiveHash() { + super(); + } + + /** + * Creates a new TPrimitiveHash instance with a prime capacity at + * or near the specified capacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TPrimitiveHash(int initialCapacity) { + this(initialCapacity, DEFAULT_LOAD_FACTOR); + } + + /** + * Creates a new TPrimitiveHash instance with a prime capacity at + * or near the minimum needed to hold + * initialCapacity elements with load factor + * loadFactor without triggering a rehash. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TPrimitiveHash(int initialCapacity, float loadFactor) { + super(); + initialCapacity = Math.max(1, initialCapacity); + _loadFactor = loadFactor; + setUp(HashFunctions.fastCeil(initialCapacity / loadFactor)); + } + + /** + * Returns the capacity of the hash table. This is the true physical capacity, + * without adjusting for the load factor. + * + * @return the physical capacity of the hash table. + */ + @Override + public int capacity() { + return _states.length; + } + + /** + * Delete the record at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _states[index] = REMOVED; + super.removeAt(index); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _states = new byte[capacity]; + return capacity; + } +} // TPrimitiveHash \ No newline at end of file diff --git a/src/gnu/trove/impl/hash/TShortByteHash.java b/src/gnu/trove/impl/hash/TShortByteHash.java new file mode 100644 index 0000000..c45b678 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortByteHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/byte primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortByteHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected byte no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortByteHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortByteHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TShortByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortByteHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (byte) 0; + } + + /** + * Creates a new TShortByteHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortByteHash(int initialCapacity, float loadFactor, short no_entry_key, byte no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + } +} // TShortByteHash diff --git a/src/gnu/trove/impl/hash/TShortCharHash.java b/src/gnu/trove/impl/hash/TShortCharHash.java new file mode 100644 index 0000000..1758503 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortCharHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/char primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortCharHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected char no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortCharHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortCharHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TShortCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortCharHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (char) 0; + } + + /** + * Creates a new TShortCharHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortCharHash(int initialCapacity, float loadFactor, short no_entry_key, char no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + } +} // TShortCharHash diff --git a/src/gnu/trove/impl/hash/TShortDoubleHash.java b/src/gnu/trove/impl/hash/TShortDoubleHash.java new file mode 100644 index 0000000..1a30bf8 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortDoubleHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/double primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortDoubleHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected double no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortDoubleHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortDoubleHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortDoubleHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortDoubleHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortDoubleHash(int initialCapacity, float loadFactor, short no_entry_key, double no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + } +} // TShortDoubleHash diff --git a/src/gnu/trove/impl/hash/TShortFloatHash.java b/src/gnu/trove/impl/hash/TShortFloatHash.java new file mode 100644 index 0000000..745bb22 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortFloatHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/float primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortFloatHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected float no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortFloatHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortFloatHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortFloatHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortFloatHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortFloatHash(int initialCapacity, float loadFactor, short no_entry_key, float no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + } +} // TShortFloatHash diff --git a/src/gnu/trove/impl/hash/TShortHash.java b/src/gnu/trove/impl/hash/TShortHash.java new file mode 100644 index 0000000..850e863 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortHash.java @@ -0,0 +1,334 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.Constants; + +import java.util.Arrays; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short primitives. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new TShortHash instance with the default capacity and + * load factor. + */ + public TShortHash() { + super(); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortHash(int initialCapacity, float loadFactor, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_value = no_entry_value; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_value; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param val + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short val) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == val) + return index; + + return indexRehashed(val, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param val + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + +} // TShortHash diff --git a/src/gnu/trove/impl/hash/TShortIntHash.java b/src/gnu/trove/impl/hash/TShortIntHash.java new file mode 100644 index 0000000..58fa16e --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortIntHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/int primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortIntHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected int no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortIntHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortIntHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortIntHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortIntHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortIntHash(int initialCapacity, float loadFactor, short no_entry_key, int no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + } +} // TShortIntHash diff --git a/src/gnu/trove/impl/hash/TShortLongHash.java b/src/gnu/trove/impl/hash/TShortLongHash.java new file mode 100644 index 0000000..4197503 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortLongHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/long primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortLongHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected long no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortLongHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortLongHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortLongHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = 0; + } + + /** + * Creates a new TShortLongHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortLongHash(int initialCapacity, float loadFactor, short no_entry_key, long no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + } +} // TShortLongHash diff --git a/src/gnu/trove/impl/hash/TShortShortHash.java b/src/gnu/trove/impl/hash/TShortShortHash.java new file mode 100644 index 0000000..d289278 --- /dev/null +++ b/src/gnu/trove/impl/hash/TShortShortHash.java @@ -0,0 +1,458 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.hash; + +import gnu.trove.procedure.*; +import gnu.trove.impl.HashFunctions; + +import java.io.ObjectOutput; +import java.io.ObjectInput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed hashing implementation for short/short primitive entries. + * + * Created: Sun Nov 4 08:56:06 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_Hash.template,v 1.1.2.6 2009/11/07 03:36:44 robeden Exp $ + */ +abstract public class TShortShortHash extends TPrimitiveHash { + static final long serialVersionUID = 1L; + + /** the set of shorts */ + public transient short[] _set; + + /** + * key that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_key; + + /** + * value that represents null + * + * NOTE: should not be modified after the Hash is created, but is not final + * because of Externalization + * + */ + protected short no_entry_value; + + protected boolean consumeFreeSlot; + + /** + * Creates a new T#E#Hash instance with the default capacity and + * load factor. + */ + public TShortShortHash() { + super(); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new T#E#Hash instance whose capacity is the next + * highest prime above initialCapacity + 1 unless that value is already + * prime. + * + * @param initialCapacity + * an int value + */ + public TShortShortHash(int initialCapacity) { + super(initialCapacity); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TShortShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortShortHash(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = (short) 0; + no_entry_value = (short) 0; + } + + /** + * Creates a new TShortShortHash instance with a prime value at or + * near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param no_entry_value + * value that represents null + */ + public TShortShortHash(int initialCapacity, float loadFactor, short no_entry_key, short no_entry_value) { + super(initialCapacity, loadFactor); + this.no_entry_key = no_entry_key; + this.no_entry_value = no_entry_value; + } + + /** + * Returns the value that is used to represent null as a key. The default value + * is generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryKey() { + return no_entry_key; + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue() { + return no_entry_value; + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _set = new short[capacity]; + return capacity; + } + + /** + * Searches the set for val + * + * @param val + * an short value + * @return a boolean value + */ + public boolean contains(short val) { + return index(val) >= 0; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + public boolean forEach(TShortProcedure procedure) { + byte[] states = _states; + short[] set = _set; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(set[i])) { + return false; + } + } + return true; + } + + /** + * Releases the element currently stored at index. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _set[index] = no_entry_key; + super.removeAt(index); + } + + /** + * Locates the index of val. + * + * @param key + * an short value + * @return the index of val or -1 if it isn't in the set. + */ + protected int index(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + if (state == FREE) + return -1; + + if (state == FULL && set[index] == key) + return index; + + return indexRehashed(key, index, hash, state); + } + + int indexRehashed(short key, int index, int hash, byte state) { + // see Knuth, p. 529 + int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + + do { + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + // + if (state == FREE) + return -1; + + // + if (key == _set[index] && state != REMOVED) + return index; + } while (index != loopIndex); + + return -1; + } + + /** + * Locates the index at which val can be inserted. if there is already + * a value equal()ing val in the set, returns that value as a negative + * integer. + * + * @param key + * an short value + * @return an int value + */ + protected int insertKey(short val) { + int hash, index; + + hash = HashFunctions.hash(val) & 0x7fffffff; + index = hash % _states.length; + byte state = _states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + insertKeyAt(index, val); + + return index; // empty, all done + } + + if (state == FULL && _set[index] == val) { + return -index - 1; // already stored + } + + // already FULL or REMOVED, must probe + return insertKeyRehash(val, index, hash, state); + } + + int insertKeyRehash(short val, int index, int hash, byte state) { + // compute the double hash + final int length = _set.length; + int probe = 1 + (hash % (length - 2)); + final int loopIndex = index; + int firstRemoved = -1; + + /** + * Look until FREE slot or we start to loop + */ + do { + // Identify first removed slot + if (state == REMOVED && firstRemoved == -1) + firstRemoved = index; + + index -= probe; + if (index < 0) { + index += length; + } + state = _states[index]; + + // A FREE slot stops the search + if (state == FREE) { + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } else { + consumeFreeSlot = true; + insertKeyAt(index, val); + return index; + } + } + + if (state == FULL && _set[index] == val) { + return -index - 1; + } + + // Detect loop + } while (index != loopIndex); + + // We inspected all reachable slots and did not find a FREE one + // If we found a REMOVED slot we return the first one found + if (firstRemoved != -1) { + insertKeyAt(firstRemoved, val); + return firstRemoved; + } + + // Can a resizing strategy be found that resizes the set? + throw new IllegalStateException("No free or removed slots available. Key set full?!!"); + } + + void insertKeyAt(int index, short val) { + _set[index] = val; // insert value + _states[index] = FULL; + } + + protected int XinsertKey(short key) { + int hash, probe, index, length; + + final byte[] states = _states; + final short[] set = _set; + length = states.length; + hash = HashFunctions.hash(key) & 0x7fffffff; + index = hash % length; + byte state = states[index]; + + consumeFreeSlot = false; + + if (state == FREE) { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; // empty, all done + } else if (state == FULL && set[index] == key) { + return -index - 1; // already stored + } else { // already FULL or REMOVED, must probe + // compute the double hash + probe = 1 + (hash % (length - 2)); + + // if the slot we landed on is FULL (but not removed), probe + // until we find an empty slot, a REMOVED slot, or an element + // equal to the one we are trying to insert. + // finding an empty slot means that the value is not present + // and that we should use that slot as the insertion point; + // finding a REMOVED slot means that we need to keep searching, + // however we want to remember the offset of that REMOVED slot + // so we can reuse it in case a "new" insertion (i.e. not an update) + // is possible. + // finding a matching value means that we've found that our desired + // key is already in the table + + if (state != REMOVED) { + // starting at the natural offset, probe until we find an + // offset that isn't full. + do { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } while (state == FULL && set[index] != key); + } + + // if the index we found was removed: continue probing until we + // locate a free location or an element which equal()s the + // one we have. + if (state == REMOVED) { + int firstRemoved = index; + while (state != FREE && (state == REMOVED || set[index] != key)) { + index -= probe; + if (index < 0) { + index += length; + } + state = states[index]; + } + + if (state == FULL) { + return -index - 1; + } else { + set[index] = key; + states[index] = FULL; + + return firstRemoved; + } + } + // if it's full, the key is already stored + if (state == FULL) { + return -index - 1; + } else { + consumeFreeSlot = true; + set[index] = key; + states[index] = FULL; + + return index; + } + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + } +} // TShortShortHash diff --git a/src/gnu/trove/impl/package.html b/src/gnu/trove/impl/package.html new file mode 100644 index 0000000..c803363 --- /dev/null +++ b/src/gnu/trove/impl/package.html @@ -0,0 +1,24 @@ + + +This package (and its sub-packages) contain internal implementations used in Trove. These +classes should not be accessed directly (treat them like com.sun +classes. + \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/SynchronizedCollection.java b/src/gnu/trove/impl/sync/SynchronizedCollection.java new file mode 100644 index 0000000..9f6c566 --- /dev/null +++ b/src/gnu/trove/impl/sync/SynchronizedCollection.java @@ -0,0 +1,143 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +import java.io.IOException; +import java.io.ObjectOutputStream; +import java.io.Serializable; +import java.util.Collection; +import java.util.Iterator; + +/** + * + */ +class SynchronizedCollection implements Collection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final Collection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + SynchronizedCollection(Collection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(Object o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public Object[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + @SuppressWarnings({ "SuspiciousToArrayCall" }) + public T[] toArray(T[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public Iterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(E e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(Object o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/SynchronizedSet.java b/src/gnu/trove/impl/sync/SynchronizedSet.java new file mode 100644 index 0000000..e35757e --- /dev/null +++ b/src/gnu/trove/impl/sync/SynchronizedSet.java @@ -0,0 +1,46 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +import java.util.Set; + +/** + * Local implementation of SynchronizedSet so we can set the mutex explicitly. + */ +class SynchronizedSet extends SynchronizedCollection implements Set { + private static final long serialVersionUID = 487447009682186044L; + + SynchronizedSet(Set s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} \ No newline at end of file diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java new file mode 100644 index 0000000..4e59d10 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteByteMap implements TByteByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteByteMap(TByteByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteByteMap(TByteByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(byte key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(byte key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java new file mode 100644 index 0000000..df37c9d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteCharMap implements TByteCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteCharMap(TByteCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteCharMap(TByteCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(byte key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(byte key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java b/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java new file mode 100644 index 0000000..f840e64 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteCollection implements TByteCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TByteCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteCollection(TByteCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedByteCollection(TByteCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(byte o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public byte[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public byte[] toArray(byte[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TByteIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(byte e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(byte o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TByteCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(byte[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TByteCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(byte[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TByteCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(byte[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TByteCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(byte[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public byte getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TByteProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java new file mode 100644 index 0000000..f4884a9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteDoubleMap implements TByteDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteDoubleMap(TByteDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteDoubleMap(TByteDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(byte key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(byte key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java new file mode 100644 index 0000000..11c0538 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteFloatMap implements TByteFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteFloatMap(TByteFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteFloatMap(TByteFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(byte key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(byte key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java new file mode 100644 index 0000000..12153e3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteIntMap implements TByteIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteIntMap(TByteIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteIntMap(TByteIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(byte key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(byte key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteList.java b/src/gnu/trove/impl/sync/TSynchronizedByteList.java new file mode 100644 index 0000000..9f42207 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedByteList extends TSynchronizedByteCollection implements TByteList { + + static final long serialVersionUID = -7754090372962971524L; + + final TByteList list; + + public TSynchronizedByteList(TByteList list) { + super(list); + this.list = list; + } + + public TSynchronizedByteList(TByteList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public byte get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public byte set(int index, byte element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, byte[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public byte replace(int offset, byte val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public byte removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(byte[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(byte[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, byte value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, byte[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(byte o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(byte o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListByteIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListByteIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedByteList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public byte[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, byte value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, byte value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(byte val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, byte val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(byte value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TByteList grep(TByteProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TByteList inverseGrep(TByteProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public byte max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public byte min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public byte sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TByteProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessByteList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java new file mode 100644 index 0000000..8c15c7b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteLongMap implements TByteLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteLongMap(TByteLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteLongMap(TByteLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(byte key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(byte key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java new file mode 100644 index 0000000..d2b3b78 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteObjectMap implements TByteObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteObjectMap(TByteObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteObjectMap(TByteObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(byte key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient Collection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(byte key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteSet.java b/src/gnu/trove/impl/sync/TSynchronizedByteSet.java new file mode 100644 index 0000000..4c60583 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedByteSet extends TSynchronizedByteCollection implements TByteSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedByteSet(TByteSet s) { + super(s); + } + + public TSynchronizedByteSet(TByteSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java new file mode 100644 index 0000000..c57146d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedByteShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedByteShortMap implements TByteShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TByteShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedByteShortMap(TByteShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedByteShortMap(TByteShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(byte key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(byte key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(byte key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(byte key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TByteShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TByteSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TByteSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedByteSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public byte[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public byte[] keys(byte[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TByteShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(byte key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(byte key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(byte key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java new file mode 100644 index 0000000..3740110 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharByteMap implements TCharByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharByteMap(TCharByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharByteMap(TCharByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(char key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(char key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java new file mode 100644 index 0000000..07d2746 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharCharMap implements TCharCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharCharMap(TCharCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharCharMap(TCharCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(char key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(char key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java b/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java new file mode 100644 index 0000000..63840e9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharCollection implements TCharCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TCharCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharCollection(TCharCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedCharCollection(TCharCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(char o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public char[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public char[] toArray(char[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TCharIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(char e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(char o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TCharCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(char[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TCharCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(char[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TCharCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(char[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TCharCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(char[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public char getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TCharProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java new file mode 100644 index 0000000..59dad75 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharDoubleMap implements TCharDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharDoubleMap(TCharDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharDoubleMap(TCharDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(char key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(char key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java new file mode 100644 index 0000000..55d2ca3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharFloatMap implements TCharFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharFloatMap(TCharFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharFloatMap(TCharFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(char key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(char key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java new file mode 100644 index 0000000..42a591d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharIntMap implements TCharIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharIntMap(TCharIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharIntMap(TCharIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(char key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(char key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharList.java b/src/gnu/trove/impl/sync/TSynchronizedCharList.java new file mode 100644 index 0000000..19620f2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedCharList extends TSynchronizedCharCollection implements TCharList { + + static final long serialVersionUID = -7754090372962971524L; + + final TCharList list; + + public TSynchronizedCharList(TCharList list) { + super(list); + this.list = list; + } + + public TSynchronizedCharList(TCharList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public char get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public char set(int index, char element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, char[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, char[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public char replace(int offset, char val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public char removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(char[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(char[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, char value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, char[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(char o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(char o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListCharIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListCharIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedCharList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public char[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public char[] toArray(char[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, char value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, char value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(char val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, char val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(char value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TCharList grep(TCharProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TCharList inverseGrep(TCharProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public char max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public char min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public char sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TCharProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessCharList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java new file mode 100644 index 0000000..9ba7a08 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharLongMap implements TCharLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharLongMap(TCharLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharLongMap(TCharLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(char key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(char key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java new file mode 100644 index 0000000..0cbacc8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharObjectMap implements TCharObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharObjectMap(TCharObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharObjectMap(TCharObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(char key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient Collection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(char key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharSet.java b/src/gnu/trove/impl/sync/TSynchronizedCharSet.java new file mode 100644 index 0000000..de57785 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedCharSet extends TSynchronizedCharCollection implements TCharSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedCharSet(TCharSet s) { + super(s); + } + + public TSynchronizedCharSet(TCharSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java new file mode 100644 index 0000000..2b5b4df --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedCharShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedCharShortMap implements TCharShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TCharShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedCharShortMap(TCharShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedCharShortMap(TCharShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(char key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(char key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(char key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(char key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TCharShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TCharSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TCharSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedCharSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public char[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public char[] keys(char[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TCharShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(char key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(char key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(char key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java new file mode 100644 index 0000000..01684a8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleByteMap implements TDoubleByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleByteMap(TDoubleByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleByteMap(TDoubleByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(double key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(double key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java new file mode 100644 index 0000000..9428de0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleCharMap implements TDoubleCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleCharMap(TDoubleCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleCharMap(TDoubleCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(double key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(double key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java new file mode 100644 index 0000000..44577c0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleCollection implements TDoubleCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TDoubleCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleCollection(TDoubleCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedDoubleCollection(TDoubleCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(double o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public double[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public double[] toArray(double[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TDoubleIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(double e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(double o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(double[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(double[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(double[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TDoubleCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(double[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public double getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TDoubleProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java new file mode 100644 index 0000000..b7aef8e --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleDoubleMap implements TDoubleDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleDoubleMap(TDoubleDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleDoubleMap(TDoubleDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(double key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(double key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java new file mode 100644 index 0000000..ac423dc --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleFloatMap implements TDoubleFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleFloatMap(TDoubleFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleFloatMap(TDoubleFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(double key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(double key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java new file mode 100644 index 0000000..63953e8 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleIntMap implements TDoubleIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleIntMap(TDoubleIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleIntMap(TDoubleIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(double key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(double key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java new file mode 100644 index 0000000..4590076 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedDoubleList extends TSynchronizedDoubleCollection implements TDoubleList { + + static final long serialVersionUID = -7754090372962971524L; + + final TDoubleList list; + + public TSynchronizedDoubleList(TDoubleList list) { + super(list); + this.list = list; + } + + public TSynchronizedDoubleList(TDoubleList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public double get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public double set(int index, double element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, double[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, double[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public double replace(int offset, double val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public double removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(double[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(double[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, double value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, double[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(double o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(double o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListDoubleIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListDoubleIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedDoubleList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public double[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public double[] toArray(double[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, double value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, double value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(double val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, double val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(double value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TDoubleList grep(TDoubleProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public double max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public double min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public double sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessDoubleList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java new file mode 100644 index 0000000..938aec7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleLongMap implements TDoubleLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleLongMap(TDoubleLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleLongMap(TDoubleLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(double key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(double key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java new file mode 100644 index 0000000..2af20eb --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleObjectMap implements TDoubleObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleObjectMap(TDoubleObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleObjectMap(TDoubleObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(double key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient Collection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(double key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java new file mode 100644 index 0000000..c8c5834 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedDoubleSet extends TSynchronizedDoubleCollection implements TDoubleSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedDoubleSet(TDoubleSet s) { + super(s); + } + + public TSynchronizedDoubleSet(TDoubleSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java new file mode 100644 index 0000000..32984e1 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedDoubleShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedDoubleShortMap implements TDoubleShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TDoubleShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedDoubleShortMap(TDoubleShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedDoubleShortMap(TDoubleShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(double key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(double key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(double key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(double key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TDoubleShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TDoubleSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TDoubleSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedDoubleSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public double[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public double[] keys(double[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TDoubleShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(double key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(double key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(double key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java new file mode 100644 index 0000000..d75013c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatByteMap implements TFloatByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatByteMap(TFloatByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatByteMap(TFloatByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(float key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(float key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java new file mode 100644 index 0000000..c7f8c4c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatCharMap implements TFloatCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatCharMap(TFloatCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatCharMap(TFloatCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(float key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(float key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java b/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java new file mode 100644 index 0000000..cbf6223 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatCollection implements TFloatCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TFloatCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatCollection(TFloatCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedFloatCollection(TFloatCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(float o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public float[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public float[] toArray(float[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TFloatIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(float e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(float o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TFloatCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(float[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TFloatCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(float[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TFloatCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(float[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TFloatCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(float[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public float getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TFloatProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java new file mode 100644 index 0000000..2ef040d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatDoubleMap implements TFloatDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatDoubleMap(TFloatDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatDoubleMap(TFloatDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(float key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(float key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java new file mode 100644 index 0000000..ee88c78 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatFloatMap implements TFloatFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatFloatMap(TFloatFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatFloatMap(TFloatFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(float key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(float key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java new file mode 100644 index 0000000..3b13685 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatIntMap implements TFloatIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatIntMap(TFloatIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatIntMap(TFloatIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(float key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(float key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatList.java b/src/gnu/trove/impl/sync/TSynchronizedFloatList.java new file mode 100644 index 0000000..2126b72 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedFloatList extends TSynchronizedFloatCollection implements TFloatList { + + static final long serialVersionUID = -7754090372962971524L; + + final TFloatList list; + + public TSynchronizedFloatList(TFloatList list) { + super(list); + this.list = list; + } + + public TSynchronizedFloatList(TFloatList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public float get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public float set(int index, float element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, float[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, float[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public float replace(int offset, float val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public float removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(float[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(float[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, float value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, float[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(float o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(float o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListFloatIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListFloatIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedFloatList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public float[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public float[] toArray(float[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, float value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, float value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(float val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, float val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(float value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TFloatList grep(TFloatProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public float max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public float min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public float sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessFloatList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java new file mode 100644 index 0000000..4c2dea0 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatLongMap implements TFloatLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatLongMap(TFloatLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatLongMap(TFloatLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(float key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(float key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java new file mode 100644 index 0000000..50cf76b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatObjectMap implements TFloatObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatObjectMap(TFloatObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatObjectMap(TFloatObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(float key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient Collection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(float key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java b/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java new file mode 100644 index 0000000..156230f --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedFloatSet extends TSynchronizedFloatCollection implements TFloatSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedFloatSet(TFloatSet s) { + super(s); + } + + public TSynchronizedFloatSet(TFloatSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java new file mode 100644 index 0000000..2f75a15 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedFloatShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedFloatShortMap implements TFloatShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TFloatShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedFloatShortMap(TFloatShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedFloatShortMap(TFloatShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(float key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(float key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(float key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(float key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TFloatShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TFloatSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TFloatSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedFloatSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public float[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public float[] keys(float[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TFloatShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(float key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(float key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(float key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java new file mode 100644 index 0000000..10803a5 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntByteMap implements TIntByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntByteMap(TIntByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntByteMap(TIntByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(int key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(int key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java new file mode 100644 index 0000000..58bb763 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntCharMap implements TIntCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntCharMap(TIntCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntCharMap(TIntCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(int key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(int key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java b/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java new file mode 100644 index 0000000..b23bd7b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntCollection implements TIntCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TIntCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntCollection(TIntCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedIntCollection(TIntCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(int o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public int[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public int[] toArray(int[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TIntIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(int e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(int o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TIntCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(int[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TIntCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(int[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TIntCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(int[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TIntCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(int[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public int getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java new file mode 100644 index 0000000..1a83b94 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntDoubleMap implements TIntDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntDoubleMap(TIntDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntDoubleMap(TIntDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(int key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(int key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java new file mode 100644 index 0000000..ab90333 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntFloatMap implements TIntFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntFloatMap(TIntFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntFloatMap(TIntFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(int key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(int key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java new file mode 100644 index 0000000..1632c0b --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntIntMap implements TIntIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntIntMap(TIntIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntIntMap(TIntIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(int key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(int key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntList.java b/src/gnu/trove/impl/sync/TSynchronizedIntList.java new file mode 100644 index 0000000..f8b616c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedIntList extends TSynchronizedIntCollection implements TIntList { + + static final long serialVersionUID = -7754090372962971524L; + + final TIntList list; + + public TSynchronizedIntList(TIntList list) { + super(list); + this.list = list; + } + + public TSynchronizedIntList(TIntList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public int get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public int set(int index, int element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, int[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, int[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public int replace(int offset, int val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public int removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(int[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(int[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, int value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, int[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(int o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(int o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListIntIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListIntIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedIntList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public int[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public int[] toArray(int[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, int value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, int value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(int val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, int val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(int value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TIntList grep(TIntProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TIntList inverseGrep(TIntProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public int max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public int min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public int sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TIntProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessIntList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java new file mode 100644 index 0000000..a7dd7ee --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntLongMap implements TIntLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntLongMap(TIntLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntLongMap(TIntLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(int key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(int key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java new file mode 100644 index 0000000..9dca7bb --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntObjectMap implements TIntObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntObjectMap(TIntObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntObjectMap(TIntObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(int key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient Collection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(int key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntSet.java b/src/gnu/trove/impl/sync/TSynchronizedIntSet.java new file mode 100644 index 0000000..ae76069 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedIntSet extends TSynchronizedIntCollection implements TIntSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedIntSet(TIntSet s) { + super(s); + } + + public TSynchronizedIntSet(TIntSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java new file mode 100644 index 0000000..5180a24 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedIntShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedIntShortMap implements TIntShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TIntShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedIntShortMap(TIntShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedIntShortMap(TIntShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(int key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(int key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(int key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(int key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TIntShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TIntSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TIntSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedIntSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public int[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public int[] keys(int[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TIntShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(int key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(int key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(int key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java new file mode 100644 index 0000000..0b58aad --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongByteMap implements TLongByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongByteMap(TLongByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongByteMap(TLongByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(long key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(long key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java new file mode 100644 index 0000000..e00ec1f --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongCharMap implements TLongCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongCharMap(TLongCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongCharMap(TLongCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(long key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(long key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java b/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java new file mode 100644 index 0000000..3480e5d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongCollection implements TLongCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TLongCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongCollection(TLongCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedLongCollection(TLongCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(long o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public long[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public long[] toArray(long[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TLongIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(long e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(long o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TLongCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(long[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TLongCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(long[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TLongCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(long[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TLongCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(long[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public long getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java new file mode 100644 index 0000000..9524893 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongDoubleMap implements TLongDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongDoubleMap(TLongDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongDoubleMap(TLongDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(long key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(long key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java new file mode 100644 index 0000000..d7bbe6d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongFloatMap implements TLongFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongFloatMap(TLongFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongFloatMap(TLongFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(long key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(long key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java new file mode 100644 index 0000000..bdd0155 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongIntMap implements TLongIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongIntMap(TLongIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongIntMap(TLongIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(long key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(long key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongList.java b/src/gnu/trove/impl/sync/TSynchronizedLongList.java new file mode 100644 index 0000000..42d9b00 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedLongList extends TSynchronizedLongCollection implements TLongList { + + static final long serialVersionUID = -7754090372962971524L; + + final TLongList list; + + public TSynchronizedLongList(TLongList list) { + super(list); + this.list = list; + } + + public TSynchronizedLongList(TLongList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public long get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public long set(int index, long element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, long[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, long[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public long replace(int offset, long val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public long removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(long[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(long[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, long value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, long[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(long o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(long o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListLongIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListLongIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedLongList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public long[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public long[] toArray(long[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, long value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, long value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(long val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, long val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(long value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TLongList grep(TLongProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TLongList inverseGrep(TLongProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public long max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public long min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public long sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TLongProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessLongList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java new file mode 100644 index 0000000..c1425e4 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongLongMap implements TLongLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongLongMap(TLongLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongLongMap(TLongLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(long key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(long key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java new file mode 100644 index 0000000..8fd1aa6 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongObjectMap implements TLongObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongObjectMap(TLongObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongObjectMap(TLongObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(long key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient Collection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(long key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongSet.java b/src/gnu/trove/impl/sync/TSynchronizedLongSet.java new file mode 100644 index 0000000..9596cc9 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedLongSet extends TSynchronizedLongCollection implements TLongSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedLongSet(TLongSet s) { + super(s); + } + + public TSynchronizedLongSet(TLongSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java new file mode 100644 index 0000000..c9e808e --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedLongShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedLongShortMap implements TLongShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TLongShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedLongShortMap(TLongShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedLongShortMap(TLongShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(long key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(long key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(long key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(long key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TLongShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TLongSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TLongSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedLongSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public long[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public long[] keys(long[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TLongShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(long key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(long key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(long key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java new file mode 100644 index 0000000..a1157ed --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectByteMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectByteMap implements TObjectByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectByteMap(TObjectByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectByteMap(TObjectByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(K key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TByteCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(K key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java new file mode 100644 index 0000000..1cf1f93 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectCharMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectCharMap implements TObjectCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectCharMap(TObjectCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectCharMap(TObjectCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(K key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TCharCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(K key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(K key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java new file mode 100644 index 0000000..3cecdc3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectDoubleMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectDoubleMap implements TObjectDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectDoubleMap(TObjectDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectDoubleMap(TObjectDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(K key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TDoubleCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(K key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(K key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java new file mode 100644 index 0000000..dd76251 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectFloatMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectFloatMap implements TObjectFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectFloatMap(TObjectFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectFloatMap(TObjectFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(K key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TFloatCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(K key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(K key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java new file mode 100644 index 0000000..12198ab --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectIntMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectIntMap implements TObjectIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectIntMap(TObjectIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectIntMap(TObjectIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(K key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TIntCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(K key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(K key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java new file mode 100644 index 0000000..8ea682c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectLongMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectLongMap implements TObjectLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectLongMap(TObjectLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectLongMap(TObjectLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(K key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TLongCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(K key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(K key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java new file mode 100644 index 0000000..1d6e92c --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedObjectShortMap.java @@ -0,0 +1,281 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Set; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedObjectShortMap implements TObjectShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TObjectShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedObjectShortMap(TObjectShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedObjectShortMap(TObjectShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(Object key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(Object key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(K key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(Object key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TObjectShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient Set keySet = null; + private transient TShortCollection values = null; + + @Override + public Set keySet() { + synchronized (mutex) { + if (keySet == null) { + keySet = new SynchronizedSet(m.keySet(), mutex); + } + return keySet; + } + } + + @Override + public Object[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public K[] keys(K[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TObjectShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(K key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TObjectShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(K key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(K key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(K key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java new file mode 100644 index 0000000..1cab757 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessByteList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessByteList extends TSynchronizedByteList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessByteList(TByteList list) { + super(list); + } + + public TSynchronizedRandomAccessByteList(TByteList list, Object mutex) { + super(list, mutex); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessByteList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedByteList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java new file mode 100644 index 0000000..38fcd02 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessCharList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessCharList extends TSynchronizedCharList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessCharList(TCharList list) { + super(list); + } + + public TSynchronizedRandomAccessCharList(TCharList list, Object mutex) { + super(list, mutex); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessCharList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedCharList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java new file mode 100644 index 0000000..5454458 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessDoubleList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessDoubleList extends TSynchronizedDoubleList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessDoubleList(TDoubleList list) { + super(list); + } + + public TSynchronizedRandomAccessDoubleList(TDoubleList list, Object mutex) { + super(list, mutex); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessDoubleList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedDoubleList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java new file mode 100644 index 0000000..3d670a7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessFloatList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessFloatList extends TSynchronizedFloatList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessFloatList(TFloatList list) { + super(list); + } + + public TSynchronizedRandomAccessFloatList(TFloatList list, Object mutex) { + super(list, mutex); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessFloatList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedFloatList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java new file mode 100644 index 0000000..eb01db2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessIntList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessIntList extends TSynchronizedIntList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessIntList(TIntList list) { + super(list); + } + + public TSynchronizedRandomAccessIntList(TIntList list, Object mutex) { + super(list, mutex); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessIntList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedIntList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java new file mode 100644 index 0000000..9580cd2 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessLongList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessLongList extends TSynchronizedLongList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessLongList(TLongList list) { + super(list); + } + + public TSynchronizedRandomAccessLongList(TLongList list, Object mutex) { + super(list, mutex); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessLongList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedLongList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java new file mode 100644 index 0000000..2ae9a5a --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedRandomAccessShortList.java @@ -0,0 +1,61 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TSynchronizedRandomAccessShortList extends TSynchronizedShortList implements RandomAccess { + + static final long serialVersionUID = 1530674583602358482L; + + public TSynchronizedRandomAccessShortList(TShortList list) { + super(list); + } + + public TSynchronizedRandomAccessShortList(TShortList list, Object mutex) { + super(list, mutex); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedRandomAccessShortList(list.subList(fromIndex, toIndex), mutex); + } + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). SynchronizedList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TSynchronizedShortList(list); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java new file mode 100644 index 0000000..145b11d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortByteMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortByteMap implements TShortByteMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortByteMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortByteMap(TShortByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortByteMap(TShortByteMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(byte value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public byte get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public byte put(short key, byte value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public byte remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortByteMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TByteCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedByteCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public byte[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public byte[] values(byte[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortByteIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public byte putIfAbsent(short key, byte value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TByteFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, byte amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java new file mode 100644 index 0000000..c898911 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortCharMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortCharMap implements TShortCharMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortCharMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortCharMap(TShortCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortCharMap(TShortCharMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(char value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public char get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public char put(short key, char value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public char remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortCharMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TCharCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedCharCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public char[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public char[] values(char[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortCharIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public char putIfAbsent(short key, char value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TCharFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, char amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java b/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java new file mode 100644 index 0000000..301a3f7 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortCollection.java @@ -0,0 +1,227 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortCollection implements TShortCollection, Serializable { + private static final long serialVersionUID = 3053995032091335093L; + + final TShortCollection c; // Backing Collection + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortCollection(TShortCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + mutex = this; + } + + public TSynchronizedShortCollection(TShortCollection c, Object mutex) { + this.c = c; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return c.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return c.isEmpty(); + } + } + + @Override + public boolean contains(short o) { + synchronized (mutex) { + return c.contains(o); + } + } + + @Override + public short[] toArray() { + synchronized (mutex) { + return c.toArray(); + } + } + + @Override + public short[] toArray(short[] a) { + synchronized (mutex) { + return c.toArray(a); + } + } + + @Override + public TShortIterator iterator() { + return c.iterator(); // Must be manually synched by user! + } + + @Override + public boolean add(short e) { + synchronized (mutex) { + return c.add(e); + } + } + + @Override + public boolean remove(short o) { + synchronized (mutex) { + return c.remove(o); + } + } + + @Override + public boolean containsAll(Collection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(TShortCollection coll) { + synchronized (mutex) { + return c.containsAll(coll); + } + } + + @Override + public boolean containsAll(short[] array) { + synchronized (mutex) { + return c.containsAll(array); + } + } + + @Override + public boolean addAll(Collection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(TShortCollection coll) { + synchronized (mutex) { + return c.addAll(coll); + } + } + + @Override + public boolean addAll(short[] array) { + synchronized (mutex) { + return c.addAll(array); + } + } + + @Override + public boolean removeAll(Collection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(TShortCollection coll) { + synchronized (mutex) { + return c.removeAll(coll); + } + } + + @Override + public boolean removeAll(short[] array) { + synchronized (mutex) { + return c.removeAll(array); + } + } + + @Override + public boolean retainAll(Collection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(TShortCollection coll) { + synchronized (mutex) { + return c.retainAll(coll); + } + } + + @Override + public boolean retainAll(short[] array) { + synchronized (mutex) { + return c.retainAll(array); + } + } + + @Override + public short getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TShortProcedure procedure) { + synchronized (mutex) { + return c.forEach(procedure); + } + } + + @Override + public void clear() { + synchronized (mutex) { + c.clear(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return c.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java new file mode 100644 index 0000000..0cf6bfd --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortDoubleMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortDoubleMap implements TShortDoubleMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortDoubleMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortDoubleMap(TShortDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortDoubleMap(TShortDoubleMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(double value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public double get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public double put(short key, double value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public double remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortDoubleMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TDoubleCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedDoubleCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public double[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public double[] values(double[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortDoubleIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public double putIfAbsent(short key, double value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TDoubleFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, double amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java new file mode 100644 index 0000000..bb30526 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortFloatMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortFloatMap implements TShortFloatMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortFloatMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortFloatMap(TShortFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortFloatMap(TShortFloatMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(float value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public float get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public float put(short key, float value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public float remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortFloatMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TFloatCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedFloatCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public float[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public float[] values(float[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortFloatIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public float putIfAbsent(short key, float value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TFloatFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, float amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java new file mode 100644 index 0000000..8aa6141 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortIntMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortIntMap implements TShortIntMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortIntMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortIntMap(TShortIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortIntMap(TShortIntMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(int value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public int get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public int put(short key, int value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public int remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortIntMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TIntCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedIntCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public int[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public int[] values(int[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortIntIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public int putIfAbsent(short key, int value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TIntFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, int amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortList.java b/src/gnu/trove/impl/sync/TSynchronizedShortList.java new file mode 100644 index 0000000..59570d3 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortList.java @@ -0,0 +1,341 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TSynchronizedShortList extends TSynchronizedShortCollection implements TShortList { + + static final long serialVersionUID = -7754090372962971524L; + + final TShortList list; + + public TSynchronizedShortList(TShortList list) { + super(list); + this.list = list; + } + + public TSynchronizedShortList(TShortList list, Object mutex) { + super(list, mutex); + this.list = list; + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return list.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return list.hashCode(); + } + } + + @Override + public short get(int index) { + synchronized (mutex) { + return list.get(index); + } + } + + @Override + public short set(int index, short element) { + synchronized (mutex) { + return list.set(index, element); + } + } + + @Override + public void set(int offset, short[] values) { + synchronized (mutex) { + list.set(offset, values); + } + } + + @Override + public void set(int offset, short[] values, int valOffset, int length) { + synchronized (mutex) { + list.set(offset, values, valOffset, length); + } + } + + @Override + public short replace(int offset, short val) { + synchronized (mutex) { + return list.replace(offset, val); + } + } + + @Override + public void remove(int offset, int length) { + synchronized (mutex) { + list.remove(offset, length); + } + } + + @Override + public short removeAt(int offset) { + synchronized (mutex) { + return list.removeAt(offset); + } + } + + @Override + public void add(short[] vals) { + synchronized (mutex) { + list.add(vals); + } + } + + @Override + public void add(short[] vals, int offset, int length) { + synchronized (mutex) { + list.add(vals, offset, length); + } + } + + @Override + public void insert(int offset, short value) { + synchronized (mutex) { + list.insert(offset, value); + } + } + + @Override + public void insert(int offset, short[] values) { + synchronized (mutex) { + list.insert(offset, values); + } + } + + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + synchronized (mutex) { + list.insert(offset, values, valOffset, len); + } + } + + @Override + public int indexOf(short o) { + synchronized (mutex) { + return list.indexOf(o); + } + } + + @Override + public int lastIndexOf(short o) { + synchronized (mutex) { + return list.lastIndexOf(o); + } + } + + // public TListShortIterator listIterator() { + // return list.listIterator(); // Must be manually synched by user + // } + + // public TListShortIterator listIterator( int index ) { + // return list.listIterator( index ); // Must be manually synched by user + // } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + synchronized (mutex) { + return new TSynchronizedShortList(list.subList(fromIndex, toIndex), mutex); + } + } + + @Override + public short[] toArray(int offset, int len) { + synchronized (mutex) { + return list.toArray(offset, len); + } + } + + @Override + public short[] toArray(short[] dest, int offset, int len) { + synchronized (mutex) { + return list.toArray(dest, offset, len); + } + } + + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + synchronized (mutex) { + return list.toArray(dest, source_pos, dest_pos, len); + } + } + + @Override + public int indexOf(int offset, short value) { + synchronized (mutex) { + return list.indexOf(offset, value); + } + } + + @Override + public int lastIndexOf(int offset, short value) { + synchronized (mutex) { + return list.lastIndexOf(offset, value); + } + } + + @Override + public void fill(short val) { + synchronized (mutex) { + list.fill(val); + } + } + + @Override + public void fill(int fromIndex, int toIndex, short val) { + synchronized (mutex) { + list.fill(fromIndex, toIndex, val); + } + } + + @Override + public void reverse() { + synchronized (mutex) { + list.reverse(); + } + } + + @Override + public void reverse(int from, int to) { + synchronized (mutex) { + list.reverse(from, to); + } + } + + @Override + public void shuffle(Random rand) { + synchronized (mutex) { + list.shuffle(rand); + } + } + + @Override + public void sort() { + synchronized (mutex) { + list.sort(); + } + } + + @Override + public void sort(int fromIndex, int toIndex) { + synchronized (mutex) { + list.sort(fromIndex, toIndex); + } + } + + @Override + public int binarySearch(short value) { + synchronized (mutex) { + return list.binarySearch(value); + } + } + + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + synchronized (mutex) { + return list.binarySearch(value, fromIndex, toIndex); + } + } + + @Override + public TShortList grep(TShortProcedure condition) { + synchronized (mutex) { + return list.grep(condition); + } + } + + @Override + public TShortList inverseGrep(TShortProcedure condition) { + synchronized (mutex) { + return list.inverseGrep(condition); + } + } + + @Override + public short max() { + synchronized (mutex) { + return list.max(); + } + } + + @Override + public short min() { + synchronized (mutex) { + return list.min(); + } + } + + @Override + public short sum() { + synchronized (mutex) { + return list.sum(); + } + } + + @Override + public boolean forEachDescending(TShortProcedure procedure) { + synchronized (mutex) { + return list.forEachDescending(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + list.transformValues(function); + } + } + + /** + * SynchronizedRandomAccessList instances are serialized as SynchronizedList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * SynchronizedRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * SynchronizedList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, SynchronizedRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become SynchronizedList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TSynchronizedRandomAccessShortList(list) : this); + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java new file mode 100644 index 0000000..e7dcf7d --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortLongMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortLongMap implements TShortLongMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortLongMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortLongMap(TShortLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortLongMap(TShortLongMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(long value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public long get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public long put(short key, long value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public long remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortLongMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TLongCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedLongCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public long[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public long[] values(long[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortLongIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public long putIfAbsent(short key, long value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TLongFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, long amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java new file mode 100644 index 0000000..6c43655 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortObjectMap.java @@ -0,0 +1,260 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import java.util.Collection; +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortObjectMap implements TShortObjectMap, Serializable { + // use serialVersionUID from JDK 1.2.2 for interoperability + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortObjectMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortObjectMap(TShortObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortObjectMap(TShortObjectMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(Object value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public V get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public V put(short key, V value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public V remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortObjectMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient Collection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public Collection valueCollection() { + synchronized (mutex) { + if (values == null) { + values = new SynchronizedCollection(m.valueCollection(), mutex); + } + return values; + } + } + + @Override + public Object[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public V[] values(V[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortObjectIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public V putIfAbsent(short key, V value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortObjectProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TObjectFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortObjectProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortSet.java b/src/gnu/trove/impl/sync/TSynchronizedShortSet.java new file mode 100644 index 0000000..9266646 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortSet.java @@ -0,0 +1,58 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; + +public class TSynchronizedShortSet extends TSynchronizedShortCollection implements TShortSet { + + private static final long serialVersionUID = 487447009682186044L; + + public TSynchronizedShortSet(TShortSet s) { + super(s); + } + + public TSynchronizedShortSet(TShortSet s, Object mutex) { + super(s, mutex); + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return c.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return c.hashCode(); + } + } +} diff --git a/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java b/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java new file mode 100644 index 0000000..6f5cd74 --- /dev/null +++ b/src/gnu/trove/impl/sync/TSynchronizedShortShortMap.java @@ -0,0 +1,285 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.sync; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; +import java.io.ObjectOutputStream; +import java.io.IOException; + +public class TSynchronizedShortShortMap implements TShortShortMap, Serializable { + private static final long serialVersionUID = 1978198479659022715L; + + private final TShortShortMap m; // Backing Map + final Object mutex; // Object on which to synchronize + + public TSynchronizedShortShortMap(TShortShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + mutex = this; + } + + public TSynchronizedShortShortMap(TShortShortMap m, Object mutex) { + this.m = m; + this.mutex = mutex; + } + + @Override + public int size() { + synchronized (mutex) { + return m.size(); + } + } + + @Override + public boolean isEmpty() { + synchronized (mutex) { + return m.isEmpty(); + } + } + + @Override + public boolean containsKey(short key) { + synchronized (mutex) { + return m.containsKey(key); + } + } + + @Override + public boolean containsValue(short value) { + synchronized (mutex) { + return m.containsValue(value); + } + } + + @Override + public short get(short key) { + synchronized (mutex) { + return m.get(key); + } + } + + @Override + public short put(short key, short value) { + synchronized (mutex) { + return m.put(key, value); + } + } + + @Override + public short remove(short key) { + synchronized (mutex) { + return m.remove(key); + } + } + + @Override + public void putAll(Map map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void putAll(TShortShortMap map) { + synchronized (mutex) { + m.putAll(map); + } + } + + @Override + public void clear() { + synchronized (mutex) { + m.clear(); + } + } + + private transient TShortSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TShortSet keySet() { + synchronized (mutex) { + if (keySet == null) + keySet = new TSynchronizedShortSet(m.keySet(), mutex); + return keySet; + } + } + + @Override + public short[] keys() { + synchronized (mutex) { + return m.keys(); + } + } + + @Override + public short[] keys(short[] array) { + synchronized (mutex) { + return m.keys(array); + } + } + + @Override + public TShortCollection valueCollection() { + synchronized (mutex) { + if (values == null) + values = new TSynchronizedShortCollection(m.valueCollection(), mutex); + return values; + } + } + + @Override + public short[] values() { + synchronized (mutex) { + return m.values(); + } + } + + @Override + public short[] values(short[] array) { + synchronized (mutex) { + return m.values(array); + } + } + + @Override + public TShortShortIterator iterator() { + return m.iterator(); // Must be manually synched by user! + } + + // these are unchanging over the life of the map, no need to lock + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public short putIfAbsent(short key, short value) { + synchronized (mutex) { + return m.putIfAbsent(key, value); + } + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachKey(procedure); + } + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + synchronized (mutex) { + return m.forEachValue(procedure); + } + } + + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + synchronized (mutex) { + return m.forEachEntry(procedure); + } + } + + @Override + public void transformValues(TShortFunction function) { + synchronized (mutex) { + m.transformValues(function); + } + } + + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + synchronized (mutex) { + return m.retainEntries(procedure); + } + } + + @Override + public boolean increment(short key) { + synchronized (mutex) { + return m.increment(key); + } + } + + @Override + public boolean adjustValue(short key, short amount) { + synchronized (mutex) { + return m.adjustValue(key, amount); + } + } + + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + synchronized (mutex) { + return m.adjustOrPutValue(key, adjust_amount, put_amount); + } + } + + @Override + public boolean equals(Object o) { + synchronized (mutex) { + return m.equals(o); + } + } + + @Override + public int hashCode() { + synchronized (mutex) { + return m.hashCode(); + } + } + + @Override + public String toString() { + synchronized (mutex) { + return m.toString(); + } + } + + private void writeObject(ObjectOutputStream s) throws IOException { + synchronized (mutex) { + s.defaultWriteObject(); + } + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java new file mode 100644 index 0000000..1505442 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteByteMap implements TByteByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteByteMap m; + + public TUnmodifiableByteByteMap(TByteByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(byte key) { + return m.get(key); + } + + @Override + public byte put(byte key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteByteIterator iterator() { + return new TByteByteIterator() { + TByteByteIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(byte key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java new file mode 100644 index 0000000..5adabbd --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteCharMap implements TByteCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteCharMap m; + + public TUnmodifiableByteCharMap(TByteCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(byte key) { + return m.get(key); + } + + @Override + public char put(byte key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteCharIterator iterator() { + return new TByteCharIterator() { + TByteCharIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(byte key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java new file mode 100644 index 0000000..c9537d7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableByteCollection implements TByteCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TByteCollection c; + + public TUnmodifiableByteCollection(TByteCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(byte o) { + return c.contains(o); + } + + @Override + public byte[] toArray() { + return c.toArray(); + } + + @Override + public byte[] toArray(byte[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public byte getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TByteProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TByteIterator iterator() { + return new TByteIterator() { + TByteIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public byte next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(byte e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(byte o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TByteCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(byte[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TByteCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java new file mode 100644 index 0000000..ad6d17c --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteDoubleMap implements TByteDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteDoubleMap m; + + public TUnmodifiableByteDoubleMap(TByteDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(byte key) { + return m.get(key); + } + + @Override + public double put(byte key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteDoubleIterator iterator() { + return new TByteDoubleIterator() { + TByteDoubleIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(byte key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java new file mode 100644 index 0000000..27f6464 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteFloatMap implements TByteFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteFloatMap m; + + public TUnmodifiableByteFloatMap(TByteFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(byte key) { + return m.get(key); + } + + @Override + public float put(byte key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteFloatIterator iterator() { + return new TByteFloatIterator() { + TByteFloatIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(byte key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java new file mode 100644 index 0000000..2c6b0d7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteIntMap implements TByteIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteIntMap m; + + public TUnmodifiableByteIntMap(TByteIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(byte key) { + return m.get(key); + } + + @Override + public int put(byte key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteIntIterator iterator() { + return new TByteIntIterator() { + TByteIntIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(byte key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java new file mode 100644 index 0000000..724f15c --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableByteList extends TUnmodifiableByteCollection implements TByteList { + static final long serialVersionUID = -283967356065247728L; + + final TByteList list; + + public TUnmodifiableByteList(TByteList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public byte get(int index) { + return list.get(index); + } + + @Override + public int indexOf(byte o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(byte o) { + return list.lastIndexOf(o); + } + + @Override + public byte[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TByteProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(byte value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, byte value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, byte value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TByteList grep(TByteProcedure condition) { + return list.grep(condition); + } + + @Override + public TByteList inverseGrep(TByteProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public byte max() { + return list.max(); + } + + @Override + public byte min() { + return list.min(); + } + + @Override + public byte sum() { + return list.sum(); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + return new TUnmodifiableByteList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessByteList(list) : this); + } + + @Override + public void add(byte[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(byte[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public byte removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public byte set(int offset, byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, byte[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public byte replace(int offset, byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, byte val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java new file mode 100644 index 0000000..d08c5c9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteLongMap implements TByteLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteLongMap m; + + public TUnmodifiableByteLongMap(TByteLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(byte key) { + return m.get(key); + } + + @Override + public long put(byte key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteLongIterator iterator() { + return new TByteLongIterator() { + TByteLongIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(byte key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java new file mode 100644 index 0000000..43d2b3b --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableByteObjectMap implements TByteObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteObjectMap m; + + public TUnmodifiableByteObjectMap(TByteObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(byte key) { + return m.get(key); + } + + @Override + public V put(byte key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient Collection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteObjectIterator iterator() { + return new TByteObjectIterator() { + TByteObjectIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(byte key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java new file mode 100644 index 0000000..e1a67b7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableByteSet extends TUnmodifiableByteCollection implements TByteSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableByteSet(TByteSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java new file mode 100644 index 0000000..43cb0c2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableByteShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableByteShortMap implements TByteShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TByteShortMap m; + + public TUnmodifiableByteShortMap(TByteShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(byte key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(byte key) { + return m.get(key); + } + + @Override + public short put(byte key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TByteShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TByteSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TByteSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public byte[] keys() { + return m.keys(); + } + + @Override + public byte[] keys(byte[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TByteProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TByteShortIterator iterator() { + return new TByteShortIterator() { + TByteShortIterator iter = m.iterator(); + + @Override + public byte key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(byte key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(byte key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(byte key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java new file mode 100644 index 0000000..2349057 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharByteMap implements TCharByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharByteMap m; + + public TUnmodifiableCharByteMap(TCharByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(char key) { + return m.get(key); + } + + @Override + public byte put(char key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharByteIterator iterator() { + return new TCharByteIterator() { + TCharByteIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(char key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java new file mode 100644 index 0000000..fbacb4e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharCharMap implements TCharCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharCharMap m; + + public TUnmodifiableCharCharMap(TCharCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(char key) { + return m.get(key); + } + + @Override + public char put(char key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharCharIterator iterator() { + return new TCharCharIterator() { + TCharCharIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(char key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java new file mode 100644 index 0000000..efd4e3a --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableCharCollection implements TCharCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TCharCollection c; + + public TUnmodifiableCharCollection(TCharCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(char o) { + return c.contains(o); + } + + @Override + public char[] toArray() { + return c.toArray(); + } + + @Override + public char[] toArray(char[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public char getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TCharProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TCharIterator iterator() { + return new TCharIterator() { + TCharIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public char next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(char e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(char o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TCharCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(char[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TCharCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(char[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java new file mode 100644 index 0000000..064d1dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharDoubleMap implements TCharDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharDoubleMap m; + + public TUnmodifiableCharDoubleMap(TCharDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(char key) { + return m.get(key); + } + + @Override + public double put(char key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharDoubleIterator iterator() { + return new TCharDoubleIterator() { + TCharDoubleIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(char key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java new file mode 100644 index 0000000..39bbdea --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharFloatMap implements TCharFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharFloatMap m; + + public TUnmodifiableCharFloatMap(TCharFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(char key) { + return m.get(key); + } + + @Override + public float put(char key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharFloatIterator iterator() { + return new TCharFloatIterator() { + TCharFloatIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(char key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java new file mode 100644 index 0000000..5463e90 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharIntMap implements TCharIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharIntMap m; + + public TUnmodifiableCharIntMap(TCharIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(char key) { + return m.get(key); + } + + @Override + public int put(char key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharIntIterator iterator() { + return new TCharIntIterator() { + TCharIntIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(char key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java new file mode 100644 index 0000000..dbd5de7 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableCharList extends TUnmodifiableCharCollection implements TCharList { + static final long serialVersionUID = -283967356065247728L; + + final TCharList list; + + public TUnmodifiableCharList(TCharList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public char get(int index) { + return list.get(index); + } + + @Override + public int indexOf(char o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(char o) { + return list.lastIndexOf(o); + } + + @Override + public char[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public char[] toArray(char[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TCharProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(char value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, char value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, char value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TCharList grep(TCharProcedure condition) { + return list.grep(condition); + } + + @Override + public TCharList inverseGrep(TCharProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public char max() { + return list.max(); + } + + @Override + public char min() { + return list.min(); + } + + @Override + public char sum() { + return list.sum(); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + return new TUnmodifiableCharList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessCharList(list) : this); + } + + @Override + public void add(char[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(char[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public char removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public char set(int offset, char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, char[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, char[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public char replace(int offset, char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, char val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java new file mode 100644 index 0000000..c8189e6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharLongMap implements TCharLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharLongMap m; + + public TUnmodifiableCharLongMap(TCharLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(char key) { + return m.get(key); + } + + @Override + public long put(char key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharLongIterator iterator() { + return new TCharLongIterator() { + TCharLongIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(char key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java new file mode 100644 index 0000000..484d8ad --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableCharObjectMap implements TCharObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharObjectMap m; + + public TUnmodifiableCharObjectMap(TCharObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(char key) { + return m.get(key); + } + + @Override + public V put(char key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient Collection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharObjectIterator iterator() { + return new TCharObjectIterator() { + TCharObjectIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(char key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java new file mode 100644 index 0000000..c15c732 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableCharSet extends TUnmodifiableCharCollection implements TCharSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableCharSet(TCharSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java new file mode 100644 index 0000000..f7ff877 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableCharShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableCharShortMap implements TCharShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TCharShortMap m; + + public TUnmodifiableCharShortMap(TCharShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(char key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(char key) { + return m.get(key); + } + + @Override + public short put(char key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TCharShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TCharSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TCharSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public char[] keys() { + return m.keys(); + } + + @Override + public char[] keys(char[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TCharProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TCharShortIterator iterator() { + return new TCharShortIterator() { + TCharShortIterator iter = m.iterator(); + + @Override + public char key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(char key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(char key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(char key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java new file mode 100644 index 0000000..ae6d281 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleByteMap implements TDoubleByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleByteMap m; + + public TUnmodifiableDoubleByteMap(TDoubleByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(double key) { + return m.get(key); + } + + @Override + public byte put(double key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleByteIterator iterator() { + return new TDoubleByteIterator() { + TDoubleByteIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(double key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java new file mode 100644 index 0000000..473e4e9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleCharMap implements TDoubleCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleCharMap m; + + public TUnmodifiableDoubleCharMap(TDoubleCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(double key) { + return m.get(key); + } + + @Override + public char put(double key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleCharIterator iterator() { + return new TDoubleCharIterator() { + TDoubleCharIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(double key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java new file mode 100644 index 0000000..cd82ed0 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableDoubleCollection implements TDoubleCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TDoubleCollection c; + + public TUnmodifiableDoubleCollection(TDoubleCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(double o) { + return c.contains(o); + } + + @Override + public double[] toArray() { + return c.toArray(); + } + + @Override + public double[] toArray(double[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public double getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TDoubleProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TDoubleIterator iterator() { + return new TDoubleIterator() { + TDoubleIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public double next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(double e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(double o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TDoubleCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(double[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TDoubleCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(double[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java new file mode 100644 index 0000000..07152ab --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleDoubleMap implements TDoubleDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleDoubleMap m; + + public TUnmodifiableDoubleDoubleMap(TDoubleDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(double key) { + return m.get(key); + } + + @Override + public double put(double key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleDoubleIterator iterator() { + return new TDoubleDoubleIterator() { + TDoubleDoubleIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(double key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java new file mode 100644 index 0000000..ee6145f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleFloatMap implements TDoubleFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleFloatMap m; + + public TUnmodifiableDoubleFloatMap(TDoubleFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(double key) { + return m.get(key); + } + + @Override + public float put(double key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleFloatIterator iterator() { + return new TDoubleFloatIterator() { + TDoubleFloatIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(double key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java new file mode 100644 index 0000000..18986f3 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleIntMap implements TDoubleIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleIntMap m; + + public TUnmodifiableDoubleIntMap(TDoubleIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(double key) { + return m.get(key); + } + + @Override + public int put(double key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleIntIterator iterator() { + return new TDoubleIntIterator() { + TDoubleIntIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(double key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java new file mode 100644 index 0000000..ee6707e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableDoubleList extends TUnmodifiableDoubleCollection implements TDoubleList { + static final long serialVersionUID = -283967356065247728L; + + final TDoubleList list; + + public TUnmodifiableDoubleList(TDoubleList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public double get(int index) { + return list.get(index); + } + + @Override + public int indexOf(double o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(double o) { + return list.lastIndexOf(o); + } + + @Override + public double[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public double[] toArray(double[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(double value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, double value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, double value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TDoubleList grep(TDoubleProcedure condition) { + return list.grep(condition); + } + + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public double max() { + return list.max(); + } + + @Override + public double min() { + return list.min(); + } + + @Override + public double sum() { + return list.sum(); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + return new TUnmodifiableDoubleList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessDoubleList(list) : this); + } + + @Override + public void add(double[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(double[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public double removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public double set(int offset, double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, double[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, double[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public double replace(int offset, double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, double val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java new file mode 100644 index 0000000..8a6f3e5 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleLongMap implements TDoubleLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleLongMap m; + + public TUnmodifiableDoubleLongMap(TDoubleLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(double key) { + return m.get(key); + } + + @Override + public long put(double key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleLongIterator iterator() { + return new TDoubleLongIterator() { + TDoubleLongIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(double key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java new file mode 100644 index 0000000..3e5125f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableDoubleObjectMap implements TDoubleObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleObjectMap m; + + public TUnmodifiableDoubleObjectMap(TDoubleObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(double key) { + return m.get(key); + } + + @Override + public V put(double key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient Collection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleObjectIterator iterator() { + return new TDoubleObjectIterator() { + TDoubleObjectIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(double key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java new file mode 100644 index 0000000..c171edb --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableDoubleSet extends TUnmodifiableDoubleCollection implements TDoubleSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableDoubleSet(TDoubleSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java new file mode 100644 index 0000000..8569f3f --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableDoubleShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableDoubleShortMap implements TDoubleShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TDoubleShortMap m; + + public TUnmodifiableDoubleShortMap(TDoubleShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(double key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(double key) { + return m.get(key); + } + + @Override + public short put(double key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TDoubleShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TDoubleSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TDoubleSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public double[] keys() { + return m.keys(); + } + + @Override + public double[] keys(double[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TDoubleShortIterator iterator() { + return new TDoubleShortIterator() { + TDoubleShortIterator iter = m.iterator(); + + @Override + public double key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(double key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(double key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(double key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java new file mode 100644 index 0000000..f97245e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatByteMap implements TFloatByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatByteMap m; + + public TUnmodifiableFloatByteMap(TFloatByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(float key) { + return m.get(key); + } + + @Override + public byte put(float key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatByteIterator iterator() { + return new TFloatByteIterator() { + TFloatByteIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(float key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java new file mode 100644 index 0000000..9e7a6d6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatCharMap implements TFloatCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatCharMap m; + + public TUnmodifiableFloatCharMap(TFloatCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(float key) { + return m.get(key); + } + + @Override + public char put(float key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatCharIterator iterator() { + return new TFloatCharIterator() { + TFloatCharIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(float key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java new file mode 100644 index 0000000..7e45d4e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableFloatCollection implements TFloatCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TFloatCollection c; + + public TUnmodifiableFloatCollection(TFloatCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(float o) { + return c.contains(o); + } + + @Override + public float[] toArray() { + return c.toArray(); + } + + @Override + public float[] toArray(float[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public float getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TFloatProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TFloatIterator iterator() { + return new TFloatIterator() { + TFloatIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public float next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(float e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(float o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TFloatCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(float[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TFloatCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(float[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java new file mode 100644 index 0000000..691b486 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatDoubleMap implements TFloatDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatDoubleMap m; + + public TUnmodifiableFloatDoubleMap(TFloatDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(float key) { + return m.get(key); + } + + @Override + public double put(float key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatDoubleIterator iterator() { + return new TFloatDoubleIterator() { + TFloatDoubleIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(float key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java new file mode 100644 index 0000000..f6ba251 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatFloatMap implements TFloatFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatFloatMap m; + + public TUnmodifiableFloatFloatMap(TFloatFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(float key) { + return m.get(key); + } + + @Override + public float put(float key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatFloatIterator iterator() { + return new TFloatFloatIterator() { + TFloatFloatIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(float key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java new file mode 100644 index 0000000..87dbbc2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatIntMap implements TFloatIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatIntMap m; + + public TUnmodifiableFloatIntMap(TFloatIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(float key) { + return m.get(key); + } + + @Override + public int put(float key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatIntIterator iterator() { + return new TFloatIntIterator() { + TFloatIntIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(float key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java new file mode 100644 index 0000000..ffb9dbc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableFloatList extends TUnmodifiableFloatCollection implements TFloatList { + static final long serialVersionUID = -283967356065247728L; + + final TFloatList list; + + public TUnmodifiableFloatList(TFloatList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public float get(int index) { + return list.get(index); + } + + @Override + public int indexOf(float o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(float o) { + return list.lastIndexOf(o); + } + + @Override + public float[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public float[] toArray(float[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(float value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, float value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, float value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TFloatList grep(TFloatProcedure condition) { + return list.grep(condition); + } + + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public float max() { + return list.max(); + } + + @Override + public float min() { + return list.min(); + } + + @Override + public float sum() { + return list.sum(); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + return new TUnmodifiableFloatList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessFloatList(list) : this); + } + + @Override + public void add(float[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(float[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public float removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public float set(int offset, float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, float[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, float[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public float replace(int offset, float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, float val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java new file mode 100644 index 0000000..fd51057 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatLongMap implements TFloatLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatLongMap m; + + public TUnmodifiableFloatLongMap(TFloatLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(float key) { + return m.get(key); + } + + @Override + public long put(float key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatLongIterator iterator() { + return new TFloatLongIterator() { + TFloatLongIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(float key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java new file mode 100644 index 0000000..0df1073 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableFloatObjectMap implements TFloatObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatObjectMap m; + + public TUnmodifiableFloatObjectMap(TFloatObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(float key) { + return m.get(key); + } + + @Override + public V put(float key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient Collection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatObjectIterator iterator() { + return new TFloatObjectIterator() { + TFloatObjectIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(float key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java new file mode 100644 index 0000000..886e8c5 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableFloatSet extends TUnmodifiableFloatCollection implements TFloatSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableFloatSet(TFloatSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java new file mode 100644 index 0000000..8600dfc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableFloatShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableFloatShortMap implements TFloatShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TFloatShortMap m; + + public TUnmodifiableFloatShortMap(TFloatShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(float key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(float key) { + return m.get(key); + } + + @Override + public short put(float key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TFloatShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TFloatSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TFloatSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public float[] keys() { + return m.keys(); + } + + @Override + public float[] keys(float[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TFloatShortIterator iterator() { + return new TFloatShortIterator() { + TFloatShortIterator iter = m.iterator(); + + @Override + public float key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(float key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(float key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(float key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java new file mode 100644 index 0000000..c519991 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntByteMap implements TIntByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntByteMap m; + + public TUnmodifiableIntByteMap(TIntByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(int key) { + return m.get(key); + } + + @Override + public byte put(int key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntByteIterator iterator() { + return new TIntByteIterator() { + TIntByteIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(int key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java new file mode 100644 index 0000000..b7ad673 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntCharMap implements TIntCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntCharMap m; + + public TUnmodifiableIntCharMap(TIntCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(int key) { + return m.get(key); + } + + @Override + public char put(int key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntCharIterator iterator() { + return new TIntCharIterator() { + TIntCharIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(int key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java new file mode 100644 index 0000000..93c6a90 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableIntCollection implements TIntCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TIntCollection c; + + public TUnmodifiableIntCollection(TIntCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(int o) { + return c.contains(o); + } + + @Override + public int[] toArray() { + return c.toArray(); + } + + @Override + public int[] toArray(int[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public int getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TIntIterator iterator() { + return new TIntIterator() { + TIntIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public int next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(int e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(int o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TIntCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(int[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TIntCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java new file mode 100644 index 0000000..1b87709 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntDoubleMap implements TIntDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntDoubleMap m; + + public TUnmodifiableIntDoubleMap(TIntDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(int key) { + return m.get(key); + } + + @Override + public double put(int key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntDoubleIterator iterator() { + return new TIntDoubleIterator() { + TIntDoubleIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(int key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java new file mode 100644 index 0000000..0ff22dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntFloatMap implements TIntFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntFloatMap m; + + public TUnmodifiableIntFloatMap(TIntFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(int key) { + return m.get(key); + } + + @Override + public float put(int key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntFloatIterator iterator() { + return new TIntFloatIterator() { + TIntFloatIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(int key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java new file mode 100644 index 0000000..ad43bb4 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntIntMap implements TIntIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntIntMap m; + + public TUnmodifiableIntIntMap(TIntIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(int key) { + return m.get(key); + } + + @Override + public int put(int key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntIntIterator iterator() { + return new TIntIntIterator() { + TIntIntIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(int key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java new file mode 100644 index 0000000..089fb2a --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableIntList extends TUnmodifiableIntCollection implements TIntList { + static final long serialVersionUID = -283967356065247728L; + + final TIntList list; + + public TUnmodifiableIntList(TIntList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public int get(int index) { + return list.get(index); + } + + @Override + public int indexOf(int o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(int o) { + return list.lastIndexOf(o); + } + + @Override + public int[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public int[] toArray(int[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TIntProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(int value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, int value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, int value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TIntList grep(TIntProcedure condition) { + return list.grep(condition); + } + + @Override + public TIntList inverseGrep(TIntProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public int max() { + return list.max(); + } + + @Override + public int min() { + return list.min(); + } + + @Override + public int sum() { + return list.sum(); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + return new TUnmodifiableIntList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessIntList(list) : this); + } + + @Override + public void add(int[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(int[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public int removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public int set(int offset, int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, int[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, int[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public int replace(int offset, int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, int val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java new file mode 100644 index 0000000..3e8ebf9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntLongMap implements TIntLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntLongMap m; + + public TUnmodifiableIntLongMap(TIntLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(int key) { + return m.get(key); + } + + @Override + public long put(int key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntLongIterator iterator() { + return new TIntLongIterator() { + TIntLongIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(int key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java new file mode 100644 index 0000000..067cf69 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableIntObjectMap implements TIntObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntObjectMap m; + + public TUnmodifiableIntObjectMap(TIntObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(int key) { + return m.get(key); + } + + @Override + public V put(int key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient Collection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntObjectIterator iterator() { + return new TIntObjectIterator() { + TIntObjectIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(int key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java new file mode 100644 index 0000000..a924fbf --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableIntSet extends TUnmodifiableIntCollection implements TIntSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableIntSet(TIntSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java new file mode 100644 index 0000000..9751db2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableIntShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableIntShortMap implements TIntShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TIntShortMap m; + + public TUnmodifiableIntShortMap(TIntShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(int key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(int key) { + return m.get(key); + } + + @Override + public short put(int key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TIntShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TIntSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TIntSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public int[] keys() { + return m.keys(); + } + + @Override + public int[] keys(int[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TIntShortIterator iterator() { + return new TIntShortIterator() { + TIntShortIterator iter = m.iterator(); + + @Override + public int key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(int key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(int key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(int key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java new file mode 100644 index 0000000..6d475f6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongByteMap implements TLongByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongByteMap m; + + public TUnmodifiableLongByteMap(TLongByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(long key) { + return m.get(key); + } + + @Override + public byte put(long key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongByteIterator iterator() { + return new TLongByteIterator() { + TLongByteIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(long key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java new file mode 100644 index 0000000..723da6d --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongCharMap implements TLongCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongCharMap m; + + public TUnmodifiableLongCharMap(TLongCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(long key) { + return m.get(key); + } + + @Override + public char put(long key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongCharIterator iterator() { + return new TLongCharIterator() { + TLongCharIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(long key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java new file mode 100644 index 0000000..f71be15 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableLongCollection implements TLongCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TLongCollection c; + + public TUnmodifiableLongCollection(TLongCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(long o) { + return c.contains(o); + } + + @Override + public long[] toArray() { + return c.toArray(); + } + + @Override + public long[] toArray(long[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public long getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TLongIterator iterator() { + return new TLongIterator() { + TLongIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public long next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(long e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(long o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TLongCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(long[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TLongCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java new file mode 100644 index 0000000..7c82256 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongDoubleMap implements TLongDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongDoubleMap m; + + public TUnmodifiableLongDoubleMap(TLongDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(long key) { + return m.get(key); + } + + @Override + public double put(long key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongDoubleIterator iterator() { + return new TLongDoubleIterator() { + TLongDoubleIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(long key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java new file mode 100644 index 0000000..3401b25 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongFloatMap implements TLongFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongFloatMap m; + + public TUnmodifiableLongFloatMap(TLongFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(long key) { + return m.get(key); + } + + @Override + public float put(long key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongFloatIterator iterator() { + return new TLongFloatIterator() { + TLongFloatIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(long key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java new file mode 100644 index 0000000..a1c0742 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongIntMap implements TLongIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongIntMap m; + + public TUnmodifiableLongIntMap(TLongIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(long key) { + return m.get(key); + } + + @Override + public int put(long key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongIntIterator iterator() { + return new TLongIntIterator() { + TLongIntIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(long key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java new file mode 100644 index 0000000..c3ba351 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableLongList extends TUnmodifiableLongCollection implements TLongList { + static final long serialVersionUID = -283967356065247728L; + + final TLongList list; + + public TUnmodifiableLongList(TLongList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public long get(int index) { + return list.get(index); + } + + @Override + public int indexOf(long o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(long o) { + return list.lastIndexOf(o); + } + + @Override + public long[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public long[] toArray(long[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TLongProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(long value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, long value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, long value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TLongList grep(TLongProcedure condition) { + return list.grep(condition); + } + + @Override + public TLongList inverseGrep(TLongProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public long max() { + return list.max(); + } + + @Override + public long min() { + return list.min(); + } + + @Override + public long sum() { + return list.sum(); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + return new TUnmodifiableLongList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessLongList(list) : this); + } + + @Override + public void add(long[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(long[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public long removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public long set(int offset, long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, long[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, long[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public long replace(int offset, long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, long val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java new file mode 100644 index 0000000..8ab49dc --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongLongMap implements TLongLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongLongMap m; + + public TUnmodifiableLongLongMap(TLongLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(long key) { + return m.get(key); + } + + @Override + public long put(long key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongLongIterator iterator() { + return new TLongLongIterator() { + TLongLongIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(long key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java new file mode 100644 index 0000000..25c6c66 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableLongObjectMap implements TLongObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongObjectMap m; + + public TUnmodifiableLongObjectMap(TLongObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(long key) { + return m.get(key); + } + + @Override + public V put(long key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient Collection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongObjectIterator iterator() { + return new TLongObjectIterator() { + TLongObjectIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(long key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java new file mode 100644 index 0000000..2bda514 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableLongSet extends TUnmodifiableLongCollection implements TLongSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableLongSet(TLongSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java new file mode 100644 index 0000000..c91df9e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableLongShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableLongShortMap implements TLongShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TLongShortMap m; + + public TUnmodifiableLongShortMap(TLongShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(long key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(long key) { + return m.get(key); + } + + @Override + public short put(long key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TLongShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TLongSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TLongSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public long[] keys() { + return m.keys(); + } + + @Override + public long[] keys(long[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TLongShortIterator iterator() { + return new TLongShortIterator() { + TLongShortIterator iter = m.iterator(); + + @Override + public long key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(long key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(long key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(long key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java new file mode 100644 index 0000000..6368c21 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectByteMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectByteMap implements TObjectByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectByteMap m; + + public TUnmodifiableObjectByteMap(TObjectByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(Object key) { + return m.get(key); + } + + @Override + public byte put(K key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TByteCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectByteIterator iterator() { + return new TObjectByteIterator() { + TObjectByteIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(K key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java new file mode 100644 index 0000000..f12fb07 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectCharMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectCharMap implements TObjectCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectCharMap m; + + public TUnmodifiableObjectCharMap(TObjectCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(Object key) { + return m.get(key); + } + + @Override + public char put(K key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TCharCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectCharIterator iterator() { + return new TObjectCharIterator() { + TObjectCharIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(K key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(K key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java new file mode 100644 index 0000000..0e8c801 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectDoubleMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectDoubleMap implements TObjectDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectDoubleMap m; + + public TUnmodifiableObjectDoubleMap(TObjectDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(Object key) { + return m.get(key); + } + + @Override + public double put(K key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TDoubleCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleIterator() { + TObjectDoubleIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(K key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(K key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java new file mode 100644 index 0000000..7560ca4 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectFloatMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectFloatMap implements TObjectFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectFloatMap m; + + public TUnmodifiableObjectFloatMap(TObjectFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(Object key) { + return m.get(key); + } + + @Override + public float put(K key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TFloatCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatIterator() { + TObjectFloatIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(K key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(K key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java new file mode 100644 index 0000000..ab5e398 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectIntMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectIntMap implements TObjectIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectIntMap m; + + public TUnmodifiableObjectIntMap(TObjectIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(Object key) { + return m.get(key); + } + + @Override + public int put(K key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TIntCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectIntIterator iterator() { + return new TObjectIntIterator() { + TObjectIntIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(K key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(K key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java new file mode 100644 index 0000000..af0aa5d --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectLongMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectLongMap implements TObjectLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectLongMap m; + + public TUnmodifiableObjectLongMap(TObjectLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(Object key) { + return m.get(key); + } + + @Override + public long put(K key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TLongCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectLongIterator iterator() { + return new TObjectLongIterator() { + TObjectLongIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(K key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(K key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java new file mode 100644 index 0000000..d199d23 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableObjectShortMap.java @@ -0,0 +1,239 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableObjectShortMap implements TObjectShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TObjectShortMap m; + + public TUnmodifiableObjectShortMap(TObjectShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(Object key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(Object key) { + return m.get(key); + } + + @Override + public short put(K key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(Object key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TObjectShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient Set keySet = null; + private transient TShortCollection values = null; + + @Override + public Set keySet() { + if (keySet == null) + keySet = Collections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public Object[] keys() { + return m.keys(); + } + + @Override + public K[] keys(K[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TObjectShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TObjectShortIterator iterator() { + return new TObjectShortIterator() { + TObjectShortIterator iter = m.iterator(); + + @Override + public K key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(K key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(K key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(K key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(K key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java new file mode 100644 index 0000000..2146663 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessByteList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessByteList extends TUnmodifiableByteList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessByteList(TByteList list) { + super(list); + } + + @Override + public TByteList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessByteList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableByteList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java new file mode 100644 index 0000000..6e62a7b --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessCharList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessCharList extends TUnmodifiableCharList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessCharList(TCharList list) { + super(list); + } + + @Override + public TCharList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessCharList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableCharList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java new file mode 100644 index 0000000..5e0b826 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessDoubleList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessDoubleList extends TUnmodifiableDoubleList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessDoubleList(TDoubleList list) { + super(list); + } + + @Override + public TDoubleList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessDoubleList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableDoubleList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java new file mode 100644 index 0000000..d024238 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessFloatList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessFloatList extends TUnmodifiableFloatList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessFloatList(TFloatList list) { + super(list); + } + + @Override + public TFloatList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessFloatList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableFloatList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java new file mode 100644 index 0000000..7322e68 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessIntList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessIntList extends TUnmodifiableIntList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessIntList(TIntList list) { + super(list); + } + + @Override + public TIntList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessIntList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableIntList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java new file mode 100644 index 0000000..97b1f18 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessLongList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessLongList extends TUnmodifiableLongList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessLongList(TLongList list) { + super(list); + } + + @Override + public TLongList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessLongList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableLongList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java new file mode 100644 index 0000000..f4d8577 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableRandomAccessShortList.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.list.*; +import java.util.RandomAccess; + +public class TUnmodifiableRandomAccessShortList extends TUnmodifiableShortList implements RandomAccess { + + private static final long serialVersionUID = -2542308836966382001L; + + public TUnmodifiableRandomAccessShortList(TShortList list) { + super(list); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + return new TUnmodifiableRandomAccessShortList(list.subList(fromIndex, toIndex)); + } + + /** + * Allows instances to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). UnmodifiableList has a readResolve method that + * inverts this transformation upon deserialization. + */ + private Object writeReplace() { + return new TUnmodifiableShortList(list); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java new file mode 100644 index 0000000..428f167 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortByteMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortByteMap implements TShortByteMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortByteMap m; + + public TUnmodifiableShortByteMap(TShortByteMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(byte val) { + return m.containsValue(val); + } + + @Override + public byte get(short key) { + return m.get(key); + } + + @Override + public byte put(short key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public byte remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortByteMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TByteCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TByteCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public byte[] values() { + return m.values(); + } + + @Override + public byte[] values(byte[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public byte getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TByteProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortByteIterator iterator() { + return new TShortByteIterator() { + TShortByteIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public byte value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public byte setValue(byte val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public byte putIfAbsent(short key, byte value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TByteFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, byte amount) { + throw new UnsupportedOperationException(); + } + + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java new file mode 100644 index 0000000..3c20369 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCharMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortCharMap implements TShortCharMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortCharMap m; + + public TUnmodifiableShortCharMap(TShortCharMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(char val) { + return m.containsValue(val); + } + + @Override + public char get(short key) { + return m.get(key); + } + + @Override + public char put(short key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public char remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortCharMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TCharCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TCharCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public char[] values() { + return m.values(); + } + + @Override + public char[] values(char[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public char getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TCharProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortCharIterator iterator() { + return new TShortCharIterator() { + TShortCharIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public char value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public char setValue(char val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public char putIfAbsent(short key, char value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TCharFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, char amount) { + throw new UnsupportedOperationException(); + } + + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java new file mode 100644 index 0000000..b5280cd --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortCollection.java @@ -0,0 +1,185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.*; + +import java.util.Collection; +import java.io.Serializable; + +public class TUnmodifiableShortCollection implements TShortCollection, Serializable { + private static final long serialVersionUID = 1820017752578914078L; + + final TShortCollection c; + + public TUnmodifiableShortCollection(TShortCollection c) { + if (c == null) + throw new NullPointerException(); + this.c = c; + } + + @Override + public int size() { + return c.size(); + } + + @Override + public boolean isEmpty() { + return c.isEmpty(); + } + + @Override + public boolean contains(short o) { + return c.contains(o); + } + + @Override + public short[] toArray() { + return c.toArray(); + } + + @Override + public short[] toArray(short[] a) { + return c.toArray(a); + } + + @Override + public String toString() { + return c.toString(); + } + + @Override + public short getNoEntryValue() { + return c.getNoEntryValue(); + } + + @Override + public boolean forEach(TShortProcedure procedure) { + return c.forEach(procedure); + } + + @Override + public TShortIterator iterator() { + return new TShortIterator() { + TShortIterator i = c.iterator(); + + @Override + public boolean hasNext() { + return i.hasNext(); + } + + @Override + public short next() { + return i.next(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public boolean add(short e) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(short o) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean containsAll(Collection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(TShortCollection coll) { + return c.containsAll(coll); + } + + @Override + public boolean containsAll(short[] array) { + return c.containsAll(array); + } + + @Override + public boolean addAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean removeAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(TShortCollection coll) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(short[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java new file mode 100644 index 0000000..ad833a2 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortDoubleMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortDoubleMap implements TShortDoubleMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortDoubleMap m; + + public TUnmodifiableShortDoubleMap(TShortDoubleMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(double val) { + return m.containsValue(val); + } + + @Override + public double get(short key) { + return m.get(key); + } + + @Override + public double put(short key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public double remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortDoubleMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TDoubleCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TDoubleCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public double[] values() { + return m.values(); + } + + @Override + public double[] values(double[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public double getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortDoubleIterator iterator() { + return new TShortDoubleIterator() { + TShortDoubleIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public double value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public double setValue(double val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public double putIfAbsent(short key, double value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TDoubleFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, double amount) { + throw new UnsupportedOperationException(); + } + + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java new file mode 100644 index 0000000..fc2dca6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortFloatMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortFloatMap implements TShortFloatMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortFloatMap m; + + public TUnmodifiableShortFloatMap(TShortFloatMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(float val) { + return m.containsValue(val); + } + + @Override + public float get(short key) { + return m.get(key); + } + + @Override + public float put(short key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public float remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortFloatMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TFloatCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TFloatCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public float[] values() { + return m.values(); + } + + @Override + public float[] values(float[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public float getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TFloatProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortFloatIterator iterator() { + return new TShortFloatIterator() { + TShortFloatIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public float value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public float setValue(float val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public float putIfAbsent(short key, float value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TFloatFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, float amount) { + throw new UnsupportedOperationException(); + } + + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java new file mode 100644 index 0000000..a8d47d9 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortIntMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortIntMap implements TShortIntMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortIntMap m; + + public TUnmodifiableShortIntMap(TShortIntMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(int val) { + return m.containsValue(val); + } + + @Override + public int get(short key) { + return m.get(key); + } + + @Override + public int put(short key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public int remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortIntMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TIntCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TIntCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public int[] values() { + return m.values(); + } + + @Override + public int[] values(int[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public int getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TIntProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortIntIterator iterator() { + return new TShortIntIterator() { + TShortIntIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public int value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public int setValue(int val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public int putIfAbsent(short key, int value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TIntFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, int amount) { + throw new UnsupportedOperationException(); + } + + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java new file mode 100644 index 0000000..f28a3ff --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortList.java @@ -0,0 +1,277 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.procedure.*; +import gnu.trove.list.*; +import gnu.trove.function.*; +import java.util.RandomAccess; +import java.util.Random; + +public class TUnmodifiableShortList extends TUnmodifiableShortCollection implements TShortList { + static final long serialVersionUID = -283967356065247728L; + + final TShortList list; + + public TUnmodifiableShortList(TShortList list) { + super(list); + this.list = list; + } + + @Override + public boolean equals(Object o) { + return o == this || list.equals(o); + } + + @Override + public int hashCode() { + return list.hashCode(); + } + + @Override + public short get(int index) { + return list.get(index); + } + + @Override + public int indexOf(short o) { + return list.indexOf(o); + } + + @Override + public int lastIndexOf(short o) { + return list.lastIndexOf(o); + } + + @Override + public short[] toArray(int offset, int len) { + return list.toArray(offset, len); + } + + @Override + public short[] toArray(short[] dest, int offset, int len) { + return list.toArray(dest, offset, len); + } + + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + return list.toArray(dest, source_pos, dest_pos, len); + } + + @Override + public boolean forEachDescending(TShortProcedure procedure) { + return list.forEachDescending(procedure); + } + + @Override + public int binarySearch(short value) { + return list.binarySearch(value); + } + + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + return list.binarySearch(value, fromIndex, toIndex); + } + + @Override + public int indexOf(int offset, short value) { + return list.indexOf(offset, value); + } + + @Override + public int lastIndexOf(int offset, short value) { + return list.lastIndexOf(offset, value); + } + + @Override + public TShortList grep(TShortProcedure condition) { + return list.grep(condition); + } + + @Override + public TShortList inverseGrep(TShortProcedure condition) { + return list.inverseGrep(condition); + } + + @Override + public short max() { + return list.max(); + } + + @Override + public short min() { + return list.min(); + } + + @Override + public short sum() { + return list.sum(); + } + + @Override + public TShortList subList(int fromIndex, int toIndex) { + return new TUnmodifiableShortList(list.subList(fromIndex, toIndex)); + } + + // TODO: Do we want to fullt implement ListIterator? + // public TIntListIterator listIterator() {return listIterator(0);} + // + // public ListIterator listIterator(final int index) { + // return new ListIterator() { + // ListIterator i = list.listIterator(index); + // + // public boolean hasNext() {return i.hasNext();} + // public E next() {return i.next();} + // public boolean hasPrevious() {return i.hasPrevious();} + // public E previous() {return i.previous();} + // public int nextIndex() {return i.nextIndex();} + // public int previousIndex() {return i.previousIndex();} + // + // public void remove() { + // throw new UnsupportedOperationException(); + // } + // public void set(E e) { + // throw new UnsupportedOperationException(); + // } + // public void add(E e) { + // throw new UnsupportedOperationException(); + // } + // }; + // } + + /** + * UnmodifiableRandomAccessList instances are serialized as UnmodifiableList + * instances to allow them to be deserialized in pre-1.4 JREs (which do not have + * UnmodifiableRandomAccessList). This method inverts the transformation. As a + * beneficial side-effect, it also grafts the RandomAccess marker onto + * UnmodifiableList instances that were serialized in pre-1.4 JREs. + * + * Note: Unfortunately, UnmodifiableRandomAccessList instances serialized in + * 1.4.1 and deserialized in 1.4 will become UnmodifiableList instances, as this + * method was missing in 1.4. + */ + private Object readResolve() { + return (list instanceof RandomAccess ? new TUnmodifiableRandomAccessShortList(list) : this); + } + + @Override + public void add(short[] vals) { + throw new UnsupportedOperationException(); + } + + @Override + public void add(short[] vals, int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public short removeAt(int offset) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(int offset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + throw new UnsupportedOperationException(); + } + + @Override + public short set(int offset, short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, short[] values) { + throw new UnsupportedOperationException(); + } + + @Override + public void set(int offset, short[] values, int valOffset, int length) { + throw new UnsupportedOperationException(); + } + + @Override + public short replace(int offset, short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse() { + throw new UnsupportedOperationException(); + } + + @Override + public void reverse(int from, int to) { + throw new UnsupportedOperationException(); + } + + @Override + public void shuffle(Random rand) { + throw new UnsupportedOperationException(); + } + + @Override + public void sort() { + throw new UnsupportedOperationException(); + } + + @Override + public void sort(int fromIndex, int toIndex) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void fill(int fromIndex, int toIndex, short val) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java new file mode 100644 index 0000000..268a550 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortLongMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortLongMap implements TShortLongMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortLongMap m; + + public TUnmodifiableShortLongMap(TShortLongMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(long val) { + return m.containsValue(val); + } + + @Override + public long get(short key) { + return m.get(key); + } + + @Override + public long put(short key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public long remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortLongMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TLongCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TLongCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public long[] values() { + return m.values(); + } + + @Override + public long[] values(long[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public long getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TLongProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortLongIterator iterator() { + return new TShortLongIterator() { + TShortLongIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public long value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public long setValue(long val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public long putIfAbsent(short key, long value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TLongFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, long amount) { + throw new UnsupportedOperationException(); + } + + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java new file mode 100644 index 0000000..f9ae332 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortObjectMap.java @@ -0,0 +1,225 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.*; +import java.io.Serializable; + +public class TUnmodifiableShortObjectMap implements TShortObjectMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortObjectMap m; + + public TUnmodifiableShortObjectMap(TShortObjectMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(Object val) { + return m.containsValue(val); + } + + @Override + public V get(short key) { + return m.get(key); + } + + @Override + public V put(short key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public V remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortObjectMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient Collection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public Collection valueCollection() { + if (values == null) + values = Collections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public Object[] values() { + return m.values(); + } + + @Override + public V[] values(V[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortObjectProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortObjectIterator iterator() { + return new TShortObjectIterator() { + TShortObjectIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public V value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public V setValue(V val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public V putIfAbsent(short key, V value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TObjectFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortObjectProcedure procedure) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java new file mode 100644 index 0000000..553363e --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortSet.java @@ -0,0 +1,51 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.set.*; +import java.io.Serializable; + +public class TUnmodifiableShortSet extends TUnmodifiableShortCollection implements TShortSet, Serializable { + + private static final long serialVersionUID = -9215047833775013803L; + + public TUnmodifiableShortSet(TShortSet s) { + super(s); + } + + @Override + public boolean equals(Object o) { + return o == this || c.equals(o); + } + + @Override + public int hashCode() { + return c.hashCode(); + } +} diff --git a/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java new file mode 100644 index 0000000..cff10c6 --- /dev/null +++ b/src/gnu/trove/impl/unmodifiable/TUnmodifiableShortShortMap.java @@ -0,0 +1,245 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2008, Robert D. Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.impl.unmodifiable; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// THIS IS AN IMPLEMENTATION CLASS. DO NOT USE DIRECTLY! // +// Access to these methods should be through TCollections // +//////////////////////////////////////////////////////////// + +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.function.*; +import gnu.trove.map.*; +import gnu.trove.*; + +import java.util.Map; +import java.io.Serializable; + +public class TUnmodifiableShortShortMap implements TShortShortMap, Serializable { + private static final long serialVersionUID = -1034234728574286014L; + + private final TShortShortMap m; + + public TUnmodifiableShortShortMap(TShortShortMap m) { + if (m == null) + throw new NullPointerException(); + this.m = m; + } + + @Override + public int size() { + return m.size(); + } + + @Override + public boolean isEmpty() { + return m.isEmpty(); + } + + @Override + public boolean containsKey(short key) { + return m.containsKey(key); + } + + @Override + public boolean containsValue(short val) { + return m.containsValue(val); + } + + @Override + public short get(short key) { + return m.get(key); + } + + @Override + public short put(short key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public short remove(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(TShortShortMap m) { + throw new UnsupportedOperationException(); + } + + @Override + public void putAll(Map map) { + throw new UnsupportedOperationException(); + } + + @Override + public void clear() { + throw new UnsupportedOperationException(); + } + + private transient TShortSet keySet = null; + private transient TShortCollection values = null; + + @Override + public TShortSet keySet() { + if (keySet == null) + keySet = TCollections.unmodifiableSet(m.keySet()); + return keySet; + } + + @Override + public short[] keys() { + return m.keys(); + } + + @Override + public short[] keys(short[] array) { + return m.keys(array); + } + + @Override + public TShortCollection valueCollection() { + if (values == null) + values = TCollections.unmodifiableCollection(m.valueCollection()); + return values; + } + + @Override + public short[] values() { + return m.values(); + } + + @Override + public short[] values(short[] array) { + return m.values(array); + } + + @Override + public boolean equals(Object o) { + return o == this || m.equals(o); + } + + @Override + public int hashCode() { + return m.hashCode(); + } + + @Override + public String toString() { + return m.toString(); + } + + @Override + public short getNoEntryKey() { + return m.getNoEntryKey(); + } + + @Override + public short getNoEntryValue() { + return m.getNoEntryValue(); + } + + @Override + public boolean forEachKey(TShortProcedure procedure) { + return m.forEachKey(procedure); + } + + @Override + public boolean forEachValue(TShortProcedure procedure) { + return m.forEachValue(procedure); + } + + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + return m.forEachEntry(procedure); + } + + @Override + public TShortShortIterator iterator() { + return new TShortShortIterator() { + TShortShortIterator iter = m.iterator(); + + @Override + public short key() { + return iter.key(); + } + + @Override + public short value() { + return iter.value(); + } + + @Override + public void advance() { + iter.advance(); + } + + @Override + public boolean hasNext() { + return iter.hasNext(); + } + + @Override + public short setValue(short val) { + throw new UnsupportedOperationException(); + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + @Override + public short putIfAbsent(short key, short value) { + throw new UnsupportedOperationException(); + } + + @Override + public void transformValues(TShortFunction function) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean increment(short key) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean adjustValue(short key, short amount) { + throw new UnsupportedOperationException(); + } + + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + throw new UnsupportedOperationException(); + } +} diff --git a/src/gnu/trove/iterator/TAdvancingIterator.java b/src/gnu/trove/iterator/TAdvancingIterator.java new file mode 100644 index 0000000..1b4c195 --- /dev/null +++ b/src/gnu/trove/iterator/TAdvancingIterator.java @@ -0,0 +1,32 @@ +// //////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +// //////////////////////////////////////////////////////////////////////////// +package gnu.trove.iterator; + +/** + * Common interface for iterators that operate via the "advance" method for + * moving the cursor to the next element. + */ +public interface TAdvancingIterator extends TIterator { + /** + * Moves the iterator forward to the next entry. + * + * @throws java.util.NoSuchElementException + * if the iterator is already exhausted + */ + public void advance(); +} diff --git a/src/gnu/trove/iterator/TByteByteIterator.java b/src/gnu/trove/iterator/TByteByteIterator.java new file mode 100644 index 0000000..60320a9 --- /dev/null +++ b/src/gnu/trove/iterator/TByteByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TByteCharIterator.java b/src/gnu/trove/iterator/TByteCharIterator.java new file mode 100644 index 0000000..dcf3ea2 --- /dev/null +++ b/src/gnu/trove/iterator/TByteCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TByteDoubleIterator.java b/src/gnu/trove/iterator/TByteDoubleIterator.java new file mode 100644 index 0000000..8b91050 --- /dev/null +++ b/src/gnu/trove/iterator/TByteDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TByteFloatIterator.java b/src/gnu/trove/iterator/TByteFloatIterator.java new file mode 100644 index 0000000..e9d048a --- /dev/null +++ b/src/gnu/trove/iterator/TByteFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TByteIntIterator.java b/src/gnu/trove/iterator/TByteIntIterator.java new file mode 100644 index 0000000..037c21c --- /dev/null +++ b/src/gnu/trove/iterator/TByteIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TByteIterator.java b/src/gnu/trove/iterator/TByteIterator.java new file mode 100644 index 0000000..62bf5be --- /dev/null +++ b/src/gnu/trove/iterator/TByteIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for byte collections. + */ +public interface TByteIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next byte in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public byte next(); +} diff --git a/src/gnu/trove/iterator/TByteLongIterator.java b/src/gnu/trove/iterator/TByteLongIterator.java new file mode 100644 index 0000000..43a803f --- /dev/null +++ b/src/gnu/trove/iterator/TByteLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TByteObjectIterator.java b/src/gnu/trove/iterator/TByteObjectIterator.java new file mode 100644 index 0000000..e3f585e --- /dev/null +++ b/src/gnu/trove/iterator/TByteObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TByteObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TByteObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TByteObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TByteShortIterator.java b/src/gnu/trove/iterator/TByteShortIterator.java new file mode 100644 index 0000000..6e290b0 --- /dev/null +++ b/src/gnu/trove/iterator/TByteShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type byte and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TByteShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TByteShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TByteShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public byte key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TCharByteIterator.java b/src/gnu/trove/iterator/TCharByteIterator.java new file mode 100644 index 0000000..25178e9 --- /dev/null +++ b/src/gnu/trove/iterator/TCharByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TCharCharIterator.java b/src/gnu/trove/iterator/TCharCharIterator.java new file mode 100644 index 0000000..3f46990 --- /dev/null +++ b/src/gnu/trove/iterator/TCharCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TCharDoubleIterator.java b/src/gnu/trove/iterator/TCharDoubleIterator.java new file mode 100644 index 0000000..2a34dfd --- /dev/null +++ b/src/gnu/trove/iterator/TCharDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TCharFloatIterator.java b/src/gnu/trove/iterator/TCharFloatIterator.java new file mode 100644 index 0000000..6cee311 --- /dev/null +++ b/src/gnu/trove/iterator/TCharFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TCharIntIterator.java b/src/gnu/trove/iterator/TCharIntIterator.java new file mode 100644 index 0000000..82fdb12 --- /dev/null +++ b/src/gnu/trove/iterator/TCharIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TCharIterator.java b/src/gnu/trove/iterator/TCharIterator.java new file mode 100644 index 0000000..dfdf38f --- /dev/null +++ b/src/gnu/trove/iterator/TCharIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for char collections. + */ +public interface TCharIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next char in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public char next(); +} diff --git a/src/gnu/trove/iterator/TCharLongIterator.java b/src/gnu/trove/iterator/TCharLongIterator.java new file mode 100644 index 0000000..c8f9a78 --- /dev/null +++ b/src/gnu/trove/iterator/TCharLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TCharObjectIterator.java b/src/gnu/trove/iterator/TCharObjectIterator.java new file mode 100644 index 0000000..3e2d9e5 --- /dev/null +++ b/src/gnu/trove/iterator/TCharObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TCharObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TCharObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TCharObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TCharShortIterator.java b/src/gnu/trove/iterator/TCharShortIterator.java new file mode 100644 index 0000000..3f46bad --- /dev/null +++ b/src/gnu/trove/iterator/TCharShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type char and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TCharShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TCharShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TCharShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public char key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TDoubleByteIterator.java b/src/gnu/trove/iterator/TDoubleByteIterator.java new file mode 100644 index 0000000..fff6444 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TDoubleCharIterator.java b/src/gnu/trove/iterator/TDoubleCharIterator.java new file mode 100644 index 0000000..2e0e2ca --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TDoubleDoubleIterator.java b/src/gnu/trove/iterator/TDoubleDoubleIterator.java new file mode 100644 index 0000000..515522f --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TDoubleFloatIterator.java b/src/gnu/trove/iterator/TDoubleFloatIterator.java new file mode 100644 index 0000000..0324399 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TDoubleIntIterator.java b/src/gnu/trove/iterator/TDoubleIntIterator.java new file mode 100644 index 0000000..64a12b4 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TDoubleIterator.java b/src/gnu/trove/iterator/TDoubleIterator.java new file mode 100644 index 0000000..792e359 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for double collections. + */ +public interface TDoubleIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next double in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public double next(); +} diff --git a/src/gnu/trove/iterator/TDoubleLongIterator.java b/src/gnu/trove/iterator/TDoubleLongIterator.java new file mode 100644 index 0000000..1d2385e --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TDoubleObjectIterator.java b/src/gnu/trove/iterator/TDoubleObjectIterator.java new file mode 100644 index 0000000..bce9020 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TDoubleObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TDoubleObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TDoubleObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TDoubleShortIterator.java b/src/gnu/trove/iterator/TDoubleShortIterator.java new file mode 100644 index 0000000..6010074 --- /dev/null +++ b/src/gnu/trove/iterator/TDoubleShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type double and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TDoubleShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TDoubleShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TDoubleShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public double key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TFloatByteIterator.java b/src/gnu/trove/iterator/TFloatByteIterator.java new file mode 100644 index 0000000..17c5051 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TFloatCharIterator.java b/src/gnu/trove/iterator/TFloatCharIterator.java new file mode 100644 index 0000000..17d8cc8 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TFloatDoubleIterator.java b/src/gnu/trove/iterator/TFloatDoubleIterator.java new file mode 100644 index 0000000..dbeedf2 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TFloatFloatIterator.java b/src/gnu/trove/iterator/TFloatFloatIterator.java new file mode 100644 index 0000000..985679c --- /dev/null +++ b/src/gnu/trove/iterator/TFloatFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TFloatIntIterator.java b/src/gnu/trove/iterator/TFloatIntIterator.java new file mode 100644 index 0000000..7cba419 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TFloatIterator.java b/src/gnu/trove/iterator/TFloatIterator.java new file mode 100644 index 0000000..39bbd18 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for float collections. + */ +public interface TFloatIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next float in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public float next(); +} diff --git a/src/gnu/trove/iterator/TFloatLongIterator.java b/src/gnu/trove/iterator/TFloatLongIterator.java new file mode 100644 index 0000000..df16828 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TFloatObjectIterator.java b/src/gnu/trove/iterator/TFloatObjectIterator.java new file mode 100644 index 0000000..d2b2344 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TFloatObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TFloatObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TFloatObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TFloatShortIterator.java b/src/gnu/trove/iterator/TFloatShortIterator.java new file mode 100644 index 0000000..3a1eb98 --- /dev/null +++ b/src/gnu/trove/iterator/TFloatShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type float and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TFloatShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TFloatShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TFloatShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public float key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TIntByteIterator.java b/src/gnu/trove/iterator/TIntByteIterator.java new file mode 100644 index 0000000..caf7ab1 --- /dev/null +++ b/src/gnu/trove/iterator/TIntByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TIntCharIterator.java b/src/gnu/trove/iterator/TIntCharIterator.java new file mode 100644 index 0000000..27f760f --- /dev/null +++ b/src/gnu/trove/iterator/TIntCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TIntDoubleIterator.java b/src/gnu/trove/iterator/TIntDoubleIterator.java new file mode 100644 index 0000000..57b8792 --- /dev/null +++ b/src/gnu/trove/iterator/TIntDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TIntFloatIterator.java b/src/gnu/trove/iterator/TIntFloatIterator.java new file mode 100644 index 0000000..a262687 --- /dev/null +++ b/src/gnu/trove/iterator/TIntFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TIntIntIterator.java b/src/gnu/trove/iterator/TIntIntIterator.java new file mode 100644 index 0000000..a2e2129 --- /dev/null +++ b/src/gnu/trove/iterator/TIntIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TIntIterator.java b/src/gnu/trove/iterator/TIntIterator.java new file mode 100644 index 0000000..30b2c3d --- /dev/null +++ b/src/gnu/trove/iterator/TIntIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for int collections. + */ +public interface TIntIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next int in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public int next(); +} diff --git a/src/gnu/trove/iterator/TIntLongIterator.java b/src/gnu/trove/iterator/TIntLongIterator.java new file mode 100644 index 0000000..f0e7abb --- /dev/null +++ b/src/gnu/trove/iterator/TIntLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TIntObjectIterator.java b/src/gnu/trove/iterator/TIntObjectIterator.java new file mode 100644 index 0000000..8de94ff --- /dev/null +++ b/src/gnu/trove/iterator/TIntObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TIntObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TIntObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TIntObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TIntShortIterator.java b/src/gnu/trove/iterator/TIntShortIterator.java new file mode 100644 index 0000000..63b83fa --- /dev/null +++ b/src/gnu/trove/iterator/TIntShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type int and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TIntShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TIntShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TIntShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public int key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TIterator.java b/src/gnu/trove/iterator/TIterator.java new file mode 100644 index 0000000..a5459e2 --- /dev/null +++ b/src/gnu/trove/iterator/TIterator.java @@ -0,0 +1,37 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// +package gnu.trove.iterator; + +/** + * Common interface for all iterators used in Trove. + */ +public interface TIterator { + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + public boolean hasNext(); + + /** + * Removes the last entry returned by the iterator. The result of invoking this + * method more than once for a single entry is undefined and can leave the + * underlying data structure in a confused state. + */ + public void remove(); +} diff --git a/src/gnu/trove/iterator/TLongByteIterator.java b/src/gnu/trove/iterator/TLongByteIterator.java new file mode 100644 index 0000000..3b6a360 --- /dev/null +++ b/src/gnu/trove/iterator/TLongByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TLongCharIterator.java b/src/gnu/trove/iterator/TLongCharIterator.java new file mode 100644 index 0000000..2a4180a --- /dev/null +++ b/src/gnu/trove/iterator/TLongCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TLongDoubleIterator.java b/src/gnu/trove/iterator/TLongDoubleIterator.java new file mode 100644 index 0000000..c314a93 --- /dev/null +++ b/src/gnu/trove/iterator/TLongDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TLongFloatIterator.java b/src/gnu/trove/iterator/TLongFloatIterator.java new file mode 100644 index 0000000..87fd8a3 --- /dev/null +++ b/src/gnu/trove/iterator/TLongFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TLongIntIterator.java b/src/gnu/trove/iterator/TLongIntIterator.java new file mode 100644 index 0000000..75877c7 --- /dev/null +++ b/src/gnu/trove/iterator/TLongIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TLongIterator.java b/src/gnu/trove/iterator/TLongIterator.java new file mode 100644 index 0000000..60e7cb9 --- /dev/null +++ b/src/gnu/trove/iterator/TLongIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for long collections. + */ +public interface TLongIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next long in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public long next(); +} diff --git a/src/gnu/trove/iterator/TLongLongIterator.java b/src/gnu/trove/iterator/TLongLongIterator.java new file mode 100644 index 0000000..badf4d6 --- /dev/null +++ b/src/gnu/trove/iterator/TLongLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TLongObjectIterator.java b/src/gnu/trove/iterator/TLongObjectIterator.java new file mode 100644 index 0000000..08566bb --- /dev/null +++ b/src/gnu/trove/iterator/TLongObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TLongObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TLongObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TLongObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TLongShortIterator.java b/src/gnu/trove/iterator/TLongShortIterator.java new file mode 100644 index 0000000..71ebc5a --- /dev/null +++ b/src/gnu/trove/iterator/TLongShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type long and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TLongShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TLongShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TLongShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public long key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TObjectByteIterator.java b/src/gnu/trove/iterator/TObjectByteIterator.java new file mode 100644 index 0000000..6fa4fc5 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectByteIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and byte. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectByteIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectByteIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TObjectCharIterator.java b/src/gnu/trove/iterator/TObjectCharIterator.java new file mode 100644 index 0000000..9728116 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectCharIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and char. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectCharIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectCharIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TObjectDoubleIterator.java b/src/gnu/trove/iterator/TObjectDoubleIterator.java new file mode 100644 index 0000000..1833cb3 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectDoubleIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and double. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectDoubleIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectDoubleIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TObjectFloatIterator.java b/src/gnu/trove/iterator/TObjectFloatIterator.java new file mode 100644 index 0000000..fb735e4 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectFloatIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and float. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectFloatIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectFloatIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TObjectIntIterator.java b/src/gnu/trove/iterator/TObjectIntIterator.java new file mode 100644 index 0000000..98a45be --- /dev/null +++ b/src/gnu/trove/iterator/TObjectIntIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and int. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectIntIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectIntIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TObjectLongIterator.java b/src/gnu/trove/iterator/TObjectLongIterator.java new file mode 100644 index 0000000..c882a2e --- /dev/null +++ b/src/gnu/trove/iterator/TObjectLongIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and long. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectLongIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectLongIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TObjectShortIterator.java b/src/gnu/trove/iterator/TObjectShortIterator.java new file mode 100644 index 0000000..11b5066 --- /dev/null +++ b/src/gnu/trove/iterator/TObjectShortIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type Object and short. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TObjectShortIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TObjectShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: Object_E_Iterator.template,v 1.1.2.1 2009/09/14 19:02:20 + * upholderoftruth Exp $ + */ +public interface TObjectShortIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public K key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/TPrimitiveIterator.java b/src/gnu/trove/iterator/TPrimitiveIterator.java new file mode 100644 index 0000000..1511bcd --- /dev/null +++ b/src/gnu/trove/iterator/TPrimitiveIterator.java @@ -0,0 +1,63 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +/** + * Implements all iterator functions for the hashed object set. Subclasses may + * override objectAtIndex to vary the object returned by calls to next() (e.g. + * for values, and Map.Entry objects). + *

+ *

+ * Note that iteration is fastest if you forego the calls to hasNext in + * favor of checking the size of the structure yourself and then call next() + * that many times: + *

+ * + *

+ * Iterator i = collection.iterator();
+ * for (int size = collection.size(); size-- > 0;) {
+ * 	Object o = i.next();
+ * }
+ * 
+ *

+ *

+ * You may, of course, use the hasNext(), next() idiom too if you aren't in a + * performance critical spot. + *

+ */ +public interface TPrimitiveIterator extends TIterator { + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext(); + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove(); + +} // TPrimitiveIterator diff --git a/src/gnu/trove/iterator/TShortByteIterator.java b/src/gnu/trove/iterator/TShortByteIterator.java new file mode 100644 index 0000000..31a1314 --- /dev/null +++ b/src/gnu/trove/iterator/TShortByteIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and byte. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortByteIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortByteIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortByteIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public byte value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public byte setValue(byte val); +} diff --git a/src/gnu/trove/iterator/TShortCharIterator.java b/src/gnu/trove/iterator/TShortCharIterator.java new file mode 100644 index 0000000..a2a72e4 --- /dev/null +++ b/src/gnu/trove/iterator/TShortCharIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and char. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortCharIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortCharIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortCharIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public char value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public char setValue(char val); +} diff --git a/src/gnu/trove/iterator/TShortDoubleIterator.java b/src/gnu/trove/iterator/TShortDoubleIterator.java new file mode 100644 index 0000000..0702365 --- /dev/null +++ b/src/gnu/trove/iterator/TShortDoubleIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and double. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortDoubleIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortDoubleIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortDoubleIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public double value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public double setValue(double val); +} diff --git a/src/gnu/trove/iterator/TShortFloatIterator.java b/src/gnu/trove/iterator/TShortFloatIterator.java new file mode 100644 index 0000000..cd7fc60 --- /dev/null +++ b/src/gnu/trove/iterator/TShortFloatIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and float. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortFloatIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortFloatIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortFloatIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public float value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public float setValue(float val); +} diff --git a/src/gnu/trove/iterator/TShortIntIterator.java b/src/gnu/trove/iterator/TShortIntIterator.java new file mode 100644 index 0000000..5ff0dba --- /dev/null +++ b/src/gnu/trove/iterator/TShortIntIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and int. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortIntIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortIntIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortIntIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public int value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public int setValue(int val); +} diff --git a/src/gnu/trove/iterator/TShortIterator.java b/src/gnu/trove/iterator/TShortIterator.java new file mode 100644 index 0000000..f998d8b --- /dev/null +++ b/src/gnu/trove/iterator/TShortIterator.java @@ -0,0 +1,39 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for short collections. + */ +public interface TShortIterator extends TIterator { + /** + * Advances the iterator to the next element in the underlying collection and + * returns it. + * + * @return the next short in the collection + * @exception NoSuchElementException + * if the iterator is already exhausted + */ + public short next(); +} diff --git a/src/gnu/trove/iterator/TShortLongIterator.java b/src/gnu/trove/iterator/TShortLongIterator.java new file mode 100644 index 0000000..e43e2dc --- /dev/null +++ b/src/gnu/trove/iterator/TShortLongIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and long. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortLongIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortLongIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortLongIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public long value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public long setValue(long val); +} diff --git a/src/gnu/trove/iterator/TShortObjectIterator.java b/src/gnu/trove/iterator/TShortObjectIterator.java new file mode 100644 index 0000000..4e3f8a3 --- /dev/null +++ b/src/gnu/trove/iterator/TShortObjectIterator.java @@ -0,0 +1,129 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and Object. + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *

+ * // accessing keys/values through an iterator:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		doSomethingWithValue(it.value());
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // modifying values in-place through iteration:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.setValue(newValueForKey(it.key()));
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // deleting entries during iteration:
+ * for (TShortObjectIterator it = map.iterator(); it.hasNext();) {
+ * 	it.advance();
+ * 	if (satisfiesCondition(it.key())) {
+ * 		it.remove();
+ * 	}
+ * }
+ * 
+ *

+ * + *

+ * // faster iteration by avoiding hasNext():
+ * TShortObjectIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _E_ObjectIterator.template,v 1.1.2.1 2009/09/15 02:38:31 + * upholderoftruth Exp $ + */ +public interface TShortObjectIterator extends TAdvancingIterator { + + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public V value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public V setValue(V val); +} diff --git a/src/gnu/trove/iterator/TShortShortIterator.java b/src/gnu/trove/iterator/TShortShortIterator.java new file mode 100644 index 0000000..3984f2c --- /dev/null +++ b/src/gnu/trove/iterator/TShortShortIterator.java @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Iterator for maps of type short and short. + * + *

+ * The iterator semantics for Trove's primitive maps is slightly different from + * those defined in java.util.Iterator, but still well within the scope + * of the pattern, as defined by Gamma, et al. + *

+ * + *

+ * This iterator does not implicitly advance to the next entry when the + * value at the current position is retrieved. Rather, you must explicitly ask + * the iterator to advance() and then retrieve either the + * key(), the value() or both. This is done so that you have + * the option, but not the obligation, to retrieve keys and/or values as your + * application requires, and without introducing wrapper objects that would + * carry both. As the iteration is stateful, access to the key/value parts of + * the current map entry happens in constant time. + *

+ * + *

+ * In practice, the iterator is akin to a "search finger" that you move from + * position to position. Read or write operations affect the current entry only + * and do not assume responsibility for moving the finger. + *

+ * + *

+ * Here are some sample scenarios for this class of iterator: + *

+ * + *
+ * // accessing keys/values through an iterator:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     doSomethingWithValue( it.value() );
+ *   }
+ * }
+ * 
+ * + *
+ * // modifying values in-place through iteration:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.setValue( newValueForKey( it.key() ) );
+ *   }
+ * }
+ * 
+ * + *
+ * // deleting entries during iteration:
+ * for ( TShortShortIterator it = map.iterator(); it.hasNext(); ) {
+ *   it.advance();
+ *   if ( satisfiesCondition( it.key() ) {
+ *     it.remove();
+ *   }
+ * }
+ * 
+ * + *
+ * // faster iteration by avoiding hasNext():
+ * TShortShortIterator iterator = map.iterator();
+ * for (int i = map.size(); i-- > 0;) {
+ * 	iterator.advance();
+ * 	doSomethingWithKeyAndValue(iterator.key(), iterator.value());
+ * }
+ * 
+ */ +public interface TShortShortIterator extends TAdvancingIterator { + /** + * Provides access to the key of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the key of the entry at the iterator's current position. + */ + public short key(); + + /** + * Provides access to the value of the mapping at the iterator's position. Note + * that you must advance() the iterator at least once before invoking + * this method. + * + * @return the value of the entry at the iterator's current position. + */ + public short value(); + + /** + * Replace the value of the mapping at the iterator's position with the + * specified value. Note that you must advance() the iterator at least + * once before invoking this method. + * + * @param val + * the value to set in the current entry + * @return the old value of the entry. + */ + public short setValue(short val); +} diff --git a/src/gnu/trove/iterator/hash/TObjectHashIterator.java b/src/gnu/trove/iterator/hash/TObjectHashIterator.java new file mode 100644 index 0000000..8a8ef1b --- /dev/null +++ b/src/gnu/trove/iterator/hash/TObjectHashIterator.java @@ -0,0 +1,55 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.iterator.hash; + +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.impl.hash.THashIterator; + +/** + * Iterator for hashtables that use open addressing to resolve collisions. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TObjectHashIterator.java,v 1.1.2.4 2009/10/09 01:44:34 robeden + * Exp $ + */ + +public class TObjectHashIterator extends THashIterator { + + protected final TObjectHash _objectHash; + + public TObjectHashIterator(TObjectHash hash) { + super(hash); + _objectHash = hash; + } + + @Override + @SuppressWarnings("unchecked") + protected E objectAtIndex(int index) { + Object obj = _objectHash._set[index]; + if (obj == TObjectHash.FREE || obj == TObjectHash.REMOVED) { + return null; + } + return (E) obj; + } + +} // TObjectHashIterator diff --git a/src/gnu/trove/list/TByteList.java b/src/gnu/trove/list/TByteList.java new file mode 100644 index 0000000..a33758e --- /dev/null +++ b/src/gnu/trove/list/TByteList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TByteCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TByteList extends TByteCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public byte getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an byte value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(byte val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an byte[] value + */ + public void add(byte[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an byte[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(byte[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an byte value + */ + public void insert(int offset, byte value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an byte[] value + */ + public void insert(int offset, byte[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an byte[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, byte[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an byte value + */ + public byte get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an byte value + * + * @return The value previously at the given index. + */ + public byte set(int offset, byte val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, byte[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, byte[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an byte value + * @return the value previously stored at offset. + */ + public byte replace(int offset, byte val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an byte value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(byte value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an byte that is the value removed. + */ + public byte removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TByteList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an byte[] value + */ + @Override + public byte[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an byte[] value + */ + public byte[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public byte[] toArray(byte[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public byte[] toArray(byte[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TByteProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TByteProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TByteProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TByteProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(byte val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, byte val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(byte value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(byte value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an byte value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(byte value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an byte value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, byte value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an byte value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(byte value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an byte value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, byte value); + + /** + * Searches the list for value + * + * @param value + * an byte value + * @return true if value is in the list. + */ + @Override + public boolean contains(byte value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TByteList grep(TByteProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TByteList inverseGrep(TByteProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public byte max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public byte min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public byte sum(); +} diff --git a/src/gnu/trove/list/TCharList.java b/src/gnu/trove/list/TCharList.java new file mode 100644 index 0000000..029df0c --- /dev/null +++ b/src/gnu/trove/list/TCharList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TCharCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TCharList extends TCharCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public char getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an char value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(char val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an char[] value + */ + public void add(char[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an char[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(char[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an char value + */ + public void insert(int offset, char value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an char[] value + */ + public void insert(int offset, char[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an char[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, char[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an char value + */ + public char get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an char value + * + * @return The value previously at the given index. + */ + public char set(int offset, char val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, char[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, char[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an char value + * @return the value previously stored at offset. + */ + public char replace(int offset, char val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an char value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(char value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an char that is the value removed. + */ + public char removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TCharList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an char[] value + */ + @Override + public char[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an char[] value + */ + public char[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public char[] toArray(char[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public char[] toArray(char[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TCharProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TCharProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TCharProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TCharProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(char val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, char val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(char value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(char value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an char value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(char value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an char value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, char value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an char value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(char value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an char value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, char value); + + /** + * Searches the list for value + * + * @param value + * an char value + * @return true if value is in the list. + */ + @Override + public boolean contains(char value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TCharList grep(TCharProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TCharList inverseGrep(TCharProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public char max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public char min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public char sum(); +} diff --git a/src/gnu/trove/list/TDoubleList.java b/src/gnu/trove/list/TDoubleList.java new file mode 100644 index 0000000..36abeb8 --- /dev/null +++ b/src/gnu/trove/list/TDoubleList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TDoubleCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TDoubleList extends TDoubleCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public double getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an double value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(double val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an double[] value + */ + public void add(double[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an double[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(double[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an double value + */ + public void insert(int offset, double value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an double[] value + */ + public void insert(int offset, double[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an double[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, double[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an double value + */ + public double get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an double value + * + * @return The value previously at the given index. + */ + public double set(int offset, double val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, double[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, double[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an double value + * @return the value previously stored at offset. + */ + public double replace(int offset, double val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an double value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(double value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an double that is the value removed. + */ + public double removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TDoubleList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an double[] value + */ + @Override + public double[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an double[] value + */ + public double[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public double[] toArray(double[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public double[] toArray(double[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TDoubleProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TDoubleProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TDoubleProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TDoubleProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(double val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, double val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(double value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(double value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an double value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(double value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an double value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, double value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an double value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(double value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an double value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, double value); + + /** + * Searches the list for value + * + * @param value + * an double value + * @return true if value is in the list. + */ + @Override + public boolean contains(double value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TDoubleList grep(TDoubleProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TDoubleList inverseGrep(TDoubleProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public double max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public double min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public double sum(); +} diff --git a/src/gnu/trove/list/TFloatList.java b/src/gnu/trove/list/TFloatList.java new file mode 100644 index 0000000..9dcbe91 --- /dev/null +++ b/src/gnu/trove/list/TFloatList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TFloatCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TFloatList extends TFloatCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public float getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an float value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(float val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an float[] value + */ + public void add(float[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an float[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(float[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an float value + */ + public void insert(int offset, float value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an float[] value + */ + public void insert(int offset, float[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an float[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, float[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an float value + */ + public float get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an float value + * + * @return The value previously at the given index. + */ + public float set(int offset, float val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, float[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, float[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an float value + * @return the value previously stored at offset. + */ + public float replace(int offset, float val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an float value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(float value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an float that is the value removed. + */ + public float removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TFloatList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an float[] value + */ + @Override + public float[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an float[] value + */ + public float[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public float[] toArray(float[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public float[] toArray(float[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TFloatProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TFloatProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TFloatProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TFloatProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(float val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, float val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(float value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(float value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an float value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(float value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an float value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, float value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an float value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(float value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an float value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, float value); + + /** + * Searches the list for value + * + * @param value + * an float value + * @return true if value is in the list. + */ + @Override + public boolean contains(float value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TFloatList grep(TFloatProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TFloatList inverseGrep(TFloatProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public float max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public float min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public float sum(); +} diff --git a/src/gnu/trove/list/TIntList.java b/src/gnu/trove/list/TIntList.java new file mode 100644 index 0000000..afb3e0c --- /dev/null +++ b/src/gnu/trove/list/TIntList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TIntCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TIntList extends TIntCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public int getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an int value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(int val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an int[] value + */ + public void add(int[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an int[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(int[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an int value + */ + public void insert(int offset, int value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an int[] value + */ + public void insert(int offset, int[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an int[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, int[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an int value + */ + public int get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an int value + * + * @return The value previously at the given index. + */ + public int set(int offset, int val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, int[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, int[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an int value + * @return the value previously stored at offset. + */ + public int replace(int offset, int val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an int value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(int value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an int that is the value removed. + */ + public int removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TIntList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an int[] value + */ + @Override + public int[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an int[] value + */ + public int[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public int[] toArray(int[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public int[] toArray(int[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TIntProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TIntProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TIntProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TIntProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(int val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, int val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(int value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(int value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an int value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an int value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, int value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an int value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an int value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, int value); + + /** + * Searches the list for value + * + * @param value + * an int value + * @return true if value is in the list. + */ + @Override + public boolean contains(int value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TIntList grep(TIntProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TIntList inverseGrep(TIntProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public int max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public int min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public int sum(); +} diff --git a/src/gnu/trove/list/TLinkable.java b/src/gnu/trove/list/TLinkable.java new file mode 100644 index 0000000..7e80727 --- /dev/null +++ b/src/gnu/trove/list/TLinkable.java @@ -0,0 +1,64 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +import java.io.Serializable; + +/** + * Interface for Objects which can be inserted into a TLinkedList. + * + * @author Eric D. Friedman + * @version $Id: TLinkable.java,v 1.1.2.2 2009/09/04 12:32:33 upholderoftruth + * Exp $ + * @see gnu.trove.list.linked.TLinkedList + */ + +public interface TLinkable extends Serializable { + static final long serialVersionUID = 997545054865482562L; + + /** + * Returns the linked list node after this one. + * + * @return a TLinkable value + */ + public T getNext(); + + /** + * Returns the linked list node before this one. + * + * @return a TLinkable value + */ + public T getPrevious(); + + /** + * Sets the linked list node after this one. + * + * @param linkable + * a TLinkable value + */ + public void setNext(T linkable); + + /** + * Sets the linked list node before this one. + * + * @param linkable + * a TLinkable value + */ + public void setPrevious(T linkable); +}// TLinkable diff --git a/src/gnu/trove/list/TLinkableAdapter.java b/src/gnu/trove/list/TLinkableAdapter.java new file mode 100644 index 0000000..9fd3f12 --- /dev/null +++ b/src/gnu/trove/list/TLinkableAdapter.java @@ -0,0 +1,44 @@ +package gnu.trove.list; + +/** + * Simple adapter class implementing {@link TLinkable}, so you don't have to. + * Example: + * + *

+ * private class MyObject extends TLinkableAdapter {
+ * 	private final String value;
+ * 
+ * 	MyObject(String value) {
+ * 		this.value = value;
+ * 	}
+ * 
+ * 	public String getValue() {
+ * 		return value;
+ * 	}
+ * }
+ * 
+ */ +public abstract class TLinkableAdapter implements TLinkable { + private volatile T next; + private volatile T prev; + + @Override + public T getNext() { + return next; + } + + @Override + public void setNext(T next) { + this.next = next; + } + + @Override + public T getPrevious() { + return prev; + } + + @Override + public void setPrevious(T prev) { + this.prev = prev; + } +} diff --git a/src/gnu/trove/list/TLongList.java b/src/gnu/trove/list/TLongList.java new file mode 100644 index 0000000..9333445 --- /dev/null +++ b/src/gnu/trove/list/TLongList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TLongCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TLongList extends TLongCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public long getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an long value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(long val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an long[] value + */ + public void add(long[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an long[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(long[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an long value + */ + public void insert(int offset, long value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an long[] value + */ + public void insert(int offset, long[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an long[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, long[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an long value + */ + public long get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an long value + * + * @return The value previously at the given index. + */ + public long set(int offset, long val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, long[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, long[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an long value + * @return the value previously stored at offset. + */ + public long replace(int offset, long val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an long value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(long value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an long that is the value removed. + */ + public long removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TLongList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an long[] value + */ + @Override + public long[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an long[] value + */ + public long[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public long[] toArray(long[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public long[] toArray(long[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TLongProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TLongProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TLongProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TLongProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(long val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, long val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(long value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(long value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an long value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(long value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an long value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, long value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an long value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(long value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an long value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, long value); + + /** + * Searches the list for value + * + * @param value + * an long value + * @return true if value is in the list. + */ + @Override + public boolean contains(long value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TLongList grep(TLongProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TLongList inverseGrep(TLongProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public long max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public long min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public long sum(); +} diff --git a/src/gnu/trove/list/TShortList.java b/src/gnu/trove/list/TShortList.java new file mode 100644 index 0000000..46d87bb --- /dev/null +++ b/src/gnu/trove/list/TShortList.java @@ -0,0 +1,530 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.procedure.*; +import gnu.trove.TShortCollection; + +import java.util.Random; + +/** + * Interface for Trove list implementations. + */ +public interface TShortList extends TShortCollection { + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public short getNoEntryValue(); + + /** + * Returns the number of values in the list. + * + * @return the number of values in the list. + */ + @Override + public int size(); + + /** + * Tests whether this list contains any values. + * + * @return true if the list is empty. + */ + @Override + public boolean isEmpty(); + + /** + * Adds val to the end of the list, growing as needed. + * + * @param val + * an short value + * @return true if the list was modified by the add operation + */ + @Override + public boolean add(short val); + + /** + * Adds the values in the array vals to the end of the list, in order. + * + * @param vals + * an short[] value + */ + public void add(short[] vals); + + /** + * Adds a subset of the values in the array vals to the end of the + * list, in order. + * + * @param vals + * an short[] value + * @param offset + * the offset at which to start copying + * @param length + * the number of values to copy. + */ + public void add(short[] vals, int offset, int length); + + /** + * Inserts value into the list at offset. All values including + * and to the right of offset are shifted to the right. + * + * @param offset + * an int value + * @param value + * an short value + */ + public void insert(int offset, short value); + + /** + * Inserts the array of values into the list at offset. All + * values including and to the right of offset are shifted to the + * right. + * + * @param offset + * an int value + * @param values + * an short[] value + */ + public void insert(int offset, short[] values); + + /** + * Inserts a slice of the array of values into the list at + * offset. All values including and to the right of offset are + * shifted to the right. + * + * @param offset + * an int value + * @param values + * an short[] value + * @param valOffset + * the offset in the values array at which to start copying. + * @param len + * the number of values to copy from the values array + */ + public void insert(int offset, short[] values, int valOffset, int len); + + /** + * Returns the value at the specified offset. + * + * @param offset + * an int value + * @return an short value + */ + public short get(int offset); + + /** + * Sets the value at the specified offset. + * + * @param offset + * an int value + * @param val + * an short value + * + * @return The value previously at the given index. + */ + public short set(int offset, short val); + + /** + * Replace the values in the list starting at offset with the contents + * of the values array. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + */ + public void set(int offset, short[] values); + + /** + * Replace the values in the list starting at offset with + * length values from the values array, starting at valOffset. + * + * @param offset + * the first offset to replace + * @param values + * the source of the new values + * @param valOffset + * the first value to copy from the values array + * @param length + * the number of values to copy + */ + public void set(int offset, short[] values, int valOffset, int length); + + /** + * Sets the value at the specified offset and returns the previously stored + * value. + * + * @param offset + * an int value + * @param val + * an short value + * @return the value previously stored at offset. + */ + public short replace(int offset, short val); + + /** + * Flushes the internal state of the list, resetting the capacity to the + * default. + */ + @Override + public void clear(); + + /** + * Removes value from the list. + * + * @param value + * an short value + * @return true if the list was modified by the remove operation. + */ + @Override + public boolean remove(short value); + + /** + * Removes value at a given offset from the list. + * + * @param offset + * an int value that represents the offset to the + * element to be removed + * @return an short that is the value removed. + */ + public short removeAt(int offset); + + /** + * Removes length values from the list, starting at offset + * + * @param offset + * an int value + * @param length + * an int value + */ + public void remove(int offset, int length); + + /** + * Transform each value in the list using the specified function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Reverse the order of the elements in the list. + */ + public void reverse(); + + /** + * Reverse the order of the elements in the range of the list. + * + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + public void reverse(int from, int to); + + /** + * Shuffle the elements of the list using the specified random number generator. + * + * @param rand + * a Random value + */ + public void shuffle(Random rand); + + /** + * Returns a sublist of this list. + * + * @param begin + * low endpoint (inclusive) of the subList. + * @param end + * high endpoint (exclusive) of the subList. + * @return sublist of this list from begin, inclusive to end, exclusive. + * @throws IndexOutOfBoundsException + * - endpoint out of range + * @throws IllegalArgumentException + * - endpoints out of order (end > begin) + */ + public TShortList subList(int begin, int end); + + /** + * Copies the contents of the list into a native array. + * + * @return an short[] value + */ + @Override + public short[] toArray(); + + /** + * Copies a slice of the list into a native array. + * + * @param offset + * the offset at which to start copying + * @param len + * the number of values to copy. + * @return an short[] value + */ + public short[] toArray(int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + *

+ * If the list fits in the specified array with room to spare (i.e., the array + * has more elements than the list), the element in the array immediately + * following the end of the list is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of the list only if the + * caller knows that the list does not contain any "null" elements.) + * + *

+ * NOTE: Trove does not allocate a new array if the array passed in is not large + * enough to hold all of the data elements. It will instead fill the array + * passed in. + * + * @param dest + * the array to copy into. + * @return the array passed in. + */ + @Override + public short[] toArray(short[] dest); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param offset + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public short[] toArray(short[] dest, int offset, int len); + + /** + * Copies a slice of the list into a native array. + * + * @param dest + * the array to copy into. + * @param source_pos + * the offset of the first value to copy + * @param dest_pos + * the offset where the first value should be copied + * @param len + * the number of values to copy. + * @return the array passed in. + */ + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len); + + /** + * Applies the procedure to each value in the list in ascending (front to back) + * order. + * + * @param procedure + * a TShortProcedure value + * @return true if the procedure did not terminate prematurely. + */ + @Override + public boolean forEach(TShortProcedure procedure); + + /** + * Applies the procedure to each value in the list in descending (back to front) + * order. + * + * @param procedure + * a TShortProcedure value + * @return true if the procedure did not terminate prematurely. + */ + public boolean forEachDescending(TShortProcedure procedure); + + /** + * Sort the values in the list (ascending) using the Sun quicksort + * implementation. + * + * @see java.util.Arrays#sort + */ + public void sort(); + + /** + * Sort a slice of the list (ascending) using the Sun quicksort implementation. + * + * @param fromIndex + * the index at which to start sorting (inclusive) + * @param toIndex + * the index at which to stop sorting (exclusive) + * @see java.util.Arrays#sort + */ + public void sort(int fromIndex, int toIndex); + + /** + * Fills every slot in the list with the specified value. + * + * @param val + * the value to use when filling + */ + public void fill(short val); + + /** + * Fills a range in the list with the specified value. + * + * @param fromIndex + * the offset at which to start filling (inclusive) + * @param toIndex + * the offset at which to stop filling (exclusive) + * @param val + * the value to use when filling + */ + public void fill(int fromIndex, int toIndex, short val); + + /** + * Performs a binary search for value in the entire list. Note that you + * must @{link #sort sort} the list before doing a search. + * + * @param value + * the value to search for + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(short value); + + /** + * Performs a binary search for value in the specified range. Note that + * you must @{link #sort sort} the list or the range before doing a + * search. + * + * @param value + * the value to search for + * @param fromIndex + * the lower boundary of the range (inclusive) + * @param toIndex + * the upper boundary of the range (exclusive) + * @return the absolute offset in the list of the value, or its negative + * insertion point into the sorted list. + */ + public int binarySearch(short value, int fromIndex, int toIndex); + + /** + * Searches the list front to back for the index of value. + * + * @param value + * an short value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(short value); + + /** + * Searches the list front to back for the index of value, starting at + * offset. + * + * @param offset + * the offset at which to start the linear search (inclusive) + * @param value + * an short value + * @return the first offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int indexOf(int offset, short value); + + /** + * Searches the list back to front for the last index of value. + * + * @param value + * an short value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(short value); + + /** + * Searches the list back to front for the last index of value, + * starting at offset. + * + * @param offset + * the offset at which to start the linear search (exclusive) + * @param value + * an short value + * @return the last offset of the value, or -1 if it is not in the list. + * @see #binarySearch for faster searches on sorted lists + */ + public int lastIndexOf(int offset, short value); + + /** + * Searches the list for value + * + * @param value + * an short value + * @return true if value is in the list. + */ + @Override + public boolean contains(short value); + + /** + * Searches the list for values satisfying condition in the manner of + * the *nix grep utility. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which match the condition. + */ + public TShortList grep(TShortProcedure condition); + + /** + * Searches the list for values which do not satisfy condition. + * This is akin to *nix grep -v. + * + * @param condition + * a condition to apply to each element in the list + * @return a list of values which do not match the condition. + */ + public TShortList inverseGrep(TShortProcedure condition); + + /** + * Finds the maximum value in the list. + * + * @return the largest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public short max(); + + /** + * Finds the minimum value in the list. + * + * @return the smallest value in the list. + * @exception IllegalStateException + * if the list is empty + */ + public short min(); + + /** + * Calculates the sum of all the values in the list. + * + * @return the sum of the values in the list (zero if the list is empty). + */ + public short sum(); +} diff --git a/src/gnu/trove/list/array/TByteArrayList.java b/src/gnu/trove/list/array/TByteArrayList.java new file mode 100644 index 0000000..43832a6 --- /dev/null +++ b/src/gnu/trove/list/array/TByteArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TByteFunction; +import gnu.trove.list.TByteList; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.TByteCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of byte primitives. + */ +public class TByteArrayList implements TByteList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected byte[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the byte value that represents null */ + protected byte no_entry_value; + + /** + * Creates a new TByteArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TByteArrayList() { + this(DEFAULT_CAPACITY, (byte) 0); + } + + /** + * Creates a new TByteArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TByteArrayList(int capacity) { + this(capacity, (byte) 0); + } + + /** + * Creates a new TByteArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an byte value that represents null. + */ + public TByteArrayList(int capacity, byte no_entry_value) { + _data = new byte[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TByteArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TByteArrayList(TByteCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TByteArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an byte[] value + */ + public TByteArrayList(byte[] values) { + this(values.length); + add(values); + } + + protected TByteArrayList(byte[] values, byte no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TByteArrayList wrap(byte[] values) { + return wrap(values, (byte) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TByteArrayList wrap(byte[] values, byte no_entry_value) { + return new TByteArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + byte[] tmp = new byte[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + byte[] tmp = new byte[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public byte get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public byte getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public byte set(int offset, byte val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + byte prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public byte replace(int offset, byte val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + byte old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, byte val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new byte[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte removeAt(int offset) { + byte old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (this == collection) { + return true; + } + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Byte element : collection) { + byte e = element.byteValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean changed = false; + for (byte element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + byte tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TByteList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TByteArrayList list = new TByteArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(int offset, int len) { + byte[] rv = new byte[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TByteList)) + return false; + + if (other instanceof TByteArrayList) { + TByteArrayList that = (TByteArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TByteList that = (TByteList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TByteProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(byte val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, byte val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + byte midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(byte value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, byte value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(byte value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, byte value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TByteList grep(TByteProcedure condition) { + TByteArrayList list = new TByteArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TByteList inverseGrep(TByteProcedure condition) { + TByteArrayList list = new TByteArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public byte max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + byte max = Byte.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public byte min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + byte min = Byte.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public byte sum() { + byte sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TByteArrayList iterator */ + class TByteArrayIterator implements TByteIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TByteArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + try { + byte next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TByteArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeByte(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // ENTRIES + int len = in.readInt(); + _data = new byte[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readByte(); + } + } +} // TByteArrayList diff --git a/src/gnu/trove/list/array/TCharArrayList.java b/src/gnu/trove/list/array/TCharArrayList.java new file mode 100644 index 0000000..47a0606 --- /dev/null +++ b/src/gnu/trove/list/array/TCharArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TCharFunction; +import gnu.trove.list.TCharList; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.TCharCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of char primitives. + */ +public class TCharArrayList implements TCharList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected char[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the char value that represents null */ + protected char no_entry_value; + + /** + * Creates a new TCharArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TCharArrayList() { + this(DEFAULT_CAPACITY, (char) 0); + } + + /** + * Creates a new TCharArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TCharArrayList(int capacity) { + this(capacity, (char) 0); + } + + /** + * Creates a new TCharArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an char value that represents null. + */ + public TCharArrayList(int capacity, char no_entry_value) { + _data = new char[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TCharArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TCharArrayList(TCharCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TCharArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an char[] value + */ + public TCharArrayList(char[] values) { + this(values.length); + add(values); + } + + protected TCharArrayList(char[] values, char no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TCharArrayList wrap(char[] values) { + return wrap(values, (char) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TCharArrayList wrap(char[] values, char no_entry_value) { + return new TCharArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + char[] tmp = new char[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + char[] tmp = new char[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public char get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public char getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public char set(int offset, char val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + char prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public char replace(int offset, char val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + char old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, char val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new char[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char removeAt(int offset) { + char old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (this == collection) { + return true; + } + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Character element : collection) { + char e = element.charValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean changed = false; + for (char element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + char tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TCharList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TCharArrayList list = new TCharArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(int offset, int len) { + char[] rv = new char[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TCharList)) + return false; + + if (other instanceof TCharArrayList) { + TCharArrayList that = (TCharArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TCharList that = (TCharList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TCharProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(char val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, char val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + char midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(char value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, char value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(char value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, char value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TCharList grep(TCharProcedure condition) { + TCharArrayList list = new TCharArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TCharList inverseGrep(TCharProcedure condition) { + TCharArrayList list = new TCharArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public char max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + char max = Character.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public char min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + char min = Character.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public char sum() { + char sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TCharArrayList iterator */ + class TCharArrayIterator implements TCharIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TCharArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public char next() { + try { + char next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TCharArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeChar(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // ENTRIES + int len = in.readInt(); + _data = new char[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readChar(); + } + } +} // TCharArrayList diff --git a/src/gnu/trove/list/array/TDoubleArrayList.java b/src/gnu/trove/list/array/TDoubleArrayList.java new file mode 100644 index 0000000..8720cb0 --- /dev/null +++ b/src/gnu/trove/list/array/TDoubleArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TDoubleFunction; +import gnu.trove.list.TDoubleList; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.TDoubleCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of double primitives. + */ +public class TDoubleArrayList implements TDoubleList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected double[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the double value that represents null */ + protected double no_entry_value; + + /** + * Creates a new TDoubleArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TDoubleArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TDoubleArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TDoubleArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TDoubleArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an double value that represents null. + */ + public TDoubleArrayList(int capacity, double no_entry_value) { + _data = new double[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TDoubleArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TDoubleArrayList(TDoubleCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TDoubleArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an double[] value + */ + public TDoubleArrayList(double[] values) { + this(values.length); + add(values); + } + + protected TDoubleArrayList(double[] values, double no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TDoubleArrayList wrap(double[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TDoubleArrayList wrap(double[] values, double no_entry_value) { + return new TDoubleArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + double[] tmp = new double[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + double[] tmp = new double[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public double get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public double getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public double set(int offset, double val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + double prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public double replace(int offset, double val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + double old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, double val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new double[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double removeAt(int offset) { + double old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (this == collection) { + return true; + } + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Double element : collection) { + double e = element.doubleValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean changed = false; + for (double element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + double tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TDoubleList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TDoubleArrayList list = new TDoubleArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(int offset, int len) { + double[] rv = new double[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TDoubleList)) + return false; + + if (other instanceof TDoubleArrayList) { + TDoubleArrayList that = (TDoubleArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TDoubleList that = (TDoubleList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(double val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, double val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + double midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(double value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, double value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(double value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, double value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList grep(TDoubleProcedure condition) { + TDoubleArrayList list = new TDoubleArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + TDoubleArrayList list = new TDoubleArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public double max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + double max = Double.NEGATIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public double min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + double min = Double.POSITIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public double sum() { + double sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TDoubleArrayList iterator */ + class TDoubleArrayIterator implements TDoubleIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TDoubleArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public double next() { + try { + double next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TDoubleArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeDouble(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // ENTRIES + int len = in.readInt(); + _data = new double[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readDouble(); + } + } +} // TDoubleArrayList diff --git a/src/gnu/trove/list/array/TFloatArrayList.java b/src/gnu/trove/list/array/TFloatArrayList.java new file mode 100644 index 0000000..ba671e3 --- /dev/null +++ b/src/gnu/trove/list/array/TFloatArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TFloatFunction; +import gnu.trove.list.TFloatList; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.TFloatCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of float primitives. + */ +public class TFloatArrayList implements TFloatList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected float[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the float value that represents null */ + protected float no_entry_value; + + /** + * Creates a new TFloatArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TFloatArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TFloatArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TFloatArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TFloatArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an float value that represents null. + */ + public TFloatArrayList(int capacity, float no_entry_value) { + _data = new float[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TFloatArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TFloatArrayList(TFloatCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TFloatArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an float[] value + */ + public TFloatArrayList(float[] values) { + this(values.length); + add(values); + } + + protected TFloatArrayList(float[] values, float no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TFloatArrayList wrap(float[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TFloatArrayList wrap(float[] values, float no_entry_value) { + return new TFloatArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + float[] tmp = new float[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + float[] tmp = new float[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public float get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public float getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public float set(int offset, float val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + float prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public float replace(int offset, float val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + float old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, float val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new float[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float removeAt(int offset) { + float old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (this == collection) { + return true; + } + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Float element : collection) { + float e = element.floatValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean changed = false; + for (float element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + float tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TFloatList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TFloatArrayList list = new TFloatArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(int offset, int len) { + float[] rv = new float[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TFloatList)) + return false; + + if (other instanceof TFloatArrayList) { + TFloatArrayList that = (TFloatArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TFloatList that = (TFloatList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(float val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, float val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + float midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(float value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, float value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(float value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, float value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TFloatList grep(TFloatProcedure condition) { + TFloatArrayList list = new TFloatArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + TFloatArrayList list = new TFloatArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public float max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + float max = Float.NEGATIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public float min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + float min = Float.POSITIVE_INFINITY; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public float sum() { + float sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TFloatArrayList iterator */ + class TFloatArrayIterator implements TFloatIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TFloatArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public float next() { + try { + float next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TFloatArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeFloat(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // ENTRIES + int len = in.readInt(); + _data = new float[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readFloat(); + } + } +} // TFloatArrayList diff --git a/src/gnu/trove/list/array/TIntArrayList.java b/src/gnu/trove/list/array/TIntArrayList.java new file mode 100644 index 0000000..9a07c33 --- /dev/null +++ b/src/gnu/trove/list/array/TIntArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TIntFunction; +import gnu.trove.list.TIntList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.TIntCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of int primitives. + */ +public class TIntArrayList implements TIntList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected int[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the int value that represents null */ + protected int no_entry_value; + + /** + * Creates a new TIntArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TIntArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TIntArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TIntArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TIntArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an int value that represents null. + */ + public TIntArrayList(int capacity, int no_entry_value) { + _data = new int[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TIntArrayList instance that contains a copy of the + * collection passed to us. + * + * @param collection + * the collection to copy + */ + public TIntArrayList(TIntCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TIntArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an int[] value + */ + public TIntArrayList(int[] values) { + this(values.length); + add(values); + } + + protected TIntArrayList(int[] values, int no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TIntArrayList wrap(int[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TIntArrayList wrap(int[] values, int no_entry_value) { + return new TIntArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + int[] tmp = new int[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + int[] tmp = new int[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public int get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public int getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public int set(int offset, int val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + int prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public int replace(int offset, int val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + int old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, int val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new int[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int removeAt(int offset) { + int old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + if (this == collection) { + return true; + } + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Integer element : collection) { + int e = element.intValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean changed = false; + for (int element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + int tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TIntList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TIntArrayList list = new TIntArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int offset, int len) { + int[] rv = new int[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TIntList)) + return false; + + if (other instanceof TIntArrayList) { + TIntArrayList that = (TIntArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TIntList that = (TIntList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TIntProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(int val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, int val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + int midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, int value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, int value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TIntList grep(TIntProcedure condition) { + TIntArrayList list = new TIntArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TIntList inverseGrep(TIntProcedure condition) { + TIntArrayList list = new TIntArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public int max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + int max = Integer.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public int min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + int min = Integer.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public int sum() { + int sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TIntArrayList iterator */ + class TIntArrayIterator implements TIntIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TIntArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public int next() { + try { + int next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TIntArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeInt(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // ENTRIES + int len = in.readInt(); + _data = new int[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readInt(); + } + } +} // TIntArrayList diff --git a/src/gnu/trove/list/array/TLongArrayList.java b/src/gnu/trove/list/array/TLongArrayList.java new file mode 100644 index 0000000..2379262 --- /dev/null +++ b/src/gnu/trove/list/array/TLongArrayList.java @@ -0,0 +1,1072 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TLongFunction; +import gnu.trove.list.TLongList; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.TLongCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of long primitives. + */ +public class TLongArrayList implements TLongList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected long[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the long value that represents null */ + protected long no_entry_value; + + /** + * Creates a new TLongArrayList instance with the default capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TLongArrayList() { + this(DEFAULT_CAPACITY, 0); + } + + /** + * Creates a new TLongArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TLongArrayList(int capacity) { + this(capacity, 0); + } + + /** + * Creates a new TLongArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an long value that represents null. + */ + public TLongArrayList(int capacity, long no_entry_value) { + _data = new long[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TLongArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TLongArrayList(TLongCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TLongArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an long[] value + */ + public TLongArrayList(long[] values) { + this(values.length); + add(values); + } + + protected TLongArrayList(long[] values, long no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TLongArrayList wrap(long[] values) { + return wrap(values, 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TLongArrayList wrap(long[] values, long no_entry_value) { + return new TLongArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + long[] tmp = new long[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + long[] tmp = new long[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public long get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public long getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public long set(int offset, long val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + long prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public long replace(int offset, long val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + long old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, long val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new long[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long removeAt(int offset) { + long old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + if (this == collection) { + return true; + } + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Long element : collection) { + long e = element.longValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean changed = false; + for (long element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + long tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TLongList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TLongArrayList list = new TLongArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(int offset, int len) { + long[] rv = new long[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TLongList)) + return false; + + if (other instanceof TLongArrayList) { + TLongArrayList that = (TLongArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TLongList that = (TLongList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TLongProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(long val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, long val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + long midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(long value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, long value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(long value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, long value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TLongList grep(TLongProcedure condition) { + TLongArrayList list = new TLongArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TLongList inverseGrep(TLongProcedure condition) { + TLongArrayList list = new TLongArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public long max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + long max = Long.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public long min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + long min = Long.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public long sum() { + long sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TLongArrayList iterator */ + class TLongArrayIterator implements TLongIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TLongArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public long next() { + try { + long next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TLongArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeLong(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // ENTRIES + int len = in.readInt(); + _data = new long[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readLong(); + } + } +} // TLongArrayList diff --git a/src/gnu/trove/list/array/TShortArrayList.java b/src/gnu/trove/list/array/TShortArrayList.java new file mode 100644 index 0000000..1309942 --- /dev/null +++ b/src/gnu/trove/list/array/TShortArrayList.java @@ -0,0 +1,1073 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.array; + +import gnu.trove.function.TShortFunction; +import gnu.trove.list.TShortList; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.TShortCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, array-backed list of short primitives. + */ +public class TShortArrayList implements TShortList, Externalizable { + static final long serialVersionUID = 1L; + + /** the data of the list */ + protected short[] _data; + + /** the index after the last entry in the list */ + protected int _pos; + + /** the default capacity for new lists */ + protected static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** the short value that represents null */ + protected short no_entry_value; + + /** + * Creates a new TShortArrayList instance with the default + * capacity. + */ + @SuppressWarnings({ "RedundantCast" }) + public TShortArrayList() { + this(DEFAULT_CAPACITY, (short) 0); + } + + /** + * Creates a new TShortArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + */ + @SuppressWarnings({ "RedundantCast" }) + public TShortArrayList(int capacity) { + this(capacity, (short) 0); + } + + /** + * Creates a new TShortArrayList instance with the specified + * capacity. + * + * @param capacity + * an int value + * @param no_entry_value + * an short value that represents null. + */ + public TShortArrayList(int capacity, short no_entry_value) { + _data = new short[capacity]; + _pos = 0; + this.no_entry_value = no_entry_value; + } + + /** + * Creates a new TShortArrayList instance that contains a copy of + * the collection passed to us. + * + * @param collection + * the collection to copy + */ + public TShortArrayList(TShortCollection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Creates a new TShortArrayList instance whose capacity is the + * length of values array and whose initial contents are the specified + * values. + *

+ * A defensive copy of the given values is held by the new instance. + * + * @param values + * an short[] value + */ + public TShortArrayList(short[] values) { + this(values.length); + add(values); + } + + protected TShortArrayList(short[] values, short no_entry_value, boolean wrap) { + if (!wrap) + throw new IllegalStateException("Wrong call"); + + if (values == null) + throw new IllegalArgumentException("values can not be null"); + + _data = values; + _pos = values.length; + this.no_entry_value = no_entry_value; + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @return + */ + public static TShortArrayList wrap(short[] values) { + return wrap(values, (short) 0); + } + + /** + * Returns a primitive ListCommand implementation that wraps around the given primitive + * array. + *

+ * NOTE: mutating operation are allowed as long as the ListCommand does not grow. In + * that case an IllegalStateException will be thrown + * + * @param values + * @param no_entry_value + * @return + */ + public static TShortArrayList wrap(short[] values, short no_entry_value) { + return new TShortArrayList(values, no_entry_value, true) { + /** + * Growing the wrapped external array is not allow + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) + throw new IllegalStateException("Can not grow ArrayList wrapped external array"); + } + }; + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + // sizing + + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_data.length << 1, capacity); + short[] tmp = new short[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _pos; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _pos == 0; + } + + /** + * Sheds any excess capacity above and beyond the current size of the list. + */ + public void trimToSize() { + if (_data.length > size()) { + short[] tmp = new short[size()]; + toArray(tmp, 0, tmp.length); + _data = tmp; + } + } + + // modifying + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + ensureCapacity(_pos + 1); + _data[_pos++] = val; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals) { + add(vals, 0, vals.length); + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals, int offset, int length) { + ensureCapacity(_pos + length); + System.arraycopy(vals, offset, _data, _pos, length); + _pos += length; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short value) { + if (offset == _pos) { + add(value); + return; + } + ensureCapacity(_pos + 1); + // shift right + System.arraycopy(_data, offset, _data, offset + 1, _pos - offset); + // insert + _data[offset] = value; + _pos++; + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values) { + insert(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + if (offset == _pos) { + add(values, valOffset, len); + return; + } + + ensureCapacity(_pos + len); + // shift right + System.arraycopy(_data, offset, _data, offset + len, _pos - offset); + // insert + System.arraycopy(values, valOffset, _data, offset, len); + _pos += len; + } + + /** {@inheritDoc} */ + @Override + public short get(int offset) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + return _data[offset]; + } + + /** + * Returns the value at the specified offset without doing any bounds checking. + */ + public short getQuick(int offset) { + return _data[offset]; + } + + /** {@inheritDoc} */ + @Override + public short set(int offset, short val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + short prev_val = _data[offset]; + _data[offset] = val; + return prev_val; + } + + /** {@inheritDoc} */ + @Override + public short replace(int offset, short val) { + if (offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + short old = _data[offset]; + _data[offset] = val; + return old; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values, int valOffset, int length) { + if (offset < 0 || offset + length > _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(values, valOffset, _data, offset, length); + } + + /** + * Sets the value at the specified offset without doing any bounds checking. + */ + public void setQuick(int offset, short val) { + _data[offset] = val; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + clear(DEFAULT_CAPACITY); + } + + /** + * Flushes the internal state of the list, setting the capacity of the empty + * list to capacity. + */ + public void clear(int capacity) { + _data = new short[capacity]; + _pos = 0; + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. + */ + public void reset() { + _pos = 0; + Arrays.fill(_data, no_entry_value); + } + + /** + * Sets the size of the list to 0, but does not change its capacity. This method + * can be used as an alternative to the {@link #clear()} method if you want to + * recycle a list without allocating new backing arrays. This method differs + * from {@link #reset()} in that it does not clear the old values in the backing + * array. Thus, it is possible for getQuick to return stale data if this method + * is used and the caller is careless about bounds checking. + */ + public void resetQuick() { + _pos = 0; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short value) { + for (int index = 0; index < _pos; index++) { + if (value == _data[index]) { + remove(index, 1); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short removeAt(int offset) { + short old = get(offset); + remove(offset, 1); + return old; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + if (length == 0) + return; + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + + if (offset == 0) { + // data at the front + System.arraycopy(_data, length, _data, 0, _pos - length); + } else if (_pos - length == offset) { + // no copy to make, decrementing pos "deletes" values at + // the end + } else { + // data in the middle + System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length)); + } + _pos -= length; + // no need to clear old values beyond _pos, because this is a + // primitive collection and 0 takes as much room as any other + // value + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortArrayIterator(0); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (this == collection) { + return true; + } + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Short element : collection) { + short e = element.shortValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean changed = false; + for (short element : array) { + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] data = _data; + + for (int i = _pos; i-- > 0;) { + if (Arrays.binarySearch(array, data[i]) < 0) { + remove(i, 1); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + for (int i = _pos; i-- > 0;) { + _data[i] = function.execute(_data[i]); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + reverse(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(i, j); + } + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = _pos; i-- > 1;) { + swap(i, rand.nextInt(i)); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int i, int j) { + short tmp = _data[i]; + _data[i] = _data[j]; + _data[j] = tmp; + } + + // copying + + /** {@inheritDoc} */ + @Override + public TShortList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("end index " + end + " greater than begin index " + begin); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > _data.length) { + throw new IndexOutOfBoundsException("end index < " + _data.length); + } + TShortArrayList list = new TShortArrayList(end - begin); + for (int i = begin; i < end; i++) { + list.add(_data[i]); + } + return list; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return toArray(0, _pos); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(int offset, int len) { + short[] rv = new short[len]; + toArray(rv, offset, len); + return rv; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + int len = dest.length; + if (dest.length > _pos) { + len = _pos; + dest[len] = no_entry_value; + } + toArray(dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int offset, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (offset < 0 || offset >= _pos) { + throw new ArrayIndexOutOfBoundsException(offset); + } + System.arraycopy(_data, offset, dest, 0, len); + return dest; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= _pos) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + System.arraycopy(_data, source_pos, dest, dest_pos, len); + return dest; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TShortList)) + return false; + + if (other instanceof TShortArrayList) { + TShortArrayList that = (TShortArrayList) other; + if (that.size() != this.size()) + return false; + + for (int i = _pos; i-- > 0;) { + if (this._data[i] != that._data[i]) { + return false; + } + } + return true; + } else { + TShortList that = (TShortList) other; + if (that.size() != this.size()) + return false; + + for (int i = 0; i < _pos; i++) { + if (this._data[i] != that.get(i)) { + return false; + } + } + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = _pos; i-- > 0;) { + h += HashFunctions.hash(_data[i]); + } + return h; + } + + // procedures + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + for (int i = 0; i < _pos; i++) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TShortProcedure procedure) { + for (int i = _pos; i-- > 0;) { + if (!procedure.execute(_data[i])) { + return false; + } + } + return true; + } + + // sorting + + /** {@inheritDoc} */ + @Override + public void sort() { + Arrays.sort(_data, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + Arrays.sort(_data, fromIndex, toIndex); + } + + // filling + + /** {@inheritDoc} */ + @Override + public void fill(short val) { + Arrays.fill(_data, 0, _pos, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, short val) { + if (toIndex > _pos) { + ensureCapacity(toIndex); + _pos = toIndex; + } + Arrays.fill(_data, fromIndex, toIndex, val); + } + + // searching + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value) { + return binarySearch(value, 0, _pos); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new ArrayIndexOutOfBoundsException(fromIndex); + } + if (toIndex > _pos) { + throw new ArrayIndexOutOfBoundsException(toIndex); + } + + int low = fromIndex; + int high = toIndex - 1; + + while (low <= high) { + int mid = (low + high) >>> 1; + short midVal = _data[mid]; + + if (midVal < value) { + low = mid + 1; + } else if (midVal > value) { + high = mid - 1; + } else { + return mid; // value found + } + } + return -(low + 1); // value not found. + } + + /** {@inheritDoc} */ + @Override + public int indexOf(short value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, short value) { + for (int i = offset; i < _pos; i++) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(short value) { + return lastIndexOf(_pos, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, short value) { + for (int i = offset; i-- > 0;) { + if (_data[i] == value) { + return i; + } + } + return -1; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short value) { + return lastIndexOf(value) >= 0; + } + + /** {@inheritDoc} */ + @Override + public TShortList grep(TShortProcedure condition) { + TShortArrayList list = new TShortArrayList(); + for (int i = 0; i < _pos; i++) { + if (condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public TShortList inverseGrep(TShortProcedure condition) { + TShortArrayList list = new TShortArrayList(); + for (int i = 0; i < _pos; i++) { + if (!condition.execute(_data[i])) { + list.add(_data[i]); + } + } + return list; + } + + /** {@inheritDoc} */ + @Override + public short max() { + if (size() == 0) { + throw new IllegalStateException("cannot find maximum of an empty list"); + } + short max = Short.MIN_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] > max) { + max = _data[i]; + } + } + return max; + } + + /** {@inheritDoc} */ + @Override + public short min() { + if (size() == 0) { + throw new IllegalStateException("cannot find minimum of an empty list"); + } + short min = Short.MAX_VALUE; + for (int i = 0; i < _pos; i++) { + if (_data[i] < min) { + min = _data[i]; + } + } + return min; + } + + /** {@inheritDoc} */ + @Override + public short sum() { + short sum = 0; + for (int i = 0; i < _pos; i++) { + sum += _data[i]; + } + return sum; + } + + // stringification + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = 0, end = _pos - 1; i < end; i++) { + buf.append(_data[i]); + buf.append(", "); + } + if (size() > 0) { + buf.append(_data[_pos - 1]); + } + buf.append("}"); + return buf.toString(); + } + + /** TShortArrayList iterator */ + class TShortArrayIterator implements TShortIterator { + + /** Index of element to be returned by subsequent call to next. */ + private int cursor = 0; + + /** + * Index of element returned by most recent call to next or previous. Reset to + * -1 if this element is deleted by a call to remove. + */ + int lastRet = -1; + + TShortArrayIterator(int index) { + cursor = index; + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return cursor < size(); + } + + /** {@inheritDoc} */ + @Override + public short next() { + try { + short next = get(cursor); + lastRet = cursor++; + return next; + } catch (IndexOutOfBoundsException e) { + throw new NoSuchElementException(); + } + } + + /** {@inheritDoc} */ + @Override + public void remove() { + if (lastRet == -1) + throw new IllegalStateException(); + + try { + TShortArrayList.this.remove(lastRet, 1); + if (lastRet < cursor) + cursor--; + lastRet = -1; + } catch (IndexOutOfBoundsException e) { + throw new ConcurrentModificationException(); + } + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // POSITION + out.writeInt(_pos); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // ENTRIES + int len = _data.length; + out.writeInt(len); + for (int i = 0; i < len; i++) { + out.writeShort(_data[i]); + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // POSITION + _pos = in.readInt(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // ENTRIES + int len = in.readInt(); + _data = new short[len]; + for (int i = 0; i < len; i++) { + _data[i] = in.readShort(); + } + } +} // TShortArrayList diff --git a/src/gnu/trove/list/linked/TByteLinkedList.java b/src/gnu/trove/list/linked/TByteLinkedList.java new file mode 100644 index 0000000..b45f0ec --- /dev/null +++ b/src/gnu/trove/list/linked/TByteLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TByteFunction; +import gnu.trove.list.TByteList; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.TByteCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of byte primitives. + */ +public class TByteLinkedList implements TByteList, Externalizable { + private byte no_entry_value; + private int size; + + private TByteLink head = null; + private TByteLink tail = head; + + public TByteLinkedList() { + this(Constants.DEFAULT_BYTE_NO_ENTRY_VALUE); + } + + public TByteLinkedList(byte no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TByteLinkedList(TByteList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TByteIterator iterator = list.iterator(); iterator.hasNext();) { + byte next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + TByteLink l = new TByteLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals) { + for (byte val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(byte[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + byte val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte value) { + TByteLinkedList tmp = new TByteLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, byte[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TByteLinkedList tmp) { + TByteLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TByteLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TByteLinkedList link(byte[] values, int valOffset, int len) { + TByteLinkedList ret = new TByteLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TByteLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TByteLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TByteLink getLink(TByteLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TByteLink getLink(TByteLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public byte set(int offset, byte val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TByteLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + byte prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, byte[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + byte value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public byte replace(int offset, byte val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte value) { + boolean changed = false; + for (TByteLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TByteLink from the list + * + * @param l + */ + private void removeLink(TByteLink l) { + if (no(l)) + return; + + size--; + + TByteLink prev = l.getPrevious(); + TByteLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Byte) { + Byte i = (Byte) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (isEmpty()) + return false; + + for (TByteIterator it = collection.iterator(); it.hasNext();) { + byte i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + if (isEmpty()) + return false; + + for (byte i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Byte v : collection) { + if (add(v.byteValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean ret = false; + for (TByteIterator it = collection.iterator(); it.hasNext();) { + byte i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean ret = false; + for (byte i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + Arrays.sort(array); + + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + Arrays.sort(array); + + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public byte removeAt(int offset) { + TByteLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + byte prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + for (TByteLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TByteLink h = head; + TByteLink t = tail; + TByteLink prev, next, tmp; + + // + TByteLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TByteLink start = getLinkAt(from); + TByteLink stop = getLinkAt(to); + TByteLink prev, next; + TByteLink tmp = null; + + TByteLink tmpHead = start.getPrevious(); + + // + TByteLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TByteLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TByteList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TByteLinkedList ret = new TByteLinkedList(); + TByteLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return toArray(new byte[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(int offset, int len) { + return toArray(new byte[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TByteLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + for (TByteLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TByteProcedure procedure) { + for (TByteLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TByteList tmp = subList(fromIndex, toIndex); + byte[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(byte val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, byte val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TByteLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(byte value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TByteLink middle; + int mid; + int from = fromIndex; + TByteLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(byte value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, byte value) { + int count = offset; + + TByteLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(byte value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, byte value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TByteLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte value) { + if (isEmpty()) + return false; + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteIterator() { + TByteLink l = head; + TByteLink current; + + @Override + public byte next() { + if (no(l)) + throw new NoSuchElementException(); + + byte ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TByteList grep(TByteProcedure condition) { + TByteList ret = new TByteLinkedList(); + for (TByteLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TByteList inverseGrep(TByteProcedure condition) { + TByteList ret = new TByteLinkedList(); + for (TByteLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte max() { + byte ret = Byte.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte min() { + byte ret = Byte.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TByteLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public byte sum() { + byte sum = 0; + + for (TByteLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TByteLink { + byte value; + TByteLink previous; + TByteLink next; + + TByteLink(byte value) { + this.value = value; + } + + public byte getValue() { + return value; + } + + public void setValue(byte value) { + this.value = value; + } + + public TByteLink getPrevious() { + return previous; + } + + public void setPrevious(TByteLink previous) { + this.previous = previous; + } + + public TByteLink getNext() { + return next; + } + + public void setNext(TByteLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TByteProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(byte value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TByteIterator iterator = iterator(); iterator.hasNext();) { + byte next = iterator.next(); + out.writeByte(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readByte()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TByteList)) + return false; + + TByteList that = (TByteList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TByteIterator it = iterator(); + while (it.hasNext()) { + byte next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TByteLinkedList diff --git a/src/gnu/trove/list/linked/TCharLinkedList.java b/src/gnu/trove/list/linked/TCharLinkedList.java new file mode 100644 index 0000000..3980c01 --- /dev/null +++ b/src/gnu/trove/list/linked/TCharLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TCharFunction; +import gnu.trove.list.TCharList; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.TCharCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of char primitives. + */ +public class TCharLinkedList implements TCharList, Externalizable { + private char no_entry_value; + private int size; + + private TCharLink head = null; + private TCharLink tail = head; + + public TCharLinkedList() { + this(Constants.DEFAULT_CHAR_NO_ENTRY_VALUE); + } + + public TCharLinkedList(char no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TCharLinkedList(TCharList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TCharIterator iterator = list.iterator(); iterator.hasNext();) { + char next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + TCharLink l = new TCharLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals) { + for (char val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(char[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + char val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char value) { + TCharLinkedList tmp = new TCharLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, char[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TCharLinkedList tmp) { + TCharLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TCharLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TCharLinkedList link(char[] values, int valOffset, int len) { + TCharLinkedList ret = new TCharLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TCharLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TCharLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TCharLink getLink(TCharLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TCharLink getLink(TCharLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public char set(int offset, char val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TCharLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + char prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, char[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + char value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public char replace(int offset, char val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char value) { + boolean changed = false; + for (TCharLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TCharLink from the list + * + * @param l + */ + private void removeLink(TCharLink l) { + if (no(l)) + return; + + size--; + + TCharLink prev = l.getPrevious(); + TCharLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Character) { + Character i = (Character) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (isEmpty()) + return false; + + for (TCharIterator it = collection.iterator(); it.hasNext();) { + char i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + if (isEmpty()) + return false; + + for (char i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Character v : collection) { + if (add(v.charValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean ret = false; + for (TCharIterator it = collection.iterator(); it.hasNext();) { + char i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean ret = false; + for (char i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + Arrays.sort(array); + + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + Arrays.sort(array); + + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public char removeAt(int offset) { + TCharLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + char prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + for (TCharLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TCharLink h = head; + TCharLink t = tail; + TCharLink prev, next, tmp; + + // + TCharLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TCharLink start = getLinkAt(from); + TCharLink stop = getLinkAt(to); + TCharLink prev, next; + TCharLink tmp = null; + + TCharLink tmpHead = start.getPrevious(); + + // + TCharLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TCharLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TCharList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TCharLinkedList ret = new TCharLinkedList(); + TCharLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return toArray(new char[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(int offset, int len) { + return toArray(new char[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TCharLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + for (TCharLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TCharProcedure procedure) { + for (TCharLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TCharList tmp = subList(fromIndex, toIndex); + char[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(char val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, char val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TCharLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(char value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TCharLink middle; + int mid; + int from = fromIndex; + TCharLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(char value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, char value) { + int count = offset; + + TCharLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(char value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, char value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TCharLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char value) { + if (isEmpty()) + return false; + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharIterator() { + TCharLink l = head; + TCharLink current; + + @Override + public char next() { + if (no(l)) + throw new NoSuchElementException(); + + char ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TCharList grep(TCharProcedure condition) { + TCharList ret = new TCharLinkedList(); + for (TCharLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TCharList inverseGrep(TCharProcedure condition) { + TCharList ret = new TCharLinkedList(); + for (TCharLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public char max() { + char ret = Character.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char min() { + char ret = Character.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TCharLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public char sum() { + char sum = 0; + + for (TCharLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TCharLink { + char value; + TCharLink previous; + TCharLink next; + + TCharLink(char value) { + this.value = value; + } + + public char getValue() { + return value; + } + + public void setValue(char value) { + this.value = value; + } + + public TCharLink getPrevious() { + return previous; + } + + public void setPrevious(TCharLink previous) { + this.previous = previous; + } + + public TCharLink getNext() { + return next; + } + + public void setNext(TCharLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TCharProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(char value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TCharIterator iterator = iterator(); iterator.hasNext();) { + char next = iterator.next(); + out.writeChar(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readChar()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TCharList)) + return false; + + TCharList that = (TCharList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TCharIterator it = iterator(); + while (it.hasNext()) { + char next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TCharLinkedList diff --git a/src/gnu/trove/list/linked/TDoubleLinkedList.java b/src/gnu/trove/list/linked/TDoubleLinkedList.java new file mode 100644 index 0000000..f8a4be8 --- /dev/null +++ b/src/gnu/trove/list/linked/TDoubleLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TDoubleFunction; +import gnu.trove.list.TDoubleList; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.TDoubleCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of double primitives. + */ +public class TDoubleLinkedList implements TDoubleList, Externalizable { + private double no_entry_value; + private int size; + + private TDoubleLink head = null; + private TDoubleLink tail = head; + + public TDoubleLinkedList() { + this(Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE); + } + + public TDoubleLinkedList(double no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TDoubleLinkedList(TDoubleList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TDoubleIterator iterator = list.iterator(); iterator.hasNext();) { + double next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + TDoubleLink l = new TDoubleLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals) { + for (double val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(double[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + double val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double value) { + TDoubleLinkedList tmp = new TDoubleLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, double[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TDoubleLinkedList tmp) { + TDoubleLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TDoubleLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TDoubleLinkedList link(double[] values, int valOffset, int len) { + TDoubleLinkedList ret = new TDoubleLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TDoubleLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TDoubleLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TDoubleLink getLink(TDoubleLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TDoubleLink getLink(TDoubleLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public double set(int offset, double val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TDoubleLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + double prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, double[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + double value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public double replace(int offset, double val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double value) { + boolean changed = false; + for (TDoubleLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TDoubleLink from the list + * + * @param l + */ + private void removeLink(TDoubleLink l) { + if (no(l)) + return; + + size--; + + TDoubleLink prev = l.getPrevious(); + TDoubleLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Double) { + Double i = (Double) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (isEmpty()) + return false; + + for (TDoubleIterator it = collection.iterator(); it.hasNext();) { + double i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + if (isEmpty()) + return false; + + for (double i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Double v : collection) { + if (add(v.doubleValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean ret = false; + for (TDoubleIterator it = collection.iterator(); it.hasNext();) { + double i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean ret = false; + for (double i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + Arrays.sort(array); + + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + Arrays.sort(array); + + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public double removeAt(int offset) { + TDoubleLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + double prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + for (TDoubleLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TDoubleLink h = head; + TDoubleLink t = tail; + TDoubleLink prev, next, tmp; + + // + TDoubleLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TDoubleLink start = getLinkAt(from); + TDoubleLink stop = getLinkAt(to); + TDoubleLink prev, next; + TDoubleLink tmp = null; + + TDoubleLink tmpHead = start.getPrevious(); + + // + TDoubleLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TDoubleLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TDoubleList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TDoubleLinkedList ret = new TDoubleLinkedList(); + TDoubleLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return toArray(new double[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(int offset, int len) { + return toArray(new double[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TDoubleLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TDoubleProcedure procedure) { + for (TDoubleLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TDoubleList tmp = subList(fromIndex, toIndex); + double[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(double val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, double val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TDoubleLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(double value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TDoubleLink middle; + int mid; + int from = fromIndex; + TDoubleLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(double value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, double value) { + int count = offset; + + TDoubleLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(double value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, double value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TDoubleLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double value) { + if (isEmpty()) + return false; + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleIterator() { + TDoubleLink l = head; + TDoubleLink current; + + @Override + public double next() { + if (no(l)) + throw new NoSuchElementException(); + + double ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList grep(TDoubleProcedure condition) { + TDoubleList ret = new TDoubleLinkedList(); + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TDoubleList inverseGrep(TDoubleProcedure condition) { + TDoubleList ret = new TDoubleLinkedList(); + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public double max() { + double ret = Double.NEGATIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double min() { + double ret = Double.POSITIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public double sum() { + double sum = 0; + + for (TDoubleLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TDoubleLink { + double value; + TDoubleLink previous; + TDoubleLink next; + + TDoubleLink(double value) { + this.value = value; + } + + public double getValue() { + return value; + } + + public void setValue(double value) { + this.value = value; + } + + public TDoubleLink getPrevious() { + return previous; + } + + public void setPrevious(TDoubleLink previous) { + this.previous = previous; + } + + public TDoubleLink getNext() { + return next; + } + + public void setNext(TDoubleLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TDoubleProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(double value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TDoubleIterator iterator = iterator(); iterator.hasNext();) { + double next = iterator.next(); + out.writeDouble(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readDouble()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TDoubleList)) + return false; + + TDoubleList that = (TDoubleList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TDoubleIterator it = iterator(); + while (it.hasNext()) { + double next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TDoubleLinkedList diff --git a/src/gnu/trove/list/linked/TFloatLinkedList.java b/src/gnu/trove/list/linked/TFloatLinkedList.java new file mode 100644 index 0000000..13a3bbb --- /dev/null +++ b/src/gnu/trove/list/linked/TFloatLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TFloatFunction; +import gnu.trove.list.TFloatList; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.TFloatCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of float primitives. + */ +public class TFloatLinkedList implements TFloatList, Externalizable { + private float no_entry_value; + private int size; + + private TFloatLink head = null; + private TFloatLink tail = head; + + public TFloatLinkedList() { + this(Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE); + } + + public TFloatLinkedList(float no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TFloatLinkedList(TFloatList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TFloatIterator iterator = list.iterator(); iterator.hasNext();) { + float next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + TFloatLink l = new TFloatLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals) { + for (float val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(float[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + float val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float value) { + TFloatLinkedList tmp = new TFloatLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, float[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TFloatLinkedList tmp) { + TFloatLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TFloatLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TFloatLinkedList link(float[] values, int valOffset, int len) { + TFloatLinkedList ret = new TFloatLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TFloatLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TFloatLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TFloatLink getLink(TFloatLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TFloatLink getLink(TFloatLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public float set(int offset, float val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TFloatLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + float prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, float[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + float value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public float replace(int offset, float val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float value) { + boolean changed = false; + for (TFloatLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TFloatLink from the list + * + * @param l + */ + private void removeLink(TFloatLink l) { + if (no(l)) + return; + + size--; + + TFloatLink prev = l.getPrevious(); + TFloatLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Float) { + Float i = (Float) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (isEmpty()) + return false; + + for (TFloatIterator it = collection.iterator(); it.hasNext();) { + float i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + if (isEmpty()) + return false; + + for (float i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Float v : collection) { + if (add(v.floatValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean ret = false; + for (TFloatIterator it = collection.iterator(); it.hasNext();) { + float i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean ret = false; + for (float i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + Arrays.sort(array); + + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + Arrays.sort(array); + + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public float removeAt(int offset) { + TFloatLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + float prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + for (TFloatLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TFloatLink h = head; + TFloatLink t = tail; + TFloatLink prev, next, tmp; + + // + TFloatLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TFloatLink start = getLinkAt(from); + TFloatLink stop = getLinkAt(to); + TFloatLink prev, next; + TFloatLink tmp = null; + + TFloatLink tmpHead = start.getPrevious(); + + // + TFloatLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TFloatLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TFloatList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TFloatLinkedList ret = new TFloatLinkedList(); + TFloatLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return toArray(new float[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(int offset, int len) { + return toArray(new float[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TFloatLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TFloatProcedure procedure) { + for (TFloatLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TFloatList tmp = subList(fromIndex, toIndex); + float[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(float val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, float val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TFloatLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(float value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TFloatLink middle; + int mid; + int from = fromIndex; + TFloatLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(float value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, float value) { + int count = offset; + + TFloatLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(float value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, float value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TFloatLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float value) { + if (isEmpty()) + return false; + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatIterator() { + TFloatLink l = head; + TFloatLink current; + + @Override + public float next() { + if (no(l)) + throw new NoSuchElementException(); + + float ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TFloatList grep(TFloatProcedure condition) { + TFloatList ret = new TFloatLinkedList(); + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TFloatList inverseGrep(TFloatProcedure condition) { + TFloatList ret = new TFloatLinkedList(); + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public float max() { + float ret = Float.NEGATIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float min() { + float ret = Float.POSITIVE_INFINITY; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TFloatLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public float sum() { + float sum = 0; + + for (TFloatLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TFloatLink { + float value; + TFloatLink previous; + TFloatLink next; + + TFloatLink(float value) { + this.value = value; + } + + public float getValue() { + return value; + } + + public void setValue(float value) { + this.value = value; + } + + public TFloatLink getPrevious() { + return previous; + } + + public void setPrevious(TFloatLink previous) { + this.previous = previous; + } + + public TFloatLink getNext() { + return next; + } + + public void setNext(TFloatLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TFloatProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(float value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TFloatIterator iterator = iterator(); iterator.hasNext();) { + float next = iterator.next(); + out.writeFloat(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readFloat()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TFloatList)) + return false; + + TFloatList that = (TFloatList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TFloatIterator it = iterator(); + while (it.hasNext()) { + float next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TFloatLinkedList diff --git a/src/gnu/trove/list/linked/TIntLinkedList.java b/src/gnu/trove/list/linked/TIntLinkedList.java new file mode 100644 index 0000000..938a29e --- /dev/null +++ b/src/gnu/trove/list/linked/TIntLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TIntFunction; +import gnu.trove.list.TIntList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.TIntCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of int primitives. + */ +public class TIntLinkedList implements TIntList, Externalizable { + private int no_entry_value; + private int size; + + private TIntLink head = null; + private TIntLink tail = head; + + public TIntLinkedList() { + this(Constants.DEFAULT_INT_NO_ENTRY_VALUE); + } + + public TIntLinkedList(int no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TIntLinkedList(TIntList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TIntIterator iterator = list.iterator(); iterator.hasNext();) { + int next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + TIntLink l = new TIntLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals) { + for (int val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(int[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + int val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int value) { + TIntLinkedList tmp = new TIntLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, int[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TIntLinkedList tmp) { + TIntLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TIntLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TIntLinkedList link(int[] values, int valOffset, int len) { + TIntLinkedList ret = new TIntLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TIntLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TIntLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TIntLink getLink(TIntLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TIntLink getLink(TIntLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public int set(int offset, int val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TIntLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + int prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, int[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + int value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public int replace(int offset, int val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int value) { + boolean changed = false; + for (TIntLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TIntLink from the list + * + * @param l + */ + private void removeLink(TIntLink l) { + if (no(l)) + return; + + size--; + + TIntLink prev = l.getPrevious(); + TIntLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Integer) { + Integer i = (Integer) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + if (isEmpty()) + return false; + + for (TIntIterator it = collection.iterator(); it.hasNext();) { + int i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + if (isEmpty()) + return false; + + for (int i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Integer v : collection) { + if (add(v.intValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean ret = false; + for (TIntIterator it = collection.iterator(); it.hasNext();) { + int i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean ret = false; + for (int i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + Arrays.sort(array); + + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + Arrays.sort(array); + + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public int removeAt(int offset) { + TIntLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + int prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + for (TIntLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TIntLink h = head; + TIntLink t = tail; + TIntLink prev, next, tmp; + + // + TIntLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TIntLink start = getLinkAt(from); + TIntLink stop = getLinkAt(to); + TIntLink prev, next; + TIntLink tmp = null; + + TIntLink tmpHead = start.getPrevious(); + + // + TIntLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TIntLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TIntList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TIntLinkedList ret = new TIntLinkedList(); + TIntLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return toArray(new int[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int offset, int len) { + return toArray(new int[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TIntLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + for (TIntLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TIntProcedure procedure) { + for (TIntLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TIntList tmp = subList(fromIndex, toIndex); + int[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(int val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, int val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TIntLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(int value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TIntLink middle; + int mid; + int from = fromIndex; + TIntLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, int value) { + int count = offset; + + TIntLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, int value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TIntLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int value) { + if (isEmpty()) + return false; + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIterator() { + TIntLink l = head; + TIntLink current; + + @Override + public int next() { + if (no(l)) + throw new NoSuchElementException(); + + int ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TIntList grep(TIntProcedure condition) { + TIntList ret = new TIntLinkedList(); + for (TIntLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TIntList inverseGrep(TIntProcedure condition) { + TIntList ret = new TIntLinkedList(); + for (TIntLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public int max() { + int ret = Integer.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int min() { + int ret = Integer.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TIntLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public int sum() { + int sum = 0; + + for (TIntLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TIntLink { + int value; + TIntLink previous; + TIntLink next; + + TIntLink(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public void setValue(int value) { + this.value = value; + } + + public TIntLink getPrevious() { + return previous; + } + + public void setPrevious(TIntLink previous) { + this.previous = previous; + } + + public TIntLink getNext() { + return next; + } + + public void setNext(TIntLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TIntProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(int value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TIntIterator iterator = iterator(); iterator.hasNext();) { + int next = iterator.next(); + out.writeInt(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readInt()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TIntList)) + return false; + + TIntList that = (TIntList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TIntIterator it = iterator(); + while (it.hasNext()) { + int next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TIntLinkedList diff --git a/src/gnu/trove/list/linked/TLinkedList.java b/src/gnu/trove/list/linked/TLinkedList.java new file mode 100644 index 0000000..88c2ffa --- /dev/null +++ b/src/gnu/trove/list/linked/TLinkedList.java @@ -0,0 +1,849 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.list.TLinkable; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.*; +import java.util.AbstractSequentialList; +import java.util.ListIterator; +import java.util.NoSuchElementException; +import java.lang.reflect.Array; + +/** + *

+ * A LinkedList implementation which holds instances of type TLinkable. + *

+ * Using this implementation allows you to get java.util.LinkedList behavior (a + * doubly linked list, with Iterators that support insert and delete operations) + * without incurring the overhead of creating Node wrapper objects for + * every element in your list. + *

+ * The requirement to achieve this time/space gain is that the Objects stored in + * the ListCommand implement the TLinkable interface. + *

+ * The limitations are: + *

    + *
  • the same object cannot be put into more than one list at the same time. + *
  • the same object cannot be put into the same list more than once at the + * same time. + *
  • objects must only be removed from list they are in. That is, if you have + * an object A and lists l1 and l2, you must ensure that you invoke + * ListCommand.remove(A) on the correct list. + *
  • It is also forbidden to invoke ListCommand.remove() with an unaffiliated + * TLinkable (one that belongs to no list): this will destroy the list you + * invoke it on. + *
+ * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: TLinkedList.java,v 1.1.2.3 2010/09/27 17:23:07 robeden Exp $ + * @see gnu.trove.list.TLinkable + */ + +public class TLinkedList> extends AbstractSequentialList implements Externalizable { + + static final long serialVersionUID = 1L; + + /** the head of the list */ + protected T _head; + /** the tail of the list */ + protected T _tail; + /** the number of elements in the list */ + protected int _size = 0; + + /** Creates a new TLinkedList instance. */ + public TLinkedList() { + super(); + } + + /** + * Returns an iterator positioned at index. Assuming that the list has + * a value at that index, calling next() will retrieve and advance the iterator. + * Assuming that there is a value before index in the list, calling + * previous() will retrieve it (the value at index - 1) and move the iterator to + * that position. So, iterating from front to back starts at 0; iterating from + * back to front starts at size(). + * + * @param index + * an int value + * @return a ListIterator value + */ + @Override + public ListIterator listIterator(int index) { + return new IteratorImpl(index); + } + + /** + * Returns the number of elements in the list. + * + * @return an int value + */ + @Override + public int size() { + return _size; + } + + /** + * Inserts linkable at index index in the list. All values > + * index are shifted over one position to accommodate the new addition. + * + * @param index + * an int value + * @param linkable + * an object of type TLinkable + */ + @Override + public void add(int index, T linkable) { + if (index < 0 || index > size()) { + throw new IndexOutOfBoundsException("index:" + index); + } + insert(index, linkable); + } + + /** + * Appends linkable to the end of the list. + * + * @param linkable + * an object of type TLinkable + * @return always true + */ + @Override + public boolean add(T linkable) { + insert(_size, linkable); + return true; + } + + /** + * Inserts linkable at the head of the list. + * + * @param linkable + * an object of type TLinkable + */ + public void addFirst(T linkable) { + insert(0, linkable); + } + + /** + * Adds linkable to the end of the list. + * + * @param linkable + * an object of type TLinkable + */ + public void addLast(T linkable) { + insert(size(), linkable); + } + + /** Empties the list. */ + @Override + public void clear() { + if (null != _head) { + for (TLinkable link = _head.getNext(); link != null; link = link.getNext()) { + TLinkable prev = link.getPrevious(); + prev.setNext(null); + link.setPrevious(null); + } + _head = _tail = null; + } + _size = 0; + } + + /** + * Copies the list's contents into a native array. This will be a shallow copy: + * the Tlinkable instances in the Object[] array have links to one another: + * changing those will put this list into an unpredictable state. Holding a + * reference to one element in the list will prevent the others from being + * garbage collected unless you clear the next/previous links. Caveat + * programmer! + * + * @return an Object[] value + */ + @Override + public Object[] toArray() { + Object[] o = new Object[_size]; + int i = 0; + for (TLinkable link = _head; link != null; link = link.getNext()) { + o[i++] = link; + } + return o; + } + + /** + * Copies the list to a native array, destroying the next/previous links as the + * copy is made. This list will be emptied after the copy (as if clear() had + * been invoked). The Object[] array returned will contain TLinkables that do + * not hold references to one another and so are less likely to be the + * cause of memory leaks. + * + * @return an Object[] value + */ + public Object[] toUnlinkedArray() { + Object[] o = new Object[_size]; + int i = 0; + for (TLinkable link = _head, tmp; link != null; i++) { + o[i] = link; + tmp = link; + link = link.getNext(); + tmp.setNext(null); // clear the links + tmp.setPrevious(null); + } + _size = 0; // clear the list + _head = _tail = null; + return o; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @SuppressWarnings({ "unchecked" }) + public T[] toUnlinkedArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + int i = 0; + for (T link = _head, tmp; link != null; i++) { + a[i] = link; + tmp = link; + link = link.getNext(); + tmp.setNext(null); // clear the links + tmp.setPrevious(null); + } + _size = 0; // clear the list + _head = _tail = null; + return a; + } + + /** + * A linear search for o in the list. + * + * @param o + * an Object value + * @return a boolean value + */ + @Override + public boolean contains(Object o) { + for (TLinkable link = _head; link != null; link = link.getNext()) { + if (o.equals(link)) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public T get(int index) { + // Blow out for bogus values + if (index < 0 || index >= _size) { + throw new IndexOutOfBoundsException("Index: " + index + ", Size: " + _size); + } + + // Determine if it's better to get there from the front or the back + if (index > (_size >> 1)) { + int position = _size - 1; + T node = _tail; + + while (position > index) { + node = node.getPrevious(); + position--; + } + + return node; + } else { + int position = 0; + T node = _head; + + while (position < index) { + node = node.getNext(); + position++; + } + + return node; + } + } + + /** + * Returns the head of the list + * + * @return an Object value + */ + public T getFirst() { + return _head; + } + + /** + * Returns the tail of the list. + * + * @return an Object value + */ + public T getLast() { + return _tail; + } + + /** + * Return the node following the given node. This method exists for two reasons: + *
    + *
  1. It's really not recommended that the methods implemented by TLinkable be + * called directly since they're used internally by this class.
  2. + *
  3. This solves problems arising from generics when working with the linked + * objects directly.
  4. + *
+ *

+ * NOTE: this should only be used with nodes contained in the list. The results + * are undefined with anything else. + * + * @param current + * The current node + * @return the node after the current node + */ + @SuppressWarnings({ "unchecked" }) + public T getNext(T current) { + return current.getNext(); + } + + /** + * Return the node preceding the given node. This method exists for two reasons: + *

    + *
  1. It's really not recommended that the methods implemented by TLinkable be + * called directly since they're used internally by this class.
  2. + *
  3. This solves problems arising from generics when working with the linked + * objects directly.
  4. + *
+ *

+ * NOTE: this should only be used with nodes contained in the list. The results + * are undefined with anything else. + * + * @param current + * The current node + * @return the node after the current node + */ + @SuppressWarnings({ "unchecked" }) + public T getPrevious(T current) { + return current.getPrevious(); + } + + /** + * Remove and return the first element in the list. + * + * @return an Object value + */ + @SuppressWarnings({ "unchecked" }) + public T removeFirst() { + T o = _head; + + if (o == null) { + return null; + } + + T n = o.getNext(); + o.setNext(null); + + if (null != n) { + n.setPrevious(null); + } + + _head = n; + if (--_size == 0) { + _tail = null; + } + return o; + } + + /** + * Remove and return the last element in the list. + * + * @return an Object value + */ + @SuppressWarnings({ "unchecked" }) + public T removeLast() { + T o = _tail; + + if (o == null) { + return null; + } + + T prev = o.getPrevious(); + o.setPrevious(null); + + if (null != prev) { + prev.setNext(null); + } + _tail = prev; + if (--_size == 0) { + _head = null; + } + return o; + } + + /** + * Implementation of index-based list insertions. + * + * @param index + * an int value + * @param linkable + * an object of type TLinkable + */ + @SuppressWarnings({ "unchecked" }) + protected void insert(int index, T linkable) { + + if (_size == 0) { + _head = _tail = linkable; // first insertion + } else if (index == 0) { + linkable.setNext(_head); // insert at front + _head.setPrevious(linkable); + _head = linkable; + } else if (index == _size) { // insert at back + _tail.setNext(linkable); + linkable.setPrevious(_tail); + _tail = linkable; + } else { + T node = get(index); + + T before = node.getPrevious(); + if (before != null) { + before.setNext(linkable); + } + + linkable.setPrevious(before); + linkable.setNext(node); + node.setPrevious(linkable); + } + _size++; + } + + /** + * Removes the specified element from the list. Note that it is the caller's + * responsibility to ensure that the element does, in fact, belong to this list + * and not another instance of TLinkedList. + * + * @param o + * a TLinkable element already inserted in this list. + * @return true if the element was a TLinkable and removed + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + if (o instanceof TLinkable) { + T p, n; + TLinkable link = (TLinkable) o; + + p = link.getPrevious(); + n = link.getNext(); + + if (n == null && p == null) { // emptying the list + // It's possible this object is not something that's in the list. So, + // make sure it's the head if it doesn't point to anything. This solves + // problems caused by removing something multiple times. + if (o != _head) { + return false; + } + + _head = _tail = null; + } else if (n == null) { // this is the tail + // make previous the new tail + link.setPrevious(null); + p.setNext(null); + _tail = p; + } else if (p == null) { // this is the head + // make next the new head + link.setNext(null); + n.setPrevious(null); + _head = n; + } else { // somewhere in the middle + p.setNext(n); + n.setPrevious(p); + link.setNext(null); + link.setPrevious(null); + } + + _size--; // reduce size of list + return true; + } else { + return false; + } + } + + /** + * Inserts newElement into the list immediately before current. All elements to + * the right of and including current are shifted over. + * + * @param current + * a TLinkable value currently in the list. + * @param newElement + * a TLinkable value to be added to the list. + */ + public void addBefore(T current, T newElement) { + if (current == _head) { + addFirst(newElement); + } else if (current == null) { + addLast(newElement); + } else { + T p = current.getPrevious(); + newElement.setNext(current); + p.setNext(newElement); + newElement.setPrevious(p); + current.setPrevious(newElement); + _size++; + } + } + + /** + * Inserts newElement into the list immediately after current. All elements to + * the left of and including current are shifted over. + * + * @param current + * a TLinkable value currently in the list. + * @param newElement + * a TLinkable value to be added to the list. + */ + public void addAfter(T current, T newElement) { + if (current == _tail) { + addLast(newElement); + } else if (current == null) { + addFirst(newElement); + } else { + T n = current.getNext(); + newElement.setPrevious(current); + newElement.setNext(n); + current.setNext(newElement); + n.setPrevious(newElement); + _size++; + } + } + + /** + * Executes procedure for each entry in the list. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEachValue(TObjectProcedure procedure) { + T node = _head; + while (node != null) { + boolean keep_going = procedure.execute(node); + if (!keep_going) { + return false; + } + + node = node.getNext(); + } + + return true; + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // HEAD + out.writeObject(_head); + + // TAIL + out.writeObject(_tail); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NUMBER OF ENTRIED + _size = in.readInt(); + + // HEAD + _head = (T) in.readObject(); + + // TAIL + _tail = (T) in.readObject(); + } + + /** A ListIterator that supports additions and deletions. */ + protected final class IteratorImpl implements ListIterator { + + private int _nextIndex = 0; + private T _next; + private T _lastReturned; + + /** + * Creates a new Iterator instance positioned at index. + * + * @param position + * an int value + */ + @SuppressWarnings({ "unchecked" }) + IteratorImpl(int position) { + if (position < 0 || position > _size) { + throw new IndexOutOfBoundsException(); + } + + _nextIndex = position; + if (position == 0) { + _next = _head; + } else if (position == _size) { + _next = null; + } else if (position < (_size >> 1)) { + int pos = 0; + for (_next = _head; pos < position; pos++) { + _next = _next.getNext(); + } + } else { + int pos = _size - 1; + for (_next = _tail; pos > position; pos--) { + _next = _next.getPrevious(); + } + } + } + + /** + * Insert linkable at the current position of the iterator. Calling + * next() after add() will return the added object. + * + * @param linkable + * an object of type TLinkable + */ + @Override + public final void add(T linkable) { + _lastReturned = null; + _nextIndex++; + + if (_size == 0) { + TLinkedList.this.add(linkable); + } else { + TLinkedList.this.addBefore(_next, linkable); + } + } + + /** + * True if a call to next() will return an object. + * + * @return a boolean value + */ + @Override + public final boolean hasNext() { + return _nextIndex != _size; + } + + /** + * True if a call to previous() will return a value. + * + * @return a boolean value + */ + @Override + public final boolean hasPrevious() { + return _nextIndex != 0; + } + + /** + * Returns the value at the Iterator's index and advances the iterator. + * + * @return an Object value + * @throws NoSuchElementException + * if there is no next element + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final T next() { + if (_nextIndex == _size) { + throw new NoSuchElementException(); + } + + _lastReturned = _next; + _next = _next.getNext(); + _nextIndex++; + return _lastReturned; + } + + /** + * returns the index of the next node in the list (the one that would be + * returned by a call to next()). + * + * @return an int value + */ + @Override + public final int nextIndex() { + return _nextIndex; + } + + /** + * Returns the value before the Iterator's index and moves the iterator back one + * index. + * + * @return an Object value + * @throws NoSuchElementException + * if there is no previous element. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final T previous() { + if (_nextIndex == 0) { + throw new NoSuchElementException(); + } + + if (_nextIndex == _size) { + _lastReturned = _next = _tail; + } else { + _lastReturned = _next = _next.getPrevious(); + } + + _nextIndex--; + return _lastReturned; + } + + /** + * Returns the previous element's index. + * + * @return an int value + */ + @Override + public final int previousIndex() { + return _nextIndex - 1; + } + + /** + * Removes the current element in the list and shrinks its size accordingly. + * + * @throws IllegalStateException + * neither next nor previous have been invoked, or remove or add + * have been invoked after the last invocation of next or previous. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public final void remove() { + if (_lastReturned == null) { + throw new IllegalStateException("must invoke next or previous before invoking remove"); + } + + if (_lastReturned != _next) { + _nextIndex--; + } + _next = _lastReturned.getNext(); + TLinkedList.this.remove(_lastReturned); + _lastReturned = null; + } + + /** + * Replaces the current element in the list with linkable + * + * @param linkable + * an object of type TLinkable + */ + @Override + public final void set(T linkable) { + if (_lastReturned == null) { + throw new IllegalStateException(); + } + + swap(_lastReturned, linkable); + _lastReturned = linkable; + } + + /** + * Replace from with to in the list. + * + * @param from + * a TLinkable value + * @param to + * a TLinkable value + */ + private void swap(T from, T to) { + T from_p = from.getPrevious(); + T from_n = from.getNext(); + + T to_p = to.getPrevious(); + T to_n = to.getNext(); + + // NOTE: 'to' cannot be null at this point + if (from_n == to) { + if (from_p != null) + from_p.setNext(to); + to.setPrevious(from_p); + to.setNext(from); + from.setPrevious(to); + from.setNext(to_n); + if (to_n != null) + to_n.setPrevious(from); + } + // NOTE: 'from' cannot be null at this point + else if (to_n == from) { + if (to_p != null) + to_p.setNext(to); + to.setPrevious(from); + to.setNext(from_n); + from.setPrevious(to_p); + from.setNext(to); + if (from_n != null) + from_n.setPrevious(to); + } else { + from.setNext(to_n); + from.setPrevious(to_p); + if (to_p != null) + to_p.setNext(from); + if (to_n != null) + to_n.setPrevious(from); + + to.setNext(from_n); + to.setPrevious(from_p); + if (from_p != null) + from_p.setNext(to); + if (from_n != null) + from_n.setPrevious(to); + } + + if (_head == from) + _head = to; + else if (_head == to) + _head = from; + + if (_tail == from) + _tail = to; + else if (_tail == to) + _tail = from; + + if (_lastReturned == from) + _lastReturned = to; + else if (_lastReturned == to) + _lastReturned = from; + + if (_next == from) + _next = to; + else if (_next == to) + _next = from; + } + } +} // TLinkedList diff --git a/src/gnu/trove/list/linked/TLongLinkedList.java b/src/gnu/trove/list/linked/TLongLinkedList.java new file mode 100644 index 0000000..fe3a611 --- /dev/null +++ b/src/gnu/trove/list/linked/TLongLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TLongFunction; +import gnu.trove.list.TLongList; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.TLongCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of long primitives. + */ +public class TLongLinkedList implements TLongList, Externalizable { + private long no_entry_value; + private int size; + + private TLongLink head = null; + private TLongLink tail = head; + + public TLongLinkedList() { + this(Constants.DEFAULT_LONG_NO_ENTRY_VALUE); + } + + public TLongLinkedList(long no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TLongLinkedList(TLongList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TLongIterator iterator = list.iterator(); iterator.hasNext();) { + long next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + TLongLink l = new TLongLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals) { + for (long val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(long[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + long val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long value) { + TLongLinkedList tmp = new TLongLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, long[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TLongLinkedList tmp) { + TLongLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TLongLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TLongLinkedList link(long[] values, int valOffset, int len) { + TLongLinkedList ret = new TLongLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TLongLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TLongLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TLongLink getLink(TLongLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TLongLink getLink(TLongLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public long set(int offset, long val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TLongLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + long prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, long[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + long value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public long replace(int offset, long val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long value) { + boolean changed = false; + for (TLongLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TLongLink from the list + * + * @param l + */ + private void removeLink(TLongLink l) { + if (no(l)) + return; + + size--; + + TLongLink prev = l.getPrevious(); + TLongLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Long) { + Long i = (Long) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + if (isEmpty()) + return false; + + for (TLongIterator it = collection.iterator(); it.hasNext();) { + long i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + if (isEmpty()) + return false; + + for (long i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Long v : collection) { + if (add(v.longValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean ret = false; + for (TLongIterator it = collection.iterator(); it.hasNext();) { + long i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean ret = false; + for (long i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + Arrays.sort(array); + + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + Arrays.sort(array); + + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public long removeAt(int offset) { + TLongLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + long prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + for (TLongLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TLongLink h = head; + TLongLink t = tail; + TLongLink prev, next, tmp; + + // + TLongLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TLongLink start = getLinkAt(from); + TLongLink stop = getLinkAt(to); + TLongLink prev, next; + TLongLink tmp = null; + + TLongLink tmpHead = start.getPrevious(); + + // + TLongLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TLongLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TLongList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TLongLinkedList ret = new TLongLinkedList(); + TLongLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return toArray(new long[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(int offset, int len) { + return toArray(new long[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TLongLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + for (TLongLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TLongProcedure procedure) { + for (TLongLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TLongList tmp = subList(fromIndex, toIndex); + long[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(long val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, long val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TLongLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(long value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TLongLink middle; + int mid; + int from = fromIndex; + TLongLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(long value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, long value) { + int count = offset; + + TLongLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(long value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, long value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TLongLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long value) { + if (isEmpty()) + return false; + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongIterator() { + TLongLink l = head; + TLongLink current; + + @Override + public long next() { + if (no(l)) + throw new NoSuchElementException(); + + long ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TLongList grep(TLongProcedure condition) { + TLongList ret = new TLongLinkedList(); + for (TLongLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TLongList inverseGrep(TLongProcedure condition) { + TLongList ret = new TLongLinkedList(); + for (TLongLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public long max() { + long ret = Long.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long min() { + long ret = Long.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TLongLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public long sum() { + long sum = 0; + + for (TLongLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TLongLink { + long value; + TLongLink previous; + TLongLink next; + + TLongLink(long value) { + this.value = value; + } + + public long getValue() { + return value; + } + + public void setValue(long value) { + this.value = value; + } + + public TLongLink getPrevious() { + return previous; + } + + public void setPrevious(TLongLink previous) { + this.previous = previous; + } + + public TLongLink getNext() { + return next; + } + + public void setNext(TLongLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TLongProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(long value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TLongIterator iterator = iterator(); iterator.hasNext();) { + long next = iterator.next(); + out.writeLong(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readLong()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TLongList)) + return false; + + TLongList that = (TLongList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TLongIterator it = iterator(); + while (it.hasNext()) { + long next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TLongLinkedList diff --git a/src/gnu/trove/list/linked/TShortLinkedList.java b/src/gnu/trove/list/linked/TShortLinkedList.java new file mode 100644 index 0000000..b1ee750 --- /dev/null +++ b/src/gnu/trove/list/linked/TShortLinkedList.java @@ -0,0 +1,1118 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// Copyright (c) 2011, Johan Parent All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.list.linked; + +import gnu.trove.function.TShortFunction; +import gnu.trove.list.TShortList; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.TShortCollection; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A resizable, double linked list of short primitives. + */ +public class TShortLinkedList implements TShortList, Externalizable { + private short no_entry_value; + private int size; + + private TShortLink head = null; + private TShortLink tail = head; + + public TShortLinkedList() { + this(Constants.DEFAULT_SHORT_NO_ENTRY_VALUE); + } + + public TShortLinkedList(short no_entry_value) { + this.no_entry_value = no_entry_value; + } + + public TShortLinkedList(TShortList list) { + no_entry_value = list.getNoEntryValue(); + // + for (TShortIterator iterator = list.iterator(); iterator.hasNext();) { + short next = iterator.next(); + add(next); + } + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return size() == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + TShortLink l = new TShortLink(val); + if (no(head)) { + head = l; + tail = l; + } else { + l.setPrevious(tail); + tail.setNext(l); + // + tail = l; + } + + size++; + return true; + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals) { + for (short val : vals) { + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void add(short[] vals, int offset, int length) { + for (int i = 0; i < length; i++) { + short val = vals[offset + i]; + add(val); + } + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short value) { + TShortLinkedList tmp = new TShortLinkedList(); + tmp.add(value); + insert(offset, tmp); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values) { + insert(offset, link(values, 0, values.length)); + } + + /** {@inheritDoc} */ + @Override + public void insert(int offset, short[] values, int valOffset, int len) { + insert(offset, link(values, valOffset, len)); + } + + void insert(int offset, TShortLinkedList tmp) { + TShortLink l = getLinkAt(offset); + + size = size + tmp.size; + // + if (l == head) { + // Add in front + tmp.tail.setNext(head); + head.setPrevious(tmp.tail); + head = tmp.head; + + return; + } + + if (no(l)) { + if (size == 0) { + // New empty list + head = tmp.head; + tail = tmp.tail; + } else { + // append + tail.setNext(tmp.head); + tmp.head.setPrevious(tail); + tail = tmp.tail; + } + } else { + TShortLink prev = l.getPrevious(); + l.getPrevious().setNext(tmp.head); + + // Link by behind tmp + tmp.tail.setNext(l); + l.setPrevious(tmp.tail); + + tmp.head.setPrevious(prev); + } + } + + static TShortLinkedList link(short[] values, int valOffset, int len) { + TShortLinkedList ret = new TShortLinkedList(); + + for (int i = 0; i < len; i++) { + ret.add(values[valOffset + i]); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short get(int offset) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TShortLink l = getLinkAt(offset); + // + if (no(l)) + return no_entry_value; + + return l.getValue(); + } + + /** + * Returns the link at the given offset. + *

+ * A simple bisection criteria is used to keep the worst case complexity equal + * to O(n/2) where n = size(). Simply start from head of list or tail depending + * on offset and list size. + * + * @param offset + * of the link + * @return link or null if non-existent + */ + public TShortLink getLinkAt(int offset) { + if (offset >= size()) + return null; + + if (offset <= (size() >>> 1)) + return getLink(head, 0, offset, true); + else + return getLink(tail, size() - 1, offset, false); + } + + /** + * Returns the link at absolute offset starting from given the initial link 'l' + * at index 'idx' + * + * @param l + * @param idx + * @param offset + * @return + */ + private static TShortLink getLink(TShortLink l, int idx, int offset) { + return getLink(l, idx, offset, true); + } + + /** + * Returns link at given absolute offset starting from link 'l' at index 'idx' + * + * @param l + * @param idx + * @param offset + * @param next + * @return + */ + private static TShortLink getLink(TShortLink l, int idx, int offset, boolean next) { + int i = idx; + // + while (got(l)) { + if (i == offset) { + return l; + } + + i = i + (next ? 1 : -1); + l = next ? l.getNext() : l.getPrevious(); + } + + return null; + } + + /** {@inheritDoc} */ + @Override + public short set(int offset, short val) { + if (offset > size) + throw new IndexOutOfBoundsException("index " + offset + " exceeds size " + size); + + TShortLink l = getLinkAt(offset); + // + if (no(l)) + throw new IndexOutOfBoundsException("at offset " + offset); + + short prev = l.getValue(); + l.setValue(val); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values) { + set(offset, values, 0, values.length); + } + + /** {@inheritDoc} */ + @Override + public void set(int offset, short[] values, int valOffset, int length) { + for (int i = 0; i < length; i++) { + short value = values[valOffset + i]; + set(offset + i, value); + } + } + + /** {@inheritDoc} */ + @Override + public short replace(int offset, short val) { + return set(offset, val); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + size = 0; + // + head = null; + tail = null; + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short value) { + boolean changed = false; + for (TShortLink l = head; got(l); l = l.getNext()) { + // + if (l.getValue() == value) { + changed = true; + // + removeLink(l); + } + } + + return changed; + } + + /** + * unlinks the give TShortLink from the list + * + * @param l + */ + private void removeLink(TShortLink l) { + if (no(l)) + return; + + size--; + + TShortLink prev = l.getPrevious(); + TShortLink next = l.getNext(); + + if (got(prev)) { + prev.setNext(next); + } else { + // No previous we must be head + head = next; + } + + if (got(next)) { + next.setPrevious(prev); + } else { + // No next so me must be tail + tail = prev; + } + // Unlink + l.setNext(null); + l.setPrevious(null); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + if (isEmpty()) + return false; + + for (Object o : collection) { + if (o instanceof Short) { + Short i = (Short) o; + if (!(contains(i))) + return false; + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (isEmpty()) + return false; + + for (TShortIterator it = collection.iterator(); it.hasNext();) { + short i = it.next(); + if (!(contains(i))) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + if (isEmpty()) + return false; + + for (short i : array) { + if (!contains(i)) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean ret = false; + for (Short v : collection) { + if (add(v.shortValue())) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean ret = false; + for (TShortIterator it = collection.iterator(); it.hasNext();) { + short i = it.next(); + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean ret = false; + for (short i : array) { + if (add(i)) + ret = true; + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + Arrays.sort(array); + + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) < 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + Arrays.sort(array); + + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (Arrays.binarySearch(array, iter.next()) >= 0) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public short removeAt(int offset) { + TShortLink l = getLinkAt(offset); + if (no(l)) + throw new ArrayIndexOutOfBoundsException("no elemenet at " + offset); + + short prev = l.getValue(); + removeLink(l); + return prev; + } + + /** {@inheritDoc} */ + @Override + public void remove(int offset, int length) { + for (int i = 0; i < length; i++) { + removeAt(offset); // since the list shrinks we don't need to use offset+i to get the next entry ;) + } + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + for (TShortLink l = head; got(l);) { + // + l.setValue(function.execute(l.getValue())); + // + l = l.getNext(); + } + } + + /** {@inheritDoc} */ + @Override + public void reverse() { + TShortLink h = head; + TShortLink t = tail; + TShortLink prev, next, tmp; + + // + TShortLink l = head; + while (got(l)) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // + head = t; + tail = h; + } + + /** {@inheritDoc} */ + @Override + public void reverse(int from, int to) { + if (from > to) + throw new IllegalArgumentException("from > to : " + from + ">" + to); + + TShortLink start = getLinkAt(from); + TShortLink stop = getLinkAt(to); + TShortLink prev, next; + TShortLink tmp = null; + + TShortLink tmpHead = start.getPrevious(); + + // + TShortLink l = start; + while (l != stop) { + next = l.getNext(); + prev = l.getPrevious(); + // + tmp = l; + l = l.getNext(); + // + tmp.setNext(prev); + tmp.setPrevious(next); + } + + // At this point l == stop and tmp is the but last element { + if (got(tmp)) { + tmpHead.setNext(tmp); + stop.setPrevious(tmpHead); + } + start.setNext(stop); + stop.setPrevious(start); + } + + /** {@inheritDoc} */ + @Override + public void shuffle(Random rand) { + for (int i = 0; i < size; i++) { + TShortLink l = getLinkAt(rand.nextInt(size())); + removeLink(l); + add(l.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public TShortList subList(int begin, int end) { + if (end < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than end index " + end); + } + if (size < begin) { + throw new IllegalArgumentException("begin index " + begin + " greater than last index " + size); + } + if (begin < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + if (end > size) { + throw new IndexOutOfBoundsException("end index < " + size); + } + + TShortLinkedList ret = new TShortLinkedList(); + TShortLink tmp = getLinkAt(begin); + for (int i = begin; i < end; i++) { + ret.add(tmp.getValue()); // copy + tmp = tmp.getNext(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return toArray(new short[size], 0, size); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(int offset, int len) { + return toArray(new short[len], offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return toArray(dest, 0, size); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int offset, int len) { + return toArray(dest, offset, 0, len); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest, int source_pos, int dest_pos, int len) { + if (len == 0) { + return dest; // nothing to copy + } + if (source_pos < 0 || source_pos >= size()) { + throw new ArrayIndexOutOfBoundsException(source_pos); + } + + TShortLink tmp = getLinkAt(source_pos); + for (int i = 0; i < len; i++) { + dest[dest_pos + i] = tmp.getValue(); // copy + tmp = tmp.getNext(); + } + + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + for (TShortLink l = head; got(l); l = l.getNext()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachDescending(TShortProcedure procedure) { + for (TShortLink l = tail; got(l); l = l.getPrevious()) { + if (!procedure.execute(l.getValue())) + return false; + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void sort() { + sort(0, size); + } + + /** {@inheritDoc} */ + @Override + public void sort(int fromIndex, int toIndex) { + TShortList tmp = subList(fromIndex, toIndex); + short[] vals = tmp.toArray(); + Arrays.sort(vals); + set(fromIndex, vals); + } + + /** {@inheritDoc} */ + @Override + public void fill(short val) { + fill(0, size, val); + } + + /** {@inheritDoc} */ + @Override + public void fill(int fromIndex, int toIndex, short val) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + TShortLink l = getLinkAt(fromIndex); + if (toIndex > size) { + for (int i = fromIndex; i < size; i++) { + l.setValue(val); + l = l.getNext(); + } + for (int i = size; i < toIndex; i++) { + add(val); + } + } else { + for (int i = fromIndex; i < toIndex; i++) { + l.setValue(val); + l = l.getNext(); + } + } + + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value) { + return binarySearch(value, 0, size()); + } + + /** {@inheritDoc} */ + @Override + public int binarySearch(short value, int fromIndex, int toIndex) { + if (fromIndex < 0) { + throw new IndexOutOfBoundsException("begin index can not be < 0"); + } + + if (toIndex > size) { + throw new IndexOutOfBoundsException("end index > size: " + toIndex + " > " + size); + } + + if (toIndex < fromIndex) { + return -(fromIndex + 1); + } + + TShortLink middle; + int mid; + int from = fromIndex; + TShortLink fromLink = getLinkAt(fromIndex); + int to = toIndex; + + while (from < to) { + mid = (from + to) >>> 1; + middle = getLink(fromLink, from, mid); + if (middle.getValue() == value) + return mid; + + if (middle.getValue() < value) { + from = mid + 1; + fromLink = middle.next; + } else { + to = mid - 1; + } + } + + return -(from + 1); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(short value) { + return indexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int indexOf(int offset, short value) { + int count = offset; + + TShortLink l; + for (l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + return count; + + count++; + } + + if (l != null && l.getValue() == value) + return count; + + return -1; + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(short value) { + return lastIndexOf(0, value); + } + + /** {@inheritDoc} */ + @Override + public int lastIndexOf(int offset, short value) { + if (isEmpty()) + return -1; + + int last = -1; + int count = offset; + for (TShortLink l = getLinkAt(offset); got(l.getNext()); l = l.getNext()) { + if (l.getValue() == value) + last = count; + + count++; + } + + return last; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short value) { + if (isEmpty()) + return false; + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (l.getValue() == value) + return true; + } + return false; + + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortIterator() { + TShortLink l = head; + TShortLink current; + + @Override + public short next() { + if (no(l)) + throw new NoSuchElementException(); + + short ret = l.getValue(); + current = l; + l = l.getNext(); + + return ret; + } + + @Override + public boolean hasNext() { + return got(l); + } + + @Override + public void remove() { + if (current == null) + throw new IllegalStateException(); + + removeLink(current); + current = null; + } + }; + } + + /** {@inheritDoc} */ + @Override + public TShortList grep(TShortProcedure condition) { + TShortList ret = new TShortLinkedList(); + for (TShortLink l = head; got(l); l = l.getNext()) { + if (condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public TShortList inverseGrep(TShortProcedure condition) { + TShortList ret = new TShortLinkedList(); + for (TShortLink l = head; got(l); l = l.getNext()) { + if (!condition.execute(l.getValue())) + ret.add(l.getValue()); + } + return ret; + } + + /** {@inheritDoc} */ + @Override + public short max() { + short ret = Short.MIN_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (ret < l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short min() { + short ret = Short.MAX_VALUE; + + if (isEmpty()) + throw new IllegalStateException(); + + for (TShortLink l = head; got(l); l = l.getNext()) { + if (ret > l.getValue()) + ret = l.getValue(); + } + + return ret; + } + + /** {@inheritDoc} */ + @Override + public short sum() { + short sum = 0; + + for (TShortLink l = head; got(l); l = l.getNext()) { + sum += l.getValue(); + } + + return sum; + } + + // + // + // + static class TShortLink { + short value; + TShortLink previous; + TShortLink next; + + TShortLink(short value) { + this.value = value; + } + + public short getValue() { + return value; + } + + public void setValue(short value) { + this.value = value; + } + + public TShortLink getPrevious() { + return previous; + } + + public void setPrevious(TShortLink previous) { + this.previous = previous; + } + + public TShortLink getNext() { + return next; + } + + public void setNext(TShortLink next) { + this.next = next; + } + } + + class RemoveProcedure implements TShortProcedure { + boolean changed = false; + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(short value) { + if (remove(value)) + changed = true; + + return true; + } + + public boolean isChanged() { + return changed; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // ENTRIES + out.writeInt(size); + for (TShortIterator iterator = iterator(); iterator.hasNext();) { + short next = iterator.next(); + out.writeShort(next); + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // ENTRIES + int len = in.readInt(); + for (int i = 0; i < len; i++) { + add(in.readShort()); + } + } + + static boolean got(Object ref) { + return ref != null; + } + + static boolean no(Object ref) { + return ref == null; + } + + // comparing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if (!(other instanceof TShortList)) + return false; + + TShortList that = (TShortList) other; + if (size() != that.size()) + return false; + + for (int i = 0; i < size(); i++) { + if (get(i) != that.get(i)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int h = 0; + for (int i = size(); i-- > 0;) { + h += HashFunctions.hash(get(i)); + } + return h; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + TShortIterator it = iterator(); + while (it.hasNext()) { + short next = it.next(); + buf.append(next); + if (it.hasNext()) + buf.append(", "); + } + buf.append("}"); + return buf.toString(); + + } +} // TShortLinkedList diff --git a/src/gnu/trove/map/TByteByteMap.java b/src/gnu/trove/map/TByteByteMap.java new file mode 100644 index 0000000..cdfcc43 --- /dev/null +++ b/src/gnu/trove/map/TByteByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and byte values. + */ +public interface TByteByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(byte key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(byte key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteByteIterator with access to this map's keys and values + */ + public TByteByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TByteCharMap.java b/src/gnu/trove/map/TByteCharMap.java new file mode 100644 index 0000000..4cdce9a --- /dev/null +++ b/src/gnu/trove/map/TByteCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and char values. + */ +public interface TByteCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(byte key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(byte key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteCharIterator with access to this map's keys and values + */ + public TByteCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TByteDoubleMap.java b/src/gnu/trove/map/TByteDoubleMap.java new file mode 100644 index 0000000..230d819 --- /dev/null +++ b/src/gnu/trove/map/TByteDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and double values. + */ +public interface TByteDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(byte key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(byte key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteDoubleIterator with access to this map's keys and values + */ + public TByteDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TByteFloatMap.java b/src/gnu/trove/map/TByteFloatMap.java new file mode 100644 index 0000000..d380b02 --- /dev/null +++ b/src/gnu/trove/map/TByteFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and float values. + */ +public interface TByteFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(byte key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(byte key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteFloatIterator with access to this map's keys and values + */ + public TByteFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TByteIntMap.java b/src/gnu/trove/map/TByteIntMap.java new file mode 100644 index 0000000..c07d90c --- /dev/null +++ b/src/gnu/trove/map/TByteIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and int values. + */ +public interface TByteIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(byte key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(byte key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteIntIterator with access to this map's keys and values + */ + public TByteIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TByteLongMap.java b/src/gnu/trove/map/TByteLongMap.java new file mode 100644 index 0000000..0a3b375 --- /dev/null +++ b/src/gnu/trove/map/TByteLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and long values. + */ +public interface TByteLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(byte key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(byte key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteLongIterator with access to this map's keys and values + */ + public TByteLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TByteObjectMap.java b/src/gnu/trove/map/TByteObjectMap.java new file mode 100644 index 0000000..4078da4 --- /dev/null +++ b/src/gnu/trove/map/TByteObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TByteObjectIterator; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TByteSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of byte keys and Object values. + */ +public interface TByteObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + byte getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(byte key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the byte value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(byte key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(byte) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(byte key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(byte key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous byte value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(byte key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(byte,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TByteObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TByteSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TByteSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + byte[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + byte[] keys(byte[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of byte values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of byte values. + */ + V[] values(V[] array); + + /** + * Returns a TByteObjectIterator with access to this map's keys and + * values. + * + * @return a TByteObjectIterator with access to this map's keys and + * values. + */ + public TByteObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TByteObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TByteShortMap.java b/src/gnu/trove/map/TByteShortMap.java new file mode 100644 index 0000000..7a14b11 --- /dev/null +++ b/src/gnu/trove/map/TByteShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of byte keys and short values. + */ +public interface TByteShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public byte getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an byte value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(byte key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an byte value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(byte key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TByteShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(byte key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(byte key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TByteSet + * + * @return the keys of the map as a TByteSet + */ + public TByteSet keySet(); + + /** + * Returns the keys of the map as an array of byte values. + * + * @return the keys of the map as an array of byte values. + */ + public byte[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public byte[] keys(byte[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an byte value + * @return a boolean value + */ + public boolean containsKey(byte key); + + /** + * @return a TByteShortIterator with access to this map's keys and values + */ + public TByteShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TByteProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOByteShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TByteShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TByteShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(byte key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(byte key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TCharByteMap.java b/src/gnu/trove/map/TCharByteMap.java new file mode 100644 index 0000000..624848c --- /dev/null +++ b/src/gnu/trove/map/TCharByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and byte values. + */ +public interface TCharByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(char key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(char key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharByteIterator with access to this map's keys and values + */ + public TCharByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TCharCharMap.java b/src/gnu/trove/map/TCharCharMap.java new file mode 100644 index 0000000..4612451 --- /dev/null +++ b/src/gnu/trove/map/TCharCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and char values. + */ +public interface TCharCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(char key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(char key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharCharIterator with access to this map's keys and values + */ + public TCharCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(char key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TCharDoubleMap.java b/src/gnu/trove/map/TCharDoubleMap.java new file mode 100644 index 0000000..cac4b6c --- /dev/null +++ b/src/gnu/trove/map/TCharDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and double values. + */ +public interface TCharDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(char key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(char key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharDoubleIterator with access to this map's keys and values + */ + public TCharDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(char key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TCharFloatMap.java b/src/gnu/trove/map/TCharFloatMap.java new file mode 100644 index 0000000..f491469 --- /dev/null +++ b/src/gnu/trove/map/TCharFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and float values. + */ +public interface TCharFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(char key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(char key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharFloatIterator with access to this map's keys and values + */ + public TCharFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(char key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TCharIntMap.java b/src/gnu/trove/map/TCharIntMap.java new file mode 100644 index 0000000..2534f5c --- /dev/null +++ b/src/gnu/trove/map/TCharIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and int values. + */ +public interface TCharIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(char key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(char key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharIntIterator with access to this map's keys and values + */ + public TCharIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(char key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TCharLongMap.java b/src/gnu/trove/map/TCharLongMap.java new file mode 100644 index 0000000..4603e7d --- /dev/null +++ b/src/gnu/trove/map/TCharLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and long values. + */ +public interface TCharLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(char key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(char key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharLongIterator with access to this map's keys and values + */ + public TCharLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(char key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TCharObjectMap.java b/src/gnu/trove/map/TCharObjectMap.java new file mode 100644 index 0000000..22353a0 --- /dev/null +++ b/src/gnu/trove/map/TCharObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TCharObjectIterator; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TCharSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of char keys and Object values. + */ +public interface TCharObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + char getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(char key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the char value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(char key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(char) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(char key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(char key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous char value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(char key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(char,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TCharObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TCharSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TCharSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + char[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + char[] keys(char[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of char values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of char values. + */ + V[] values(V[] array); + + /** + * Returns a TCharObjectIterator with access to this map's keys and + * values. + * + * @return a TCharObjectIterator with access to this map's keys and + * values. + */ + public TCharObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TCharObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TCharShortMap.java b/src/gnu/trove/map/TCharShortMap.java new file mode 100644 index 0000000..076a8cd --- /dev/null +++ b/src/gnu/trove/map/TCharShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of char keys and short values. + */ +public interface TCharShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public char getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an char value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(char key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an char value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(char key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TCharShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(char key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(char key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TCharSet + * + * @return the keys of the map as a TCharSet + */ + public TCharSet keySet(); + + /** + * Returns the keys of the map as an array of char values. + * + * @return the keys of the map as an array of char values. + */ + public char[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public char[] keys(char[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an char value + * @return a boolean value + */ + public boolean containsKey(char key); + + /** + * @return a TCharShortIterator with access to this map's keys and values + */ + public TCharShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TCharProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOCharShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TCharShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TCharShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(char key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(char key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(char key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TDoubleByteMap.java b/src/gnu/trove/map/TDoubleByteMap.java new file mode 100644 index 0000000..0f5340e --- /dev/null +++ b/src/gnu/trove/map/TDoubleByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and byte values. + */ +public interface TDoubleByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(double key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(double key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleByteIterator with access to this map's keys and values + */ + public TDoubleByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TDoubleCharMap.java b/src/gnu/trove/map/TDoubleCharMap.java new file mode 100644 index 0000000..7937332 --- /dev/null +++ b/src/gnu/trove/map/TDoubleCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and char values. + */ +public interface TDoubleCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(double key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(double key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleCharIterator with access to this map's keys and values + */ + public TDoubleCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(double key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TDoubleDoubleMap.java b/src/gnu/trove/map/TDoubleDoubleMap.java new file mode 100644 index 0000000..c719e0d --- /dev/null +++ b/src/gnu/trove/map/TDoubleDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and double values. + */ +public interface TDoubleDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(double key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(double key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleDoubleIterator with access to this map's keys and values + */ + public TDoubleDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(double key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TDoubleFloatMap.java b/src/gnu/trove/map/TDoubleFloatMap.java new file mode 100644 index 0000000..9526956 --- /dev/null +++ b/src/gnu/trove/map/TDoubleFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and float values. + */ +public interface TDoubleFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(double key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(double key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleFloatIterator with access to this map's keys and values + */ + public TDoubleFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(double key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TDoubleIntMap.java b/src/gnu/trove/map/TDoubleIntMap.java new file mode 100644 index 0000000..55e0a69 --- /dev/null +++ b/src/gnu/trove/map/TDoubleIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and int values. + */ +public interface TDoubleIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(double key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(double key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleIntIterator with access to this map's keys and values + */ + public TDoubleIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(double key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TDoubleLongMap.java b/src/gnu/trove/map/TDoubleLongMap.java new file mode 100644 index 0000000..9cd9cb0 --- /dev/null +++ b/src/gnu/trove/map/TDoubleLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and long values. + */ +public interface TDoubleLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(double key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(double key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleLongIterator with access to this map's keys and values + */ + public TDoubleLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(double key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TDoubleObjectMap.java b/src/gnu/trove/map/TDoubleObjectMap.java new file mode 100644 index 0000000..1b68a00 --- /dev/null +++ b/src/gnu/trove/map/TDoubleObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TDoubleObjectIterator; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TDoubleSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of double keys and Object values. + */ +public interface TDoubleObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + double getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(double key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the double value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(double key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(double) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(double key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(double key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous double value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(double key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(double,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TDoubleObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TDoubleSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TDoubleSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + double[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + double[] keys(double[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of double values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of double values. + */ + V[] values(V[] array); + + /** + * Returns a TDoubleObjectIterator with access to this map's keys and + * values. + * + * @return a TDoubleObjectIterator with access to this map's keys and + * values. + */ + public TDoubleObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TDoubleObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TDoubleShortMap.java b/src/gnu/trove/map/TDoubleShortMap.java new file mode 100644 index 0000000..8a390d4 --- /dev/null +++ b/src/gnu/trove/map/TDoubleShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of double keys and short values. + */ +public interface TDoubleShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public double getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an double value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(double key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an double value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(double key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TDoubleShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(double key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(double key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TDoubleSet + * + * @return the keys of the map as a TDoubleSet + */ + public TDoubleSet keySet(); + + /** + * Returns the keys of the map as an array of double values. + * + * @return the keys of the map as an array of double values. + */ + public double[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public double[] keys(double[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an double value + * @return a boolean value + */ + public boolean containsKey(double key); + + /** + * @return a TDoubleShortIterator with access to this map's keys and values + */ + public TDoubleShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TDoubleProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TODoubleShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TDoubleShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TDoubleShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(double key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(double key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(double key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TFloatByteMap.java b/src/gnu/trove/map/TFloatByteMap.java new file mode 100644 index 0000000..3b2d4d3 --- /dev/null +++ b/src/gnu/trove/map/TFloatByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and byte values. + */ +public interface TFloatByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(float key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(float key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatByteIterator with access to this map's keys and values + */ + public TFloatByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TFloatCharMap.java b/src/gnu/trove/map/TFloatCharMap.java new file mode 100644 index 0000000..7e783bf --- /dev/null +++ b/src/gnu/trove/map/TFloatCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and char values. + */ +public interface TFloatCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(float key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(float key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatCharIterator with access to this map's keys and values + */ + public TFloatCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(float key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TFloatDoubleMap.java b/src/gnu/trove/map/TFloatDoubleMap.java new file mode 100644 index 0000000..f0bc608 --- /dev/null +++ b/src/gnu/trove/map/TFloatDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and double values. + */ +public interface TFloatDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(float key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(float key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatDoubleIterator with access to this map's keys and values + */ + public TFloatDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(float key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TFloatFloatMap.java b/src/gnu/trove/map/TFloatFloatMap.java new file mode 100644 index 0000000..c3e6948 --- /dev/null +++ b/src/gnu/trove/map/TFloatFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and float values. + */ +public interface TFloatFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(float key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(float key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatFloatIterator with access to this map's keys and values + */ + public TFloatFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(float key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TFloatIntMap.java b/src/gnu/trove/map/TFloatIntMap.java new file mode 100644 index 0000000..1629996 --- /dev/null +++ b/src/gnu/trove/map/TFloatIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and int values. + */ +public interface TFloatIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(float key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(float key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatIntIterator with access to this map's keys and values + */ + public TFloatIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(float key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TFloatLongMap.java b/src/gnu/trove/map/TFloatLongMap.java new file mode 100644 index 0000000..a13acbe --- /dev/null +++ b/src/gnu/trove/map/TFloatLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and long values. + */ +public interface TFloatLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(float key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(float key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatLongIterator with access to this map's keys and values + */ + public TFloatLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(float key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TFloatObjectMap.java b/src/gnu/trove/map/TFloatObjectMap.java new file mode 100644 index 0000000..d235735 --- /dev/null +++ b/src/gnu/trove/map/TFloatObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TFloatObjectIterator; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TFloatSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of float keys and Object values. + */ +public interface TFloatObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + float getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(float key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the float value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(float key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(float) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(float key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(float key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous float value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(float key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(float,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TFloatObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TFloatSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TFloatSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + float[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + float[] keys(float[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of float values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of float values. + */ + V[] values(V[] array); + + /** + * Returns a TFloatObjectIterator with access to this map's keys and + * values. + * + * @return a TFloatObjectIterator with access to this map's keys and + * values. + */ + public TFloatObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TFloatObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TFloatShortMap.java b/src/gnu/trove/map/TFloatShortMap.java new file mode 100644 index 0000000..b00b99d --- /dev/null +++ b/src/gnu/trove/map/TFloatShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of float keys and short values. + */ +public interface TFloatShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public float getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an float value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(float key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an float value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(float key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TFloatShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(float key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(float key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TFloatSet + * + * @return the keys of the map as a TFloatSet + */ + public TFloatSet keySet(); + + /** + * Returns the keys of the map as an array of float values. + * + * @return the keys of the map as an array of float values. + */ + public float[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public float[] keys(float[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an float value + * @return a boolean value + */ + public boolean containsKey(float key); + + /** + * @return a TFloatShortIterator with access to this map's keys and values + */ + public TFloatShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TFloatProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOFloatShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TFloatShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TFloatShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(float key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(float key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(float key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TIntByteMap.java b/src/gnu/trove/map/TIntByteMap.java new file mode 100644 index 0000000..2bd9d36 --- /dev/null +++ b/src/gnu/trove/map/TIntByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and byte values. + */ +public interface TIntByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(int key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(int key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntByteIterator with access to this map's keys and values + */ + public TIntByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TIntCharMap.java b/src/gnu/trove/map/TIntCharMap.java new file mode 100644 index 0000000..bb3dbdc --- /dev/null +++ b/src/gnu/trove/map/TIntCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and char values. + */ +public interface TIntCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(int key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(int key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntCharIterator with access to this map's keys and values + */ + public TIntCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(int key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TIntDoubleMap.java b/src/gnu/trove/map/TIntDoubleMap.java new file mode 100644 index 0000000..59acee6 --- /dev/null +++ b/src/gnu/trove/map/TIntDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and double values. + */ +public interface TIntDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(int key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(int key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntDoubleIterator with access to this map's keys and values + */ + public TIntDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(int key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TIntFloatMap.java b/src/gnu/trove/map/TIntFloatMap.java new file mode 100644 index 0000000..1dccd8d --- /dev/null +++ b/src/gnu/trove/map/TIntFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and float values. + */ +public interface TIntFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(int key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(int key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntFloatIterator with access to this map's keys and values + */ + public TIntFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(int key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TIntIntMap.java b/src/gnu/trove/map/TIntIntMap.java new file mode 100644 index 0000000..cb0f1f9 --- /dev/null +++ b/src/gnu/trove/map/TIntIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and int values. + */ +public interface TIntIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(int key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(int key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntIntIterator with access to this map's keys and values + */ + public TIntIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(int key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TIntLongMap.java b/src/gnu/trove/map/TIntLongMap.java new file mode 100644 index 0000000..01f81d6 --- /dev/null +++ b/src/gnu/trove/map/TIntLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and long values. + */ +public interface TIntLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(int key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(int key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntLongIterator with access to this map's keys and values + */ + public TIntLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(int key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TIntObjectMap.java b/src/gnu/trove/map/TIntObjectMap.java new file mode 100644 index 0000000..e382867 --- /dev/null +++ b/src/gnu/trove/map/TIntObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TIntObjectIterator; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TIntSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of int keys and Object values. + */ +public interface TIntObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + int getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(int key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the int value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(int key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(int) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(int key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(int key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous int value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(int key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(int,Object) put(k, v)} on this map once for each mapping from key + * k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TIntObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TIntSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TIntSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + int[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + int[] keys(int[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of int values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of int values. + */ + V[] values(V[] array); + + /** + * Returns a TIntObjectIterator with access to this map's keys and + * values. + * + * @return a TIntObjectIterator with access to this map's keys and + * values. + */ + public TIntObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TIntObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TIntShortMap.java b/src/gnu/trove/map/TIntShortMap.java new file mode 100644 index 0000000..4b7f20b --- /dev/null +++ b/src/gnu/trove/map/TIntShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of int keys and short values. + */ +public interface TIntShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public int getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an int value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(int key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an int value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(int key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TIntShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(int key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(int key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TIntSet + * + * @return the keys of the map as a TIntSet + */ + public TIntSet keySet(); + + /** + * Returns the keys of the map as an array of int values. + * + * @return the keys of the map as an array of int values. + */ + public int[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public int[] keys(int[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an int value + * @return a boolean value + */ + public boolean containsKey(int key); + + /** + * @return a TIntShortIterator with access to this map's keys and values + */ + public TIntShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TIntProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOIntShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TIntShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TIntShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(int key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(int key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(int key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TLongByteMap.java b/src/gnu/trove/map/TLongByteMap.java new file mode 100644 index 0000000..ac0fee2 --- /dev/null +++ b/src/gnu/trove/map/TLongByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and byte values. + */ +public interface TLongByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(long key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(long key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongByteIterator with access to this map's keys and values + */ + public TLongByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TLongCharMap.java b/src/gnu/trove/map/TLongCharMap.java new file mode 100644 index 0000000..840fbfe --- /dev/null +++ b/src/gnu/trove/map/TLongCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and char values. + */ +public interface TLongCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(long key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(long key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongCharIterator with access to this map's keys and values + */ + public TLongCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(long key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TLongDoubleMap.java b/src/gnu/trove/map/TLongDoubleMap.java new file mode 100644 index 0000000..aa7d10f --- /dev/null +++ b/src/gnu/trove/map/TLongDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and double values. + */ +public interface TLongDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(long key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(long key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongDoubleIterator with access to this map's keys and values + */ + public TLongDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(long key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TLongFloatMap.java b/src/gnu/trove/map/TLongFloatMap.java new file mode 100644 index 0000000..89726cf --- /dev/null +++ b/src/gnu/trove/map/TLongFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and float values. + */ +public interface TLongFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(long key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(long key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongFloatIterator with access to this map's keys and values + */ + public TLongFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(long key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TLongIntMap.java b/src/gnu/trove/map/TLongIntMap.java new file mode 100644 index 0000000..6fa4db5 --- /dev/null +++ b/src/gnu/trove/map/TLongIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and int values. + */ +public interface TLongIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(long key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(long key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongIntIterator with access to this map's keys and values + */ + public TLongIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(long key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TLongLongMap.java b/src/gnu/trove/map/TLongLongMap.java new file mode 100644 index 0000000..3bc107a --- /dev/null +++ b/src/gnu/trove/map/TLongLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and long values. + */ +public interface TLongLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(long key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(long key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongLongIterator with access to this map's keys and values + */ + public TLongLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(long key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TLongObjectMap.java b/src/gnu/trove/map/TLongObjectMap.java new file mode 100644 index 0000000..d2e23f5 --- /dev/null +++ b/src/gnu/trove/map/TLongObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TLongObjectIterator; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TLongSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of long keys and Object values. + */ +public interface TLongObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + long getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(long key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the long value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(long key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(long) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(long key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(long key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous long value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(long key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(long,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TLongObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TLongSet} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TLongSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + long[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + long[] keys(long[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of long values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of long values. + */ + V[] values(V[] array); + + /** + * Returns a TLongObjectIterator with access to this map's keys and + * values. + * + * @return a TLongObjectIterator with access to this map's keys and + * values. + */ + public TLongObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TLongObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TLongShortMap.java b/src/gnu/trove/map/TLongShortMap.java new file mode 100644 index 0000000..e5af795 --- /dev/null +++ b/src/gnu/trove/map/TLongShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of long keys and short values. + */ +public interface TLongShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public long getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an long value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(long key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an long value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(long key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TLongShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(long key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(long key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TLongSet + * + * @return the keys of the map as a TLongSet + */ + public TLongSet keySet(); + + /** + * Returns the keys of the map as an array of long values. + * + * @return the keys of the map as an array of long values. + */ + public long[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public long[] keys(long[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an long value + * @return a boolean value + */ + public boolean containsKey(long key); + + /** + * @return a TLongShortIterator with access to this map's keys and values + */ + public TLongShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TLongProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOLongShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TLongShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TLongShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(long key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(long key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(long key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/TMap.java b/src/gnu/trove/map/TMap.java new file mode 100644 index 0000000..10f7823 --- /dev/null +++ b/src/gnu/trove/map/TMap.java @@ -0,0 +1,95 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2011, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.util.Map; + +/** + * Interface extension to {@link Map} which adds Trove-specific features. + */ +public interface TMap extends Map { + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); +} diff --git a/src/gnu/trove/map/TObjectByteMap.java b/src/gnu/trove/map/TObjectByteMap.java new file mode 100644 index 0000000..a3fafde --- /dev/null +++ b/src/gnu/trove/map/TObjectByteMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TByteCollection; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.iterator.TObjectByteIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and byte values. + */ +public interface TObjectByteMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + byte getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * byte value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(byte value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the byte value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + byte get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + byte put(K key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an byte value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + byte putIfAbsent(K key, byte value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous byte value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + byte remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,byte) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectByteMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TByteCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TByteIterator.remove, + * TByteCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of byte values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of byte values. + */ + byte[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of byte values. + */ + byte[] values(byte[] array); + + /** + * Returns a TObjectByteIterator with access to this map's keys and + * values. + * + * @return a TObjectByteIterator with access to this map's keys and + * values. + */ + public TObjectByteIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(K key, byte adjust_amount, byte put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectCharMap.java b/src/gnu/trove/map/TObjectCharMap.java new file mode 100644 index 0000000..5fe17cf --- /dev/null +++ b/src/gnu/trove/map/TObjectCharMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TCharCollection; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.iterator.TObjectCharIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and char values. + */ +public interface TObjectCharMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + char getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * char value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(char value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the char value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + char get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + char put(K key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an char value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + char putIfAbsent(K key, char value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous char value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + char remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,char) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectCharMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TCharCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TCharIterator.remove, + * TCharCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of char values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of char values. + */ + char[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of char values. + */ + char[] values(char[] array); + + /** + * Returns a TObjectCharIterator with access to this map's keys and + * values. + * + * @return a TObjectCharIterator with access to this map's keys and + * values. + */ + public TObjectCharIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(K key, char adjust_amount, char put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectDoubleMap.java b/src/gnu/trove/map/TObjectDoubleMap.java new file mode 100644 index 0000000..fc1ce5b --- /dev/null +++ b/src/gnu/trove/map/TObjectDoubleMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TDoubleCollection; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.iterator.TObjectDoubleIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and double values. + */ +public interface TObjectDoubleMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + double getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * double value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(double value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the double value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + double get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + double put(K key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an double value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + double putIfAbsent(K key, double value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous double value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + double remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,double) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectDoubleMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TDoubleCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TDoubleIterator.remove, + * TDoubleCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of double values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of double values. + */ + double[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of double values. + */ + double[] values(double[] array); + + /** + * Returns a TObjectDoubleIterator with access to this map's keys and + * values. + * + * @return a TObjectDoubleIterator with access to this map's keys and + * values. + */ + public TObjectDoubleIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(K key, double adjust_amount, double put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectFloatMap.java b/src/gnu/trove/map/TObjectFloatMap.java new file mode 100644 index 0000000..d55c068 --- /dev/null +++ b/src/gnu/trove/map/TObjectFloatMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TFloatCollection; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.iterator.TObjectFloatIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and float values. + */ +public interface TObjectFloatMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + float getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * float value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(float value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the float value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + float get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + float put(K key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an float value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + float putIfAbsent(K key, float value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous float value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + float remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,float) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectFloatMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TFloatCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TFloatIterator.remove, + * TFloatCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of float values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of float values. + */ + float[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of float values. + */ + float[] values(float[] array); + + /** + * Returns a TObjectFloatIterator with access to this map's keys and + * values. + * + * @return a TObjectFloatIterator with access to this map's keys and + * values. + */ + public TObjectFloatIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(K key, float adjust_amount, float put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectIntMap.java b/src/gnu/trove/map/TObjectIntMap.java new file mode 100644 index 0000000..a796830 --- /dev/null +++ b/src/gnu/trove/map/TObjectIntMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TIntCollection; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.iterator.TObjectIntIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and int values. + */ +public interface TObjectIntMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + int getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * int value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(int value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the int value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + int get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + int put(K key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an int value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + int putIfAbsent(K key, int value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous int value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + int remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,int) put(k, v)} on this map once for each mapping from key + * k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectIntMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TIntCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TIntIterator.remove, + * TIntCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of int values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of int values. + */ + int[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of int values. + */ + int[] values(int[] array); + + /** + * Returns a TObjectIntIterator with access to this map's keys and + * values. + * + * @return a TObjectIntIterator with access to this map's keys and + * values. + */ + public TObjectIntIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(K key, int adjust_amount, int put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectLongMap.java b/src/gnu/trove/map/TObjectLongMap.java new file mode 100644 index 0000000..df3d5d5 --- /dev/null +++ b/src/gnu/trove/map/TObjectLongMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TLongCollection; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.iterator.TObjectLongIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and long values. + */ +public interface TObjectLongMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + long getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * long value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(long value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the long value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + long get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + long put(K key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an long value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + long putIfAbsent(K key, long value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous long value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + long remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,long) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectLongMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TLongCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TLongIterator.remove, + * TLongCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of long values. Changes to + * the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of long values. + */ + long[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of long values. + */ + long[] values(long[] array); + + /** + * Returns a TObjectLongIterator with access to this map's keys and + * values. + * + * @return a TObjectLongIterator with access to this map's keys and + * values. + */ + public TObjectLongIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(K key, long adjust_amount, long put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TObjectShortMap.java b/src/gnu/trove/map/TObjectShortMap.java new file mode 100644 index 0000000..7854985 --- /dev/null +++ b/src/gnu/trove/map/TObjectShortMap.java @@ -0,0 +1,462 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.TShortCollection; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.iterator.TObjectShortIterator; + +import java.util.Map; +import java.util.Set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of Object keys and short values. + */ +public interface TObjectShortMap { + + // Query Operations + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + short getNoEntryValue(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that + * (key==null ? k==null : key.equals(k)). (There can be at most one + * such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(Object key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==no_entry_value ? v==no_entry_value : value.equals(v)). This + * operation will probably require time linear in the map size for most + * implementations of the Map interface. + *

+ * Note that no_entry_value is the result of {@link #getNoEntryValue()} and + * represents null for this map instance. + * + * @param value + * short value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(short value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the short value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + short get(Object key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(Object) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryValue() + */ + short put(K key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value to be associated with the specified key + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + short putIfAbsent(K key, short value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that + * (key==null ? k==null : key.equals(k)), that mapping is removed. + * (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous short value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + short remove(Object key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(Object,short) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TObjectShortMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link Set} view of the keys contained in this map. The set is + * backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + Set keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + Object[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + K[] keys(K[] array); + + /** + * Returns a {@link TShortCollection} view of the values contained in this map. + * The collection is backed by the map, so changes to the map are reflected in + * the collection, and vice-versa. If the map is modified while an iteration + * over the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the TShortIterator.remove, + * TShortCollection.remove, removeAll, retainAll and + * clear operations. It does not support the add or + * addAll operations. + * + * @return a collection view of the values contained in this map + */ + TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of short values. Changes + * to the array of values will not be reflected in the map nor vice-versa. + * + * @return the values of the map as an array of short values. + */ + short[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of short values. + */ + short[] values(short[] array); + + /** + * Returns a TObjectShortIterator with access to this map's keys and + * values. + * + * @return a TObjectShortIterator with access to this map's keys and + * values. + */ + public TObjectShortIterator iterator(); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(K key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(K key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(K key, short adjust_amount, short put_amount); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TObjectProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TObjectShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TObjectShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TShortByteMap.java b/src/gnu/trove/map/TShortByteMap.java new file mode 100644 index 0000000..a260315 --- /dev/null +++ b/src/gnu/trove/map/TShortByteMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TByteCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and byte values. + */ +public interface TShortByteMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public byte getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte put(short key, byte value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an byte value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte putIfAbsent(short key, byte value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortByteMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public byte remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TByteCollection + * + * @return the values of the map as a TByteCollection + */ + public TByteCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public byte[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public byte[] values(byte[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an byte value + * @return a boolean value + */ + public boolean containsValue(byte val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortByteIterator with access to this map's keys and values + */ + public TShortByteIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TByteProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortByteProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + public void transformValues(TByteFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortByteProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, byte amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount); +} diff --git a/src/gnu/trove/map/TShortCharMap.java b/src/gnu/trove/map/TShortCharMap.java new file mode 100644 index 0000000..e483d40 --- /dev/null +++ b/src/gnu/trove/map/TShortCharMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TCharCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and char values. + */ +public interface TShortCharMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public char getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char put(short key, char value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an char value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char putIfAbsent(short key, char value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortCharMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public char remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TCharCollection + * + * @return the values of the map as a TCharCollection + */ + public TCharCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public char[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public char[] values(char[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an char value + * @return a boolean value + */ + public boolean containsValue(char val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortCharIterator with access to this map's keys and values + */ + public TShortCharIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TCharProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortCharProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + public void transformValues(TCharFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortCharProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, char amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public char adjustOrPutValue(short key, char adjust_amount, char put_amount); +} diff --git a/src/gnu/trove/map/TShortDoubleMap.java b/src/gnu/trove/map/TShortDoubleMap.java new file mode 100644 index 0000000..8355e11 --- /dev/null +++ b/src/gnu/trove/map/TShortDoubleMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TDoubleCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and double values. + */ +public interface TShortDoubleMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public double getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double put(short key, double value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an double value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double putIfAbsent(short key, double value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortDoubleMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public double remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TDoubleCollection + * + * @return the values of the map as a TDoubleCollection + */ + public TDoubleCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public double[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public double[] values(double[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an double value + * @return a boolean value + */ + public boolean containsValue(double val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortDoubleIterator with access to this map's keys and values + */ + public TShortDoubleIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TDoubleProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortDoubleProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + public void transformValues(TDoubleFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortDoubleProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, double amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public double adjustOrPutValue(short key, double adjust_amount, double put_amount); +} diff --git a/src/gnu/trove/map/TShortFloatMap.java b/src/gnu/trove/map/TShortFloatMap.java new file mode 100644 index 0000000..573316f --- /dev/null +++ b/src/gnu/trove/map/TShortFloatMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TFloatCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and float values. + */ +public interface TShortFloatMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public float getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float put(short key, float value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an float value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float putIfAbsent(short key, float value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortFloatMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public float remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TFloatCollection + * + * @return the values of the map as a TFloatCollection + */ + public TFloatCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public float[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public float[] values(float[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an float value + * @return a boolean value + */ + public boolean containsValue(float val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortFloatIterator with access to this map's keys and values + */ + public TShortFloatIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TFloatProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortFloatProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + public void transformValues(TFloatFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortFloatProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, float amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public float adjustOrPutValue(short key, float adjust_amount, float put_amount); +} diff --git a/src/gnu/trove/map/TShortIntMap.java b/src/gnu/trove/map/TShortIntMap.java new file mode 100644 index 0000000..5c089b5 --- /dev/null +++ b/src/gnu/trove/map/TShortIntMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TIntCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and int values. + */ +public interface TShortIntMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public int getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int put(short key, int value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an int value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int putIfAbsent(short key, int value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortIntMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public int remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TIntCollection + * + * @return the values of the map as a TIntCollection + */ + public TIntCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public int[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public int[] values(int[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an int value + * @return a boolean value + */ + public boolean containsValue(int val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortIntIterator with access to this map's keys and values + */ + public TShortIntIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TIntProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortIntProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + public void transformValues(TIntFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortIntProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, int amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public int adjustOrPutValue(short key, int adjust_amount, int put_amount); +} diff --git a/src/gnu/trove/map/TShortLongMap.java b/src/gnu/trove/map/TShortLongMap.java new file mode 100644 index 0000000..3c33309 --- /dev/null +++ b/src/gnu/trove/map/TShortLongMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TLongCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and long values. + */ +public interface TShortLongMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public long getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long put(short key, long value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an long value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long putIfAbsent(short key, long value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortLongMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public long remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TLongCollection + * + * @return the values of the map as a TLongCollection + */ + public TLongCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public long[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public long[] values(long[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an long value + * @return a boolean value + */ + public boolean containsValue(long val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortLongIterator with access to this map's keys and values + */ + public TShortLongIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TLongProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortLongProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + public void transformValues(TLongFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortLongProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, long amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public long adjustOrPutValue(short key, long adjust_amount, long put_amount); +} diff --git a/src/gnu/trove/map/TShortObjectMap.java b/src/gnu/trove/map/TShortObjectMap.java new file mode 100644 index 0000000..0830bef --- /dev/null +++ b/src/gnu/trove/map/TShortObjectMap.java @@ -0,0 +1,424 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +import gnu.trove.iterator.TShortObjectIterator; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortObjectProcedure; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TShortSet; + +import java.util.Collection; +import java.util.Map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for a primitive map of short keys and Object values. + */ +public interface TShortObjectMap { + + // Query Operations + + /** + * Returns the value that represents null in the {@link #keySet()}. The default + * value is generally zero, but can be changed during construction of the + * collection. + * + * @return the value that represents a null value in this collection. + */ + short getNoEntryKey(); + + /** + * Returns the number of key-value mappings in this map. If the map contains + * more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of key-value mappings in this map + */ + int size(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + boolean isEmpty(); + + /** + * Returns true if this map contains a mapping for the specified key. + * More formally, returns true if and only if this map contains a + * mapping for a key k such that key.equals(k). (There can be + * at most one such mapping.) + * + * @param key + * key whose presence in this map is to be tested + * @return true if this map contains a mapping for the specified key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + boolean containsKey(short key); + + /** + * Returns true if this map maps one or more keys to the specified + * value. More formally, returns true if and only if this map contains + * at least one mapping to a value v such that + * (value==null ? v==null : value.equals(v)). This operation will + * probably require time linear in the map size for most implementations of the + * Map interface. + * + * @param value + * value whose presence in this map is to be tested + * @return true if this map maps one or more keys to the specified + * value + * @throws ClassCastException + * if the value is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified value is null and this map does not permit null + * values (optional) + */ + boolean containsValue(Object value); + + /** + * Returns the value to which the specified key is mapped, or {@code null} if + * this map contains no mapping for the key. + * + *

+ * More formally, if this map contains a mapping from a key {@code k} to a value + * {@code v} such that {@code (key==null ? k==null : + * key.equals(k))}, then this method returns {@code v}; otherwise it returns + * {@code null}. (There can be at most one such mapping.) + * + *

+ * If this map permits null values, then a return value of {@code null} does not + * necessarily indicate that the map contains no mapping for the key; + * it's also possible that the map explicitly maps the key to {@code null}. The + * {@link #containsKey containsKey} operation may be used to distinguish these + * two cases. + * + * @param key + * the key whose associated value is to be returned + * @return the short value to which the specified key is mapped, or + * {@code null} if this map contains no mapping for the key + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V get(short key); + + // Modification Operations + + /** + * Associates the specified value with the specified key in this map (optional + * operation). If the map previously contained a mapping for the key, the old + * value is replaced by the specified value. (A map m is said to + * contain a mapping for a key k if and only if + * {@link #containsKey(short) m.containsKey(k)} would return true.) + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value value to be associated with the specified + * key + * @return the previous value associated with key, or + * no_entry_value if there was no mapping for key. (A + * no_entry_value return can also indicate that the map + * previously associated null with key, if the + * implementation supports null values.) + * @throws UnsupportedOperationException + * if the put operation is not supported by this map + * @throws ClassCastException + * if the class of the specified key or value prevents it from being + * stored in this map + * @throws NullPointerException + * if the specified key or value is null and this map does not + * permit null keys or values + * @throws IllegalArgumentException + * if some property of the specified key or value prevents it from + * being stored in this map + * @see #getNoEntryKey() + */ + V put(short key, V value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * key with which the specified value is to be associated + * @param value + * an short value to be associated with the specified key + * + * @return the previous value associated with key, or null if none was + * found. + */ + V putIfAbsent(short key, V value); + + /** + * Removes the mapping for a key from this map if it is present (optional + * operation). More formally, if this map contains a mapping from key k + * to value v such that key.equals(k), that mapping is + * removed. (The map can contain at most one such mapping.) + * + *

+ * Returns the value to which this map previously associated the key, or + * null if the map contained no mapping for the key. + * + *

+ * If this map permits null values, then a return value of null does + * not necessarily indicate that the map contained no mapping for the + * key; it's also possible that the map explicitly mapped the key to + * null. + * + *

+ * The map will not contain a mapping for the specified key once the call + * returns. + * + * @param key + * key whose mapping is to be removed from the map + * @return the previous short value associated with key, or + * null if there was no mapping for key. + * @throws UnsupportedOperationException + * if the remove operation is not supported by this map + * @throws ClassCastException + * if the key is of an inappropriate type for this map (optional) + * @throws NullPointerException + * if the specified key is null and this map does not permit null + * keys (optional) + */ + V remove(short key); + + // Bulk Operations + + /** + * Copies all of the mappings from the specified map to this map (optional + * operation). The effect of this call is equivalent to that of calling + * {@link #put(short,Object) put(k, v)} on this map once for each mapping from + * key k to value v in the specified map. The behavior of this + * operation is undefined if the specified map is modified while the operation + * is in progress. + * + * @param m + * mappings to be stored in this map + * @throws UnsupportedOperationException + * if the putAll operation is not supported by this map + * @throws ClassCastException + * if the class of a key or value in the specified map prevents it + * from being stored in this map + * @throws NullPointerException + * if the specified map is null, or if this map does not permit null + * keys or values, and the specified map contains null keys or + * values + * @throws IllegalArgumentException + * if some property of a key or value in the specified map prevents + * it from being stored in this map + */ + void putAll(Map m); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + void putAll(TShortObjectMap map); + + /** + * Removes all of the mappings from this map (optional operation). The map will + * be empty after this call returns. + * + * @throws UnsupportedOperationException + * if the clear operation is not supported by this map + */ + void clear(); + + // Views + + /** + * Returns a {@link TShortSet} view of the keys contained in this map. The set + * is backed by the map, so changes to the map are reflected in the set, and + * vice-versa. If the map is modified while an iteration over the set is in + * progress (except through the iterator's own remove operation), the + * results of the iteration are undefined. The set supports element removal, + * which removes the corresponding mapping from the map, via the + * Iterator.remove, Set.remove, removeAll, + * retainAll, and clear operations. It does not support the + * add or addAll operations. + * + * @return a set view of the keys contained in this map + */ + TShortSet keySet(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @return a copy of the keys of the map as an array. + */ + short[] keys(); + + /** + * Returns a copy of the keys of the map as an array. Changes to the array of + * keys will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + short[] keys(short[] array); + + /** + * Returns a {@link Collection} view of the values contained in this map. The + * collection is backed by the map, so changes to the map are reflected in the + * collection, and vice-versa. If the map is modified while an iteration over + * the collection is in progress (except through the iterator's own + * remove operation), the results of the iteration are undefined. The + * collection supports element removal, which removes the corresponding mapping + * from the map, via the Iterator.remove, Collection.remove, + * removeAll, retainAll and clear operations. It does + * not support the add or addAll operations. + * + * @return a collection view of the values contained in this map + */ + Collection valueCollection(); + + /** + * Returns the values of the map as an Object array. Note that the array + * returned is typed as an Object[] and may not be cast to a more specific type. + * See {@link #values(V[])} for a version which allows specifically typed + * arrays. Changes to the array of values will not be reflected in the map nor + * vice-versa. + * + * @return the values of the map as an array of short values. + */ + Object[] values(); + + /** + * Returns the values of the map using an existing array. Changes to the array + * of values will not be reflected in the map nor vice-versa. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of short values. + */ + V[] values(V[] array); + + /** + * Returns a TShortObjectIterator with access to this map's keys and + * values. + * + * @return a TShortObjectIterator with access to this map's keys and + * values. + */ + public TShortObjectIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TObjectProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TShortObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortObjectProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + public void transformValues(TObjectFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortObjectProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this map for equality. Returns + * true if the given object is also a map and the two maps represent + * the same mappings. More formally, two maps m1 and m2 + * represent the same mappings if m1.entrySet().equals(m2.entrySet()). + * This ensures that the equals method works properly across different + * implementations of the Map interface. + * + * @param o + * object to be compared for equality with this map + * @return true if the specified object is equal to this map + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this map. The hash code of a map is defined + * to be the sum of the hash codes of each entry in the map's + * entrySet() view. This ensures that m1.equals(m2) implies + * that m1.hashCode()==m2.hashCode() for any two maps m1 and + * m2, as required by the general contract of {@link Object#hashCode}. + * + * @return the hash code value for this map + * + * @see Object#equals(Object) + * @see #equals(Object) + */ + @Override + int hashCode(); +} diff --git a/src/gnu/trove/map/TShortShortMap.java b/src/gnu/trove/map/TShortShortMap.java new file mode 100644 index 0000000..a4603ce --- /dev/null +++ b/src/gnu/trove/map/TShortShortMap.java @@ -0,0 +1,294 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.function.*; +import gnu.trove.iterator.*; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.TShortCollection; + +import java.util.Map; + +/** + * Interface for a primitive map of short keys and short values. + */ +public interface TShortShortMap { + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null key in this collection. + */ + public short getNoEntryKey(); + + /** + * Returns the value that will be returned from {@link #get} or {@link #put} if + * no entry exists for a given key. The default value is generally zero, but can + * be changed during construction of the collection. + * + * @return the value that represents a null value in this collection. + */ + public short getNoEntryValue(); + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an short value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short put(short key, short value); + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an short value + * @param value + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short putIfAbsent(short key, short value); + + /** + * Put all the entries from the given Map into this map. + * + * @param map + * The Map from which entries will be obtained to put into this map. + */ + public void putAll(Map map); + + /** + * Put all the entries from the given map into this map. + * + * @param map + * The map from which entries will be obtained to put into this map. + */ + public void putAll(TShortShortMap map); + + /** + * Retrieves the value for key + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short get(short key); + + /** + * Empties the map. + */ + public void clear(); + + /** + * Returns true if this map contains no key-value mappings. + * + * @return true if this map contains no key-value mappings + */ + public boolean isEmpty(); + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an short value + * + * @return the previous value associated with key, or the "no entry" + * value if none was found (see {@link #getNoEntryValue}). + */ + public short remove(short key); + + /** + * Returns an int value that is the number of elements in the map. + * + * @return an int value that is the number of elements in the map. + */ + public int size(); + + /** + * Returns the keys of the map as a TShortSet + * + * @return the keys of the map as a TShortSet + */ + public TShortSet keySet(); + + /** + * Returns the keys of the map as an array of short values. + * + * @return the keys of the map as an array of short values. + */ + public short[] keys(); + + /** + * Returns the keys of the map. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the keys of the map as an array. + */ + public short[] keys(short[] array); + + /** + * Returns the values of the map as a TShortCollection + * + * @return the values of the map as a TShortCollection + */ + public TShortCollection valueCollection(); + + /** + * Returns the values of the map as an array of #e# values. + * + * @return the values of the map as an array of #e# values. + */ + public short[] values(); + + /** + * Returns the values of the map using an existing array. + * + * @param array + * the array into which the elements of the list are to be stored, if + * it is big enough; otherwise, a new array of the same type is + * allocated for this purpose. + * @return the values of the map as an array of #e# values. + */ + public short[] values(short[] array); + + /** + * Checks for the presence of val in the values of the map. + * + * @param val + * an short value + * @return a boolean value + */ + public boolean containsValue(short val); + + /** + * Checks for the present of key in the keys of the map. + * + * @param key + * an short value + * @return a boolean value + */ + public boolean containsKey(short key); + + /** + * @return a TShortShortIterator with access to this map's keys and values + */ + public TShortShortIterator iterator(); + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + public boolean forEachKey(TShortProcedure procedure); + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a T#F#Procedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + public boolean forEachValue(TShortProcedure procedure); + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOShortShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + public boolean forEachEntry(TShortShortProcedure procedure); + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + public void transformValues(TShortFunction function); + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + public boolean retainEntries(TShortShortProcedure procedure); + + /** + * Increments the primitive value mapped to key by 1 + * + * @param key + * the key of the value to increment + * @return true if a mapping was found and modified. + */ + public boolean increment(short key); + + /** + * Adjusts the primitive value mapped to key. + * + * @param key + * the key of the value to increment + * @param amount + * the amount to adjust the value by. + * @return true if a mapping was found and modified. + */ + public boolean adjustValue(short key, short amount); + + /** + * Adjusts the primitive value mapped to the key if the key is present in the + * map. Otherwise, the initial_value is put in the map. + * + * @param key + * the key of the value to increment + * @param adjust_amount + * the amount to adjust the value by + * @param put_amount + * the value put into the map if the key is not initial present + * + * @return the value present in the map after the adjustment or put operation + */ + public short adjustOrPutValue(short key, short adjust_amount, short put_amount); +} diff --git a/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java new file mode 100644 index 0000000..c0f7ce3 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectByteCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TByteCollection; +import gnu.trove.function.TByteFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.TObjectByteIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectByteMap; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and byte values. + * + * @author Rob Eden + */ +public class TObjectByteCustomHashMap extends TCustomObjectHash implements TObjectByteMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectByteProcedure PUT_ALL_PROC = new TObjectByteProcedure() { + @Override + public boolean execute(K key, byte value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient byte[] _values; + + /** the value that represents null */ + protected byte no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectByteCustomHashMap() { + } + + /** + * Creates a new TObjectByteHashMap instance with the default + * capacity and load factor. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + byte noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectByteCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectByteMap to be copied. + */ + public TObjectByteCustomHashMap(HashingStrategy strategy, TObjectByteMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectByteCustomHashMap) { + TObjectByteCustomHashMap hashmap = (TObjectByteCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + byte oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new byte[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + Object[] keys = _set; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public byte put(K key, byte value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(K key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private byte doPut(byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public byte remove(Object key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectByteMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TByteValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectByteIterator iterator() { + return new TObjectByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(final K key, final byte adjust_amount, final byte put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + @Override + public void transformValues(TByteFunction function) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectByteMap)) { + return false; + } + TObjectByteMap that = (TObjectByteMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectByteIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + byte value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectByteCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectByteCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectByteCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectByteCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectByteCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectByteCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteValueCollection implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TObjectByteValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TObjectByteCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TObjectByteCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TObjectByteCustomHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TObjectByteCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectByteCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TObjectByteCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectByteCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TObjectByteCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectByteValueHashIterator implements TByteIterator { + + protected THash _hash = TObjectByteCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectByteValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectByteCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectByteCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectByteHashIterator extends TObjectHashIterator implements TObjectByteIterator { + + /** the collection being iterated over */ + private final TObjectByteCustomHashMap _map; + + public TObjectByteHashIterator(TObjectByteCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeByte(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + byte val = in.readByte(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, byte value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java new file mode 100644 index 0000000..5c223e0 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectCharCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TCharCollection; +import gnu.trove.function.TCharFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.TObjectCharIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectCharMap; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and char values. + * + * @author Rob Eden + */ +public class TObjectCharCustomHashMap extends TCustomObjectHash implements TObjectCharMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectCharProcedure PUT_ALL_PROC = new TObjectCharProcedure() { + @Override + public boolean execute(K key, char value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient char[] _values; + + /** the value that represents null */ + protected char no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectCharCustomHashMap() { + } + + /** + * Creates a new TObjectCharHashMap instance with the default + * capacity and load factor. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + char noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectCharCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectCharMap to be copied. + */ + public TObjectCharCustomHashMap(HashingStrategy strategy, TObjectCharMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectCharCustomHashMap) { + TObjectCharCustomHashMap hashmap = (TObjectCharCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + char oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new char[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + Object[] keys = _set; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public char put(K key, char value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(K key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private char doPut(char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public char remove(Object key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectCharMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TCharValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectCharIterator iterator() { + return new TObjectCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(final K key, final char adjust_amount, final char put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + @Override + public void transformValues(TCharFunction function) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectCharMap)) { + return false; + } + TObjectCharMap that = (TObjectCharMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectCharIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + char value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectCharCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectCharCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectCharCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectCharCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectCharCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectCharCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharValueCollection implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TObjectCharValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TObjectCharCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TObjectCharCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TObjectCharCustomHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TObjectCharCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectCharCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TObjectCharCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectCharCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TObjectCharCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectCharValueHashIterator implements TCharIterator { + + protected THash _hash = TObjectCharCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectCharValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectCharCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectCharCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectCharHashIterator extends TObjectHashIterator implements TObjectCharIterator { + + /** the collection being iterated over */ + private final TObjectCharCustomHashMap _map; + + public TObjectCharHashIterator(TObjectCharCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeChar(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + char val = in.readChar(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, char value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java new file mode 100644 index 0000000..8338f2d --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectDoubleCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TDoubleCollection; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.TObjectDoubleIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and double values. + * + * @author Rob Eden + */ +public class TObjectDoubleCustomHashMap extends TCustomObjectHash implements TObjectDoubleMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectDoubleProcedure PUT_ALL_PROC = new TObjectDoubleProcedure() { + @Override + public boolean execute(K key, double value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient double[] _values; + + /** the value that represents null */ + protected double no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectDoubleCustomHashMap() { + } + + /** + * Creates a new TObjectDoubleHashMap instance with the default + * capacity and load factor. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + double noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectDoubleCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectDoubleMap to be copied. + */ + public TObjectDoubleCustomHashMap(HashingStrategy strategy, TObjectDoubleMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectDoubleCustomHashMap) { + TObjectDoubleCustomHashMap hashmap = (TObjectDoubleCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + double oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new double[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + Object[] keys = _set; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public double put(K key, double value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(K key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private double doPut(double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public double remove(Object key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectDoubleMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TDoubleValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(final K key, final double adjust_amount, final double put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + @Override + public void transformValues(TDoubleFunction function) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectDoubleMap)) { + return false; + } + TObjectDoubleMap that = (TObjectDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectDoubleIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + double value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectDoubleCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectDoubleCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectDoubleCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectDoubleCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectDoubleCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectDoubleCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleValueCollection implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TObjectDoubleValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TObjectDoubleCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TObjectDoubleCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TObjectDoubleCustomHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TObjectDoubleCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectDoubleCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TObjectDoubleCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectDoubleCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TObjectDoubleCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectDoubleValueHashIterator implements TDoubleIterator { + + protected THash _hash = TObjectDoubleCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectDoubleValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectDoubleCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectDoubleCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectDoubleHashIterator extends TObjectHashIterator implements TObjectDoubleIterator { + + /** the collection being iterated over */ + private final TObjectDoubleCustomHashMap _map; + + public TObjectDoubleHashIterator(TObjectDoubleCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + double val = in.readDouble(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, double value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java new file mode 100644 index 0000000..e2ae1e5 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectFloatCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TFloatCollection; +import gnu.trove.function.TFloatFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.TObjectFloatIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and float values. + * + * @author Rob Eden + */ +public class TObjectFloatCustomHashMap extends TCustomObjectHash implements TObjectFloatMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectFloatProcedure PUT_ALL_PROC = new TObjectFloatProcedure() { + @Override + public boolean execute(K key, float value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient float[] _values; + + /** the value that represents null */ + protected float no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectFloatCustomHashMap() { + } + + /** + * Creates a new TObjectFloatHashMap instance with the default + * capacity and load factor. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + float noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectFloatCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectFloatMap to be copied. + */ + public TObjectFloatCustomHashMap(HashingStrategy strategy, TObjectFloatMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectFloatCustomHashMap) { + TObjectFloatCustomHashMap hashmap = (TObjectFloatCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + float oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new float[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + Object[] keys = _set; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public float put(K key, float value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(K key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private float doPut(float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public float remove(Object key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectFloatMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TFloatValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(final K key, final float adjust_amount, final float put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + @Override + public void transformValues(TFloatFunction function) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectFloatMap)) { + return false; + } + TObjectFloatMap that = (TObjectFloatMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectFloatIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + float value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectFloatCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectFloatCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectFloatCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectFloatCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectFloatCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectFloatCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatValueCollection implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TObjectFloatValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TObjectFloatCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TObjectFloatCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TObjectFloatCustomHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TObjectFloatCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectFloatCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TObjectFloatCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectFloatCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TObjectFloatCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectFloatValueHashIterator implements TFloatIterator { + + protected THash _hash = TObjectFloatCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectFloatValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectFloatCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectFloatCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectFloatHashIterator extends TObjectHashIterator implements TObjectFloatIterator { + + /** the collection being iterated over */ + private final TObjectFloatCustomHashMap _map; + + public TObjectFloatHashIterator(TObjectFloatCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + float val = in.readFloat(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, float value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java new file mode 100644 index 0000000..f288c19 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectIntCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TIntCollection; +import gnu.trove.function.TIntFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.TObjectIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and int values. + * + * @author Rob Eden + */ +public class TObjectIntCustomHashMap extends TCustomObjectHash implements TObjectIntMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectIntProcedure PUT_ALL_PROC = new TObjectIntProcedure() { + @Override + public boolean execute(K key, int value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient int[] _values; + + /** the value that represents null */ + protected int no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectIntCustomHashMap() { + } + + /** + * Creates a new TObjectIntHashMap instance with the default + * capacity and load factor. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + int noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectIntCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectIntMap to be copied. + */ + public TObjectIntCustomHashMap(HashingStrategy strategy, TObjectIntMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectIntCustomHashMap) { + TObjectIntCustomHashMap hashmap = (TObjectIntCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + int oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new int[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + Object[] keys = _set; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public int put(K key, int value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(K key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private int doPut(int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public int remove(Object key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectIntMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TIntValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectIntIterator iterator() { + return new TObjectIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(final K key, final int adjust_amount, final int put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + @Override + public void transformValues(TIntFunction function) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectIntMap)) { + return false; + } + TObjectIntMap that = (TObjectIntMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectIntIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + int value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectIntCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectIntCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectIntCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectIntCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectIntCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectIntCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntValueCollection implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TObjectIntValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TObjectIntCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TObjectIntCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TObjectIntCustomHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TObjectIntCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectIntCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TObjectIntCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectIntCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TObjectIntCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectIntValueHashIterator implements TIntIterator { + + protected THash _hash = TObjectIntCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectIntValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectIntCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectIntCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectIntHashIterator extends TObjectHashIterator implements TObjectIntIterator { + + /** the collection being iterated over */ + private final TObjectIntCustomHashMap _map; + + public TObjectIntHashIterator(TObjectIntCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeInt(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + int val = in.readInt(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, int value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java new file mode 100644 index 0000000..817461f --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectLongCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TLongCollection; +import gnu.trove.function.TLongFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.TObjectLongIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and long values. + * + * @author Rob Eden + */ +public class TObjectLongCustomHashMap extends TCustomObjectHash implements TObjectLongMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectLongProcedure PUT_ALL_PROC = new TObjectLongProcedure() { + @Override + public boolean execute(K key, long value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient long[] _values; + + /** the value that represents null */ + protected long no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectLongCustomHashMap() { + } + + /** + * Creates a new TObjectLongHashMap instance with the default + * capacity and load factor. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + long noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectLongCustomHashMap that contains the entries + * in the map passed to it. + * + * @param map + * the TObjectLongMap to be copied. + */ + public TObjectLongCustomHashMap(HashingStrategy strategy, TObjectLongMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectLongCustomHashMap) { + TObjectLongCustomHashMap hashmap = (TObjectLongCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + long oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new long[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + Object[] keys = _set; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public long put(K key, long value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(K key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private long doPut(long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public long remove(Object key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectLongMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TLongValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectLongIterator iterator() { + return new TObjectLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + @Override + public void transformValues(TLongFunction function) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectLongMap)) { + return false; + } + TObjectLongMap that = (TObjectLongMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectLongIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + long value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectLongCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectLongCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectLongCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectLongCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectLongCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectLongCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongValueCollection implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TObjectLongValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TObjectLongCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TObjectLongCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TObjectLongCustomHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TObjectLongCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectLongCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TObjectLongCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectLongCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TObjectLongCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectLongValueHashIterator implements TLongIterator { + + protected THash _hash = TObjectLongCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectLongValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectLongCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectLongCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectLongHashIterator extends TObjectHashIterator implements TObjectLongIterator { + + /** the collection being iterated over */ + private final TObjectLongCustomHashMap _map; + + public TObjectLongHashIterator(TObjectLongCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeLong(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + long val = in.readLong(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, long value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java b/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java new file mode 100644 index 0000000..ce12258 --- /dev/null +++ b/src/gnu/trove/map/custom_hash/TObjectShortCustomHashMap.java @@ -0,0 +1,1185 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.custom_hash; + +import gnu.trove.TShortCollection; +import gnu.trove.function.TShortFunction; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.TObjectShortIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TObjectShortMap; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and short values. + * + * @author Rob Eden + */ +public class TObjectShortCustomHashMap extends TCustomObjectHash implements TObjectShortMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectShortProcedure PUT_ALL_PROC = new TObjectShortProcedure() { + @Override + public boolean execute(K key, short value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient short[] _values; + + /** the value that represents null */ + protected short no_entry_value; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TObjectShortCustomHashMap() { + } + + /** + * Creates a new TObjectShortHashMap instance with the default + * capacity and load factor. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy) { + super(strategy); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity) { + + super(strategy, initialCapacity); + + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor, + short noEntryValue) { + + super(strategy, initialCapacity, loadFactor); + + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectShortCustomHashMap that contains the + * entries in the map passed to it. + * + * @param map + * the TObjectShortMap to be copied. + */ + public TObjectShortCustomHashMap(HashingStrategy strategy, TObjectShortMap map) { + + this(strategy, map.size(), 0.5f, map.getNoEntryValue()); + + if (map instanceof TObjectShortCustomHashMap) { + TObjectShortCustomHashMap hashmap = (TObjectShortCustomHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + this.strategy = hashmap.strategy; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + short oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new short[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + K o = oldKeys[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + Object[] keys = _set; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public short put(K key, short value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(K key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private short doPut(short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public short remove(Object key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectShortMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TShortValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectShortIterator iterator() { + return new TObjectShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(final K key, final short adjust_amount, final short put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + @Override + public void transformValues(TShortFunction function) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectShortMap)) { + return false; + } + TObjectShortMap that = (TObjectShortMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectShortIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + short value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectShortCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectShortCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectShortCustomHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectShortCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectShortCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectShortCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortValueCollection implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TObjectShortValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TObjectShortCustomHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TObjectShortCustomHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TObjectShortCustomHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TObjectShortCustomHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectShortCustomHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TObjectShortCustomHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectShortCustomHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TObjectShortCustomHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectShortValueHashIterator implements TShortIterator { + + protected THash _hash = TObjectShortCustomHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectShortValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectShortCustomHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws java.util.ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectShortCustomHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + ; + } + return i; + } + } + } + + class TObjectShortHashIterator extends TObjectHashIterator implements TObjectShortIterator { + + /** the collection being iterated over */ + private final TObjectShortCustomHashMap _map; + + public TObjectShortHashIterator(TObjectShortCustomHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // STRATEGY + out.writeObject(strategy); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeShort(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // STRATEGY + strategy = (HashingStrategy) in.readObject(); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + short val = in.readShort(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, short value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} diff --git a/src/gnu/trove/map/hash/TByteByteHashMap.java b/src/gnu/trove/map/hash/TByteByteHashMap.java new file mode 100644 index 0000000..33daee6 --- /dev/null +++ b/src/gnu/trove/map/hash/TByteByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteByteHashMap extends TByteByteHash implements TByteByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TByteByteHashMap instance with the default + * capacity and load factor. + */ + public TByteByteHashMap() { + super(); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TByteByteHashMap(int initialCapacity, float loadFactor, byte noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TByteByteHashMap(byte[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteByteMap that will be duplicated. + */ + public TByteByteHashMap(TByteByteMap map) { + super(map.size()); + if (map instanceof TByteByteHashMap) { + TByteByteHashMap hashmap = (TByteByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(byte key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(byte key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(byte key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteByteMap map) { + ensureCapacity(map.size()); + TByteByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(byte key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteByteIterator iterator() { + return new TByteByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteByteProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(byte key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteByteKeyHashIterator(TByteByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteByteValueHashIterator(TByteByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteByteKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteByteHashIterator extends THashPrimitiveIterator implements TByteByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteByteHashMap we will be iterating over. + */ + TByteByteHashIterator(TByteByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteByteMap)) { + return false; + } + TByteByteMap that = (TByteByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + byte val = in.readByte(); + put(key, val); + } + } +} // TByteByteHashMap diff --git a/src/gnu/trove/map/hash/TByteCharHashMap.java b/src/gnu/trove/map/hash/TByteCharHashMap.java new file mode 100644 index 0000000..d1e794b --- /dev/null +++ b/src/gnu/trove/map/hash/TByteCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteCharHashMap extends TByteCharHash implements TByteCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TByteCharHashMap instance with the default + * capacity and load factor. + */ + public TByteCharHashMap() { + super(); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TByteCharHashMap(int initialCapacity, float loadFactor, byte noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TByteCharHashMap(byte[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteCharMap that will be duplicated. + */ + public TByteCharHashMap(TByteCharMap map) { + super(map.size()); + if (map instanceof TByteCharHashMap) { + TByteCharHashMap hashmap = (TByteCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(byte key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(byte key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(byte key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteCharMap map) { + ensureCapacity(map.size()); + TByteCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(byte key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteCharIterator iterator() { + return new TByteCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteCharProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(byte key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteCharKeyHashIterator(TByteCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TByteCharValueHashIterator(TByteCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TByteCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TByteCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TByteCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TByteCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TByteCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TByteCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteCharKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteCharHashIterator extends THashPrimitiveIterator implements TByteCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteCharHashMap we will be iterating over. + */ + TByteCharHashIterator(TByteCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteCharMap)) { + return false; + } + TByteCharMap that = (TByteCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + char val = in.readChar(); + put(key, val); + } + } +} // TByteCharHashMap diff --git a/src/gnu/trove/map/hash/TByteDoubleHashMap.java b/src/gnu/trove/map/hash/TByteDoubleHashMap.java new file mode 100644 index 0000000..dfbc74f --- /dev/null +++ b/src/gnu/trove/map/hash/TByteDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteDoubleHashMap extends TByteDoubleHash implements TByteDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TByteDoubleHashMap instance with the default + * capacity and load factor. + */ + public TByteDoubleHashMap() { + super(); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TByteDoubleHashMap(int initialCapacity, float loadFactor, byte noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TByteDoubleHashMap(byte[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteDoubleMap that will be duplicated. + */ + public TByteDoubleHashMap(TByteDoubleMap map) { + super(map.size()); + if (map instanceof TByteDoubleHashMap) { + TByteDoubleHashMap hashmap = (TByteDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(byte key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(byte key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(byte key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteDoubleMap map) { + ensureCapacity(map.size()); + TByteDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(byte key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteDoubleIterator iterator() { + return new TByteDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteDoubleProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(byte key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteDoubleKeyHashIterator(TByteDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TByteDoubleValueHashIterator(TByteDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TByteDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TByteDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TByteDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TByteDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TByteDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TByteDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteDoubleKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteDoubleHashIterator extends THashPrimitiveIterator implements TByteDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteDoubleHashMap we will be iterating over. + */ + TByteDoubleHashIterator(TByteDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteDoubleMap)) { + return false; + } + TByteDoubleMap that = (TByteDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + double val = in.readDouble(); + put(key, val); + } + } +} // TByteDoubleHashMap diff --git a/src/gnu/trove/map/hash/TByteFloatHashMap.java b/src/gnu/trove/map/hash/TByteFloatHashMap.java new file mode 100644 index 0000000..0acb1aa --- /dev/null +++ b/src/gnu/trove/map/hash/TByteFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteFloatHashMap extends TByteFloatHash implements TByteFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TByteFloatHashMap instance with the default + * capacity and load factor. + */ + public TByteFloatHashMap() { + super(); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TByteFloatHashMap(int initialCapacity, float loadFactor, byte noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TByteFloatHashMap(byte[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteFloatMap that will be duplicated. + */ + public TByteFloatHashMap(TByteFloatMap map) { + super(map.size()); + if (map instanceof TByteFloatHashMap) { + TByteFloatHashMap hashmap = (TByteFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(byte key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(byte key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(byte key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteFloatMap map) { + ensureCapacity(map.size()); + TByteFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(byte key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteFloatIterator iterator() { + return new TByteFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteFloatProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(byte key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteFloatKeyHashIterator(TByteFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TByteFloatValueHashIterator(TByteFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TByteFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TByteFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TByteFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TByteFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TByteFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TByteFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteFloatKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteFloatHashIterator extends THashPrimitiveIterator implements TByteFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteFloatHashMap we will be iterating over. + */ + TByteFloatHashIterator(TByteFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteFloatMap)) { + return false; + } + TByteFloatMap that = (TByteFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + float val = in.readFloat(); + put(key, val); + } + } +} // TByteFloatHashMap diff --git a/src/gnu/trove/map/hash/TByteIntHashMap.java b/src/gnu/trove/map/hash/TByteIntHashMap.java new file mode 100644 index 0000000..2214713 --- /dev/null +++ b/src/gnu/trove/map/hash/TByteIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteIntHashMap extends TByteIntHash implements TByteIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TByteIntHashMap instance with the default capacity + * and load factor. + */ + public TByteIntHashMap() { + super(); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TByteIntHashMap(int initialCapacity, float loadFactor, byte noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TByteIntHashMap(byte[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteIntMap that will be duplicated. + */ + public TByteIntHashMap(TByteIntMap map) { + super(map.size()); + if (map instanceof TByteIntHashMap) { + TByteIntHashMap hashmap = (TByteIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(byte key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(byte key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(byte key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteIntMap map) { + ensureCapacity(map.size()); + TByteIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(byte key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteIntIterator iterator() { + return new TByteIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteIntProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(byte key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteIntKeyHashIterator(TByteIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TByteIntValueHashIterator(TByteIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TByteIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TByteIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TByteIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TByteIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TByteIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TByteIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteIntKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteIntHashIterator extends THashPrimitiveIterator implements TByteIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteIntHashMap we will be iterating over. + */ + TByteIntHashIterator(TByteIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteIntMap)) { + return false; + } + TByteIntMap that = (TByteIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + int val = in.readInt(); + put(key, val); + } + } +} // TByteIntHashMap diff --git a/src/gnu/trove/map/hash/TByteLongHashMap.java b/src/gnu/trove/map/hash/TByteLongHashMap.java new file mode 100644 index 0000000..9ad543e --- /dev/null +++ b/src/gnu/trove/map/hash/TByteLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteLongHashMap extends TByteLongHash implements TByteLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TByteLongHashMap instance with the default + * capacity and load factor. + */ + public TByteLongHashMap() { + super(); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TByteLongHashMap(int initialCapacity, float loadFactor, byte noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TByteLongHashMap(byte[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteLongMap that will be duplicated. + */ + public TByteLongHashMap(TByteLongMap map) { + super(map.size()); + if (map instanceof TByteLongHashMap) { + TByteLongHashMap hashmap = (TByteLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(byte key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(byte key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(byte key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteLongMap map) { + ensureCapacity(map.size()); + TByteLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(byte key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteLongIterator iterator() { + return new TByteLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteLongProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(byte key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteLongKeyHashIterator(TByteLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TByteLongValueHashIterator(TByteLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TByteLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TByteLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TByteLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TByteLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TByteLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TByteLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteLongKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteLongHashIterator extends THashPrimitiveIterator implements TByteLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteLongHashMap we will be iterating over. + */ + TByteLongHashIterator(TByteLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteLongMap)) { + return false; + } + TByteLongMap that = (TByteLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + long val = in.readLong(); + put(key, val); + } + } +} // TByteLongHashMap diff --git a/src/gnu/trove/map/hash/TByteObjectHashMap.java b/src/gnu/trove/map/hash/TByteObjectHashMap.java new file mode 100644 index 0000000..7534c4c --- /dev/null +++ b/src/gnu/trove/map/hash/TByteObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TByteObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TByteObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.TByteObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TByteSet; +import gnu.trove.TByteCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for byte keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TByteObjectHashMap extends TByteHash implements TByteObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TByteObjectProcedure PUT_ALL_PROC = new TByteObjectProcedure() { + @Override + public boolean execute(byte key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected byte no_entry_key; + + /** + * Creates a new TByteObjectHashMap instance with the default + * capacity and load factor. + */ + public TByteObjectHashMap() { + super(); + } + + /** + * Creates a new TByteObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TByteObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TByteObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TByteObjectHashMap(int initialCapacity, float loadFactor, byte noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TByteObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TByteObjectMap to be copied. + */ + public TByteObjectHashMap(TByteObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(byte key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(byte key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(byte key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(byte key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public byte[] keys() { + byte[] keys = new byte[size()]; + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public byte[] keys(byte[] dest) { + if (dest.length < _size) { + dest = new byte[_size]; + } + + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TByteObjectIterator iterator() { + return new TByteObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TByteObjectProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TByteObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteObjectMap)) { + return false; + } + TByteObjectMap that = (TByteObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TByteObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + byte key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteHashIterator(TByteObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return null != TByteObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TByteObjectHashMap.this.containsKey(((Byte) element).byteValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + if (collection == this) { + return true; + } + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TByteHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** the collection on which the iterator operates */ + private final TByteHash _hash; + + /** {@inheritDoc} */ + public TByteHashIterator(TByteHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TByteObjectValueHashIterator(TByteObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TByteObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TByteObjectHashMap _map; + + public TByteObjectValueHashIterator(TByteObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TByteObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TByteObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TByteObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteObjectHashIterator extends THashPrimitiveIterator implements TByteObjectIterator { + + /** the collection being iterated over */ + private final TByteObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TByteObjectHashIterator(TByteObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeByte(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TByteObjectHashMap diff --git a/src/gnu/trove/map/hash/TByteShortHashMap.java b/src/gnu/trove/map/hash/TByteShortHashMap.java new file mode 100644 index 0000000..770ff1d --- /dev/null +++ b/src/gnu/trove/map/hash/TByteShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TByteShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for byte keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TByteShortHashMap extends TByteShortHash implements TByteShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TByteShortHashMap instance with the default + * capacity and load factor. + */ + public TByteShortHashMap() { + super(); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TByteShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TByteShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TByteShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a byte value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TByteShortHashMap(int initialCapacity, float loadFactor, byte noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TByteShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a byte array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TByteShortHashMap(byte[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TByteShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TByteShortMap that will be duplicated. + */ + public TByteShortHashMap(TByteShortMap map) { + super(map.size()); + if (map instanceof TByteShortHashMap) { + TByteShortHashMap hashmap = (TByteShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (byte) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(byte key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(byte key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(byte key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().byteValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TByteShortMap map) { + ensureCapacity(map.size()); + TByteShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(byte key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(byte key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TByteSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] keys() { + byte[] keys = new byte[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + byte[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public byte[] keys(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(byte key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TByteShortIterator iterator() { + return new TByteShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TByteProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TByteShortProcedure procedure) { + byte[] states = _states; + byte[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TByteShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + byte[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(byte key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(byte key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(byte key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TByteSet { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteShortKeyHashIterator(TByteShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TByteShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TByteShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TByteShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + return no_entry_value != TByteShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TByteShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TByteShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TByteShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TByteShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + final TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TByteShortValueHashIterator(TByteShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TByteShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TByteShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TByteShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + byte[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TByteShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TByteShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TByteShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TByteShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TByteShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TByteShortKeyHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TByteShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TByteShortHashIterator extends THashPrimitiveIterator implements TByteShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TByteShortHashMap we will be iterating over. + */ + TByteShortHashIterator(TByteShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public byte key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TByteShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteShortMap)) { + return false; + } + TByteShortMap that = (TByteShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + byte key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TByteShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + byte key = in.readByte(); + short val = in.readShort(); + put(key, val); + } + } +} // TByteShortHashMap diff --git a/src/gnu/trove/map/hash/TCharByteHashMap.java b/src/gnu/trove/map/hash/TCharByteHashMap.java new file mode 100644 index 0000000..178d6c8 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharByteHashMap extends TCharByteHash implements TCharByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TCharByteHashMap instance with the default + * capacity and load factor. + */ + public TCharByteHashMap() { + super(); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TCharByteHashMap(int initialCapacity, float loadFactor, char noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TCharByteHashMap(char[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharByteMap that will be duplicated. + */ + public TCharByteHashMap(TCharByteMap map) { + super(map.size()); + if (map instanceof TCharByteHashMap) { + TCharByteHashMap hashmap = (TCharByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(char key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(char key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(char key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharByteMap map) { + ensureCapacity(map.size()); + TCharByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(char key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharByteIterator iterator() { + return new TCharByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharByteProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(char key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharByteKeyHashIterator(TCharByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TCharByteValueHashIterator(TCharByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TCharByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TCharByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TCharByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TCharByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TCharByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TCharByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharByteKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharByteHashIterator extends THashPrimitiveIterator implements TCharByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharByteHashMap we will be iterating over. + */ + TCharByteHashIterator(TCharByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharByteMap)) { + return false; + } + TCharByteMap that = (TCharByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + byte val = in.readByte(); + put(key, val); + } + } +} // TCharByteHashMap diff --git a/src/gnu/trove/map/hash/TCharCharHashMap.java b/src/gnu/trove/map/hash/TCharCharHashMap.java new file mode 100644 index 0000000..ad900bf --- /dev/null +++ b/src/gnu/trove/map/hash/TCharCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharCharHashMap extends TCharCharHash implements TCharCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TCharCharHashMap instance with the default + * capacity and load factor. + */ + public TCharCharHashMap() { + super(); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TCharCharHashMap(int initialCapacity, float loadFactor, char noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TCharCharHashMap(char[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharCharMap that will be duplicated. + */ + public TCharCharHashMap(TCharCharMap map) { + super(map.size()); + if (map instanceof TCharCharHashMap) { + TCharCharHashMap hashmap = (TCharCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(char key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(char key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(char key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharCharMap map) { + ensureCapacity(map.size()); + TCharCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(char key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharCharIterator iterator() { + return new TCharCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharCharProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(char key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharCharKeyHashIterator(TCharCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharCharValueHashIterator(TCharCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharCharKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharCharHashIterator extends THashPrimitiveIterator implements TCharCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharCharHashMap we will be iterating over. + */ + TCharCharHashIterator(TCharCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharCharMap)) { + return false; + } + TCharCharMap that = (TCharCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + char val = in.readChar(); + put(key, val); + } + } +} // TCharCharHashMap diff --git a/src/gnu/trove/map/hash/TCharDoubleHashMap.java b/src/gnu/trove/map/hash/TCharDoubleHashMap.java new file mode 100644 index 0000000..c0ab81e --- /dev/null +++ b/src/gnu/trove/map/hash/TCharDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharDoubleHashMap extends TCharDoubleHash implements TCharDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TCharDoubleHashMap instance with the default + * capacity and load factor. + */ + public TCharDoubleHashMap() { + super(); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TCharDoubleHashMap(int initialCapacity, float loadFactor, char noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TCharDoubleHashMap(char[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharDoubleMap that will be duplicated. + */ + public TCharDoubleHashMap(TCharDoubleMap map) { + super(map.size()); + if (map instanceof TCharDoubleHashMap) { + TCharDoubleHashMap hashmap = (TCharDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(char key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(char key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(char key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharDoubleMap map) { + ensureCapacity(map.size()); + TCharDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(char key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharDoubleIterator iterator() { + return new TCharDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharDoubleProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(char key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharDoubleKeyHashIterator(TCharDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TCharDoubleValueHashIterator(TCharDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TCharDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TCharDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TCharDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TCharDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TCharDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TCharDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharDoubleKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharDoubleHashIterator extends THashPrimitiveIterator implements TCharDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharDoubleHashMap we will be iterating over. + */ + TCharDoubleHashIterator(TCharDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharDoubleMap)) { + return false; + } + TCharDoubleMap that = (TCharDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + double val = in.readDouble(); + put(key, val); + } + } +} // TCharDoubleHashMap diff --git a/src/gnu/trove/map/hash/TCharFloatHashMap.java b/src/gnu/trove/map/hash/TCharFloatHashMap.java new file mode 100644 index 0000000..914ae0b --- /dev/null +++ b/src/gnu/trove/map/hash/TCharFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharFloatHashMap extends TCharFloatHash implements TCharFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TCharFloatHashMap instance with the default + * capacity and load factor. + */ + public TCharFloatHashMap() { + super(); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TCharFloatHashMap(int initialCapacity, float loadFactor, char noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TCharFloatHashMap(char[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharFloatMap that will be duplicated. + */ + public TCharFloatHashMap(TCharFloatMap map) { + super(map.size()); + if (map instanceof TCharFloatHashMap) { + TCharFloatHashMap hashmap = (TCharFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(char key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(char key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(char key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharFloatMap map) { + ensureCapacity(map.size()); + TCharFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(char key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharFloatIterator iterator() { + return new TCharFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharFloatProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(char key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharFloatKeyHashIterator(TCharFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TCharFloatValueHashIterator(TCharFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TCharFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TCharFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TCharFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TCharFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TCharFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TCharFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharFloatKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharFloatHashIterator extends THashPrimitiveIterator implements TCharFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharFloatHashMap we will be iterating over. + */ + TCharFloatHashIterator(TCharFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharFloatMap)) { + return false; + } + TCharFloatMap that = (TCharFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + float val = in.readFloat(); + put(key, val); + } + } +} // TCharFloatHashMap diff --git a/src/gnu/trove/map/hash/TCharIntHashMap.java b/src/gnu/trove/map/hash/TCharIntHashMap.java new file mode 100644 index 0000000..adf0dde --- /dev/null +++ b/src/gnu/trove/map/hash/TCharIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharIntHashMap extends TCharIntHash implements TCharIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TCharIntHashMap instance with the default capacity + * and load factor. + */ + public TCharIntHashMap() { + super(); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TCharIntHashMap(int initialCapacity, float loadFactor, char noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TCharIntHashMap(char[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharIntMap that will be duplicated. + */ + public TCharIntHashMap(TCharIntMap map) { + super(map.size()); + if (map instanceof TCharIntHashMap) { + TCharIntHashMap hashmap = (TCharIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(char key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(char key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(char key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharIntMap map) { + ensureCapacity(map.size()); + TCharIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(char key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharIntIterator iterator() { + return new TCharIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharIntProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(char key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharIntKeyHashIterator(TCharIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TCharIntValueHashIterator(TCharIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TCharIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TCharIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TCharIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TCharIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TCharIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TCharIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharIntKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharIntHashIterator extends THashPrimitiveIterator implements TCharIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharIntHashMap we will be iterating over. + */ + TCharIntHashIterator(TCharIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharIntMap)) { + return false; + } + TCharIntMap that = (TCharIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + int val = in.readInt(); + put(key, val); + } + } +} // TCharIntHashMap diff --git a/src/gnu/trove/map/hash/TCharLongHashMap.java b/src/gnu/trove/map/hash/TCharLongHashMap.java new file mode 100644 index 0000000..f52070f --- /dev/null +++ b/src/gnu/trove/map/hash/TCharLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharLongHashMap extends TCharLongHash implements TCharLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TCharLongHashMap instance with the default + * capacity and load factor. + */ + public TCharLongHashMap() { + super(); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TCharLongHashMap(int initialCapacity, float loadFactor, char noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TCharLongHashMap(char[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharLongMap that will be duplicated. + */ + public TCharLongHashMap(TCharLongMap map) { + super(map.size()); + if (map instanceof TCharLongHashMap) { + TCharLongHashMap hashmap = (TCharLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(char key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(char key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(char key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharLongMap map) { + ensureCapacity(map.size()); + TCharLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(char key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharLongIterator iterator() { + return new TCharLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharLongProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(char key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharLongKeyHashIterator(TCharLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TCharLongValueHashIterator(TCharLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TCharLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TCharLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TCharLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TCharLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TCharLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TCharLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharLongKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharLongHashIterator extends THashPrimitiveIterator implements TCharLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharLongHashMap we will be iterating over. + */ + TCharLongHashIterator(TCharLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharLongMap)) { + return false; + } + TCharLongMap that = (TCharLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + long val = in.readLong(); + put(key, val); + } + } +} // TCharLongHashMap diff --git a/src/gnu/trove/map/hash/TCharObjectHashMap.java b/src/gnu/trove/map/hash/TCharObjectHashMap.java new file mode 100644 index 0000000..eef81e1 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TCharObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TCharObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.TCharObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TCharSet; +import gnu.trove.TCharCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for char keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TCharObjectHashMap extends TCharHash implements TCharObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TCharObjectProcedure PUT_ALL_PROC = new TCharObjectProcedure() { + @Override + public boolean execute(char key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected char no_entry_key; + + /** + * Creates a new TCharObjectHashMap instance with the default + * capacity and load factor. + */ + public TCharObjectHashMap() { + super(); + } + + /** + * Creates a new TCharObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TCharObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TCharObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TCharObjectHashMap(int initialCapacity, float loadFactor, char noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TCharObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TCharObjectMap to be copied. + */ + public TCharObjectHashMap(TCharObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(char key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(char key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(char key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(char key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public char[] keys() { + char[] keys = new char[size()]; + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public char[] keys(char[] dest) { + if (dest.length < _size) { + dest = new char[_size]; + } + + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TCharObjectIterator iterator() { + return new TCharObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TCharObjectProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TCharObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharObjectMap)) { + return false; + } + TCharObjectMap that = (TCharObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TCharObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + char key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharHashIterator(TCharObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return null != TCharObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TCharObjectHashMap.this.containsKey(((Character) element).charValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + if (collection == this) { + return true; + } + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TCharHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** the collection on which the iterator operates */ + private final TCharHash _hash; + + /** {@inheritDoc} */ + public TCharHashIterator(TCharHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TCharObjectValueHashIterator(TCharObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TCharObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TCharObjectHashMap _map; + + public TCharObjectValueHashIterator(TCharObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TCharObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TCharObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TCharObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharObjectHashIterator extends THashPrimitiveIterator implements TCharObjectIterator { + + /** the collection being iterated over */ + private final TCharObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TCharObjectHashIterator(TCharObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeChar(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TCharObjectHashMap diff --git a/src/gnu/trove/map/hash/TCharShortHashMap.java b/src/gnu/trove/map/hash/TCharShortHashMap.java new file mode 100644 index 0000000..2402cb4 --- /dev/null +++ b/src/gnu/trove/map/hash/TCharShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TCharShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for char keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TCharShortHashMap extends TCharShortHash implements TCharShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TCharShortHashMap instance with the default + * capacity and load factor. + */ + public TCharShortHashMap() { + super(); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCharShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCharShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TCharShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a char value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TCharShortHashMap(int initialCapacity, float loadFactor, char noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TCharShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a char array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TCharShortHashMap(char[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TCharShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TCharShortMap that will be duplicated. + */ + public TCharShortHashMap(TCharShortMap map) { + super(map.size()); + if (map instanceof TCharShortHashMap) { + TCharShortHashMap hashmap = (TCharShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (char) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(char key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(char key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(char key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().charValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TCharShortMap map) { + ensureCapacity(map.size()); + TCharShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(char key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(char key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TCharSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public char[] keys() { + char[] keys = new char[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + char[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public char[] keys(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(char key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TCharShortIterator iterator() { + return new TCharShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TCharProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TCharShortProcedure procedure) { + byte[] states = _states; + char[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TCharShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + char[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(char key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(char key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(char key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TCharSet { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharShortKeyHashIterator(TCharShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TCharShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TCharShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TCharShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + return no_entry_value != TCharShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TCharShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TCharShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TCharShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TCharShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + final TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TCharShortValueHashIterator(TCharShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TCharShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TCharShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TCharShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + char[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TCharShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TCharShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TCharShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TCharShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TCharShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TCharShortKeyHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TCharShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TCharShortHashIterator extends THashPrimitiveIterator implements TCharShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TCharShortHashMap we will be iterating over. + */ + TCharShortHashIterator(TCharShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public char key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TCharShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharShortMap)) { + return false; + } + TCharShortMap that = (TCharShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + char key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TCharShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(char key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + char key = in.readChar(); + short val = in.readShort(); + put(key, val); + } + } +} // TCharShortHashMap diff --git a/src/gnu/trove/map/hash/TCustomHashMap.java b/src/gnu/trove/map/hash/TCustomHashMap.java new file mode 100644 index 0000000..42d8293 --- /dev/null +++ b/src/gnu/trove/map/hash/TCustomHashMap.java @@ -0,0 +1,896 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TMap; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.strategy.HashingStrategy; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +/** + * An implementation of the Map interface which uses an open addressed hash + * table to store its contents. + * + * @author Rob Eden + */ +public class TCustomHashMap extends TCustomObjectHash implements TMap, Externalizable { + + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient V[] _values; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomHashMap() { + super(); + } + + /** + * Creates a new TCustomHashMap instance with the default capacity + * and load factor. + */ + public TCustomHashMap(HashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new TCustomHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TCustomHashMap(HashingStrategy strategy, int initialCapacity) { + super(strategy, initialCapacity); + } + + /** + * Creates a new TCustomHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCustomHashMap(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + } + + /** + * Creates a new TCustomHashMap instance which contains the + * key/value pairs in map. + * + * @param map + * a Map value + */ + public TCustomHashMap(HashingStrategy strategy, Map map) { + + this(strategy, map.size()); + putAll(map); + } + + /** + * Creates a new TCustomHashMap instance which contains the + * key/value pairs in map. + * + * @param map + * a Map value + */ + public TCustomHashMap(HashingStrategy strategy, TCustomHashMap map) { + + this(strategy, map.size()); + putAll(map); + } + + /** + * initialize the value array of the map. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + // noinspection unchecked + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V put(K key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value) { + int index = insertKey(key); + if (index < 0) { + return _values[-index - 1]; + } + return doPut(value, index); + } + + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + @SuppressWarnings({ "unchecked", "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Map)) { + return false; + } + Map that = (Map) other; + if (that.size() != this.size()) { + return false; + } + return forEachEntry(new EqProcedure(that)); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, V value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + private final class HashProcedure implements TObjectObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(K key, V value) { + h += HashFunctions.hash(key) ^ (value == null ? 0 : value.hashCode()); + return true; + } + } + + private static final class EqProcedure implements TObjectObjectProcedure { + private final Map _otherMap; + + EqProcedure(Map otherMap) { + _otherMap = otherMap; + } + + @Override + public final boolean execute(K key, V value) { + // Check to make sure the key is there. This avoids problems that come up with + // null values. Since it is only caused in that cause, only do this when the + // value is null (to avoid extra work). + if (value == null && !_otherMap.containsKey(key)) { + return false; + } + + V oValue = _otherMap.get(key); + return oValue == value || (oValue != null && oValue.equals(value)); + } + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure) { + Object[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure) { + boolean modified = false; + Object[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + @Override + public void transformValues(TObjectFunction function) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldKeys[] = _set; + V oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = (V[]) new Object[newCapacity]; + + // Process entries from the old array, skipping free and removed slots. Put the + // values into the appropriate place in the new array. + for (int i = oldCapacity; i-- > 0;) { + Object o = oldKeys[i]; + if (o == FREE || o == REMOVED) + continue; + + int index = insertKey((K) o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldKeys); + } + _values[index] = oldVals[i]; + } + } + + /** + * retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V get(Object key) { + int index = index(key); + if (index < 0 || !strategy.equals((K) _set[index], (K) key)) { + return null; + } + return _values[index]; + } + + /** Empties the map. */ + @Override + public void clear() { + if (size() == 0) { + return; // optimization + } + + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return an Object value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V remove(Object key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * removes the mapping at index from the map. + * + * @param index + * an int value + */ + @Override + public void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + /** + * Returns a view on the values of the map. + * + * @return a Collection value + */ + @Override + public Collection values() { + return new ValueView(); + } + + /** + * returns a Set view on the keys of the map. + * + * @return a Set value + */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new EntryView(); + } + + /** + * checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + Object[] set = _set; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && val == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) + && (val == vals[i] || strategy.equals((K) val, (K) vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** + * checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** + * copies the key/value mappings in map into this map. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof TCustomHashMap + for (Map.Entry e : map.entrySet()) { + put(e.getKey(), e.getValue()); + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TCustomHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + Object[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && value == values[i] + || (null != values[i] && strategy.equals((K) values[i], (K) value))) { + + removeAt(i); + return true; + } + } + + return false; + } + } + + /** a view onto the entries of the map. */ + protected class EntryView extends MapBackedView> { + + private final class EntryIterator extends TObjectHashIterator { + + EntryIterator(TCustomHashMap map) { + super(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Entry objectAtIndex(final int index) { + return new Entry((K) _set[index], _values[index], index); + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator> iterator() { + return new EntryIterator(TCustomHashMap.this); + } + + @Override + public boolean removeElement(Map.Entry entry) { + // have to effectively reimplement Map.remove here + // because we need to return true/false depending on + // whether the removal took place. Since the Entry's + // value can be null, this means that we can't rely + // on the value of the object returned by Map.remove() + // to determine whether a deletion actually happened. + // + // Note also that the deletion is only legal if + // both the key and the value match. + Object val; + int index; + + K key = keyForEntry(entry); + index = index(key); + if (index >= 0) { + val = valueForEntry(entry); + if (val == _values[index] || (null != val && strategy.equals((K) val, (K) _values[index]))) { + removeAt(index); // clear key,state; adjust size + return true; + } + } + return false; + } + + @Override + public boolean containsElement(Map.Entry entry) { + Object val = get(keyForEntry(entry)); + Object entryValue = entry.getValue(); + return entryValue == val || (null != val && strategy.equals((K) val, (K) entryValue)); + } + + protected V valueForEntry(Map.Entry entry) { + return entry.getValue(); + } + + protected K keyForEntry(Map.Entry entry) { + return entry.getKey(); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + // public boolean containsAll( Collection collection ) { + // for ( Object element : collection ) { + // if ( !contains( element ) ) { + // return false; + // } + // } + // return true; + // } + + @Override + public void clear() { + TCustomHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TCustomHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TCustomHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + Iterator i = iterator(); + if (!i.hasNext()) + return "{}"; + + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (;;) { + E e = i.next(); + sb.append(e == this ? "(this Collection)" : e); + if (!i.hasNext()) + return sb.append('}').toString(); + sb.append(", "); + } + } + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TCustomHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return null != TCustomHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TCustomHashMap.this.contains(key); + } + } + + final class Entry implements Map.Entry { + + private K key; + private V val; + private final int index; + + Entry(final K key, V value, final int index) { + this.key = key; + this.val = value; + this.index = index; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public V setValue(V o) { + if (_values[index] != val) { + throw new ConcurrentModificationException(); + } + // need to return previous value + V retval = val; + // update this entry's value, in case setValue is called again + _values[index] = o; + val = o; + return retval; + } + + @Override + public boolean equals(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e1 = this; + Map.Entry e2 = (Map.Entry) o; + return (e1.getKey() == null ? e2.getKey() == null : strategy.equals(e1.getKey(), (K) e2.getKey())) + && (e1.getValue() == null ? e2.getValue() == null : e1.getValue().equals(e2.getValue())); + } + return false; + } + + @Override + public int hashCode() { + return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); + } + + @Override + public String toString() { + return key + "=" + val; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + // noinspection unchecked + V val = (V) in.readObject(); + put(key, val); + } + } +} // TCustomHashMap diff --git a/src/gnu/trove/map/hash/TDoubleByteHashMap.java b/src/gnu/trove/map/hash/TDoubleByteHashMap.java new file mode 100644 index 0000000..1437c73 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleByteHashMap extends TDoubleByteHash implements TDoubleByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TDoubleByteHashMap instance with the default + * capacity and load factor. + */ + public TDoubleByteHashMap() { + super(); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TDoubleByteHashMap(int initialCapacity, float loadFactor, double noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TDoubleByteHashMap(double[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleByteMap that will be duplicated. + */ + public TDoubleByteHashMap(TDoubleByteMap map) { + super(map.size()); + if (map instanceof TDoubleByteHashMap) { + TDoubleByteHashMap hashmap = (TDoubleByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(double key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(double key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(double key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleByteMap map) { + ensureCapacity(map.size()); + TDoubleByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(double key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleByteIterator iterator() { + return new TDoubleByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleByteProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(double key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleByteKeyHashIterator(TDoubleByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TDoubleByteValueHashIterator(TDoubleByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TDoubleByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TDoubleByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TDoubleByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TDoubleByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TDoubleByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TDoubleByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleByteKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleByteHashIterator extends THashPrimitiveIterator implements TDoubleByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleByteHashMap we will be iterating over. + */ + TDoubleByteHashIterator(TDoubleByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleByteMap)) { + return false; + } + TDoubleByteMap that = (TDoubleByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + byte val = in.readByte(); + put(key, val); + } + } +} // TDoubleByteHashMap diff --git a/src/gnu/trove/map/hash/TDoubleCharHashMap.java b/src/gnu/trove/map/hash/TDoubleCharHashMap.java new file mode 100644 index 0000000..2b0e3f9 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleCharHashMap extends TDoubleCharHash implements TDoubleCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TDoubleCharHashMap instance with the default + * capacity and load factor. + */ + public TDoubleCharHashMap() { + super(); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TDoubleCharHashMap(int initialCapacity, float loadFactor, double noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TDoubleCharHashMap(double[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleCharMap that will be duplicated. + */ + public TDoubleCharHashMap(TDoubleCharMap map) { + super(map.size()); + if (map instanceof TDoubleCharHashMap) { + TDoubleCharHashMap hashmap = (TDoubleCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(double key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(double key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(double key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleCharMap map) { + ensureCapacity(map.size()); + TDoubleCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(double key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleCharIterator iterator() { + return new TDoubleCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleCharProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(double key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleCharKeyHashIterator(TDoubleCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TDoubleCharValueHashIterator(TDoubleCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TDoubleCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TDoubleCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TDoubleCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TDoubleCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TDoubleCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TDoubleCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleCharKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleCharHashIterator extends THashPrimitiveIterator implements TDoubleCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleCharHashMap we will be iterating over. + */ + TDoubleCharHashIterator(TDoubleCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleCharMap)) { + return false; + } + TDoubleCharMap that = (TDoubleCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + char val = in.readChar(); + put(key, val); + } + } +} // TDoubleCharHashMap diff --git a/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java b/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java new file mode 100644 index 0000000..1290b50 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleDoubleHashMap extends TDoubleDoubleHash implements TDoubleDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TDoubleDoubleHashMap instance with the default + * capacity and load factor. + */ + public TDoubleDoubleHashMap() { + super(); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TDoubleDoubleHashMap(int initialCapacity, float loadFactor, double noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleDoubleHashMap instance containing all of + * the entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TDoubleDoubleHashMap(double[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleDoubleHashMap instance containing all of + * the entries in the map passed in. + * + * @param map + * a TDoubleDoubleMap that will be duplicated. + */ + public TDoubleDoubleHashMap(TDoubleDoubleMap map) { + super(map.size()); + if (map instanceof TDoubleDoubleHashMap) { + TDoubleDoubleHashMap hashmap = (TDoubleDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(double key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(double key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(double key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleDoubleMap map) { + ensureCapacity(map.size()); + TDoubleDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(double key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleDoubleIterator iterator() { + return new TDoubleDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleDoubleProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(double key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleDoubleKeyHashIterator(TDoubleDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleDoubleValueHashIterator(TDoubleDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleDoubleKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleDoubleHashIterator extends THashPrimitiveIterator implements TDoubleDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleDoubleHashMap we will be iterating over. + */ + TDoubleDoubleHashIterator(TDoubleDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleDoubleMap)) { + return false; + } + TDoubleDoubleMap that = (TDoubleDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + double val = in.readDouble(); + put(key, val); + } + } +} // TDoubleDoubleHashMap diff --git a/src/gnu/trove/map/hash/TDoubleFloatHashMap.java b/src/gnu/trove/map/hash/TDoubleFloatHashMap.java new file mode 100644 index 0000000..53f22c5 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleFloatHashMap extends TDoubleFloatHash implements TDoubleFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TDoubleFloatHashMap instance with the default + * capacity and load factor. + */ + public TDoubleFloatHashMap() { + super(); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TDoubleFloatHashMap(int initialCapacity, float loadFactor, double noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TDoubleFloatHashMap(double[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleFloatMap that will be duplicated. + */ + public TDoubleFloatHashMap(TDoubleFloatMap map) { + super(map.size()); + if (map instanceof TDoubleFloatHashMap) { + TDoubleFloatHashMap hashmap = (TDoubleFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(double key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(double key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(double key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleFloatMap map) { + ensureCapacity(map.size()); + TDoubleFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(double key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleFloatIterator iterator() { + return new TDoubleFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleFloatProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(double key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleFloatKeyHashIterator(TDoubleFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TDoubleFloatValueHashIterator(TDoubleFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TDoubleFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TDoubleFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TDoubleFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TDoubleFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TDoubleFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TDoubleFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleFloatKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleFloatHashIterator extends THashPrimitiveIterator implements TDoubleFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleFloatHashMap we will be iterating over. + */ + TDoubleFloatHashIterator(TDoubleFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleFloatMap)) { + return false; + } + TDoubleFloatMap that = (TDoubleFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + float val = in.readFloat(); + put(key, val); + } + } +} // TDoubleFloatHashMap diff --git a/src/gnu/trove/map/hash/TDoubleIntHashMap.java b/src/gnu/trove/map/hash/TDoubleIntHashMap.java new file mode 100644 index 0000000..2d1d727 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleIntHashMap extends TDoubleIntHash implements TDoubleIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TDoubleIntHashMap instance with the default + * capacity and load factor. + */ + public TDoubleIntHashMap() { + super(); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TDoubleIntHashMap(int initialCapacity, float loadFactor, double noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TDoubleIntHashMap(double[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleIntMap that will be duplicated. + */ + public TDoubleIntHashMap(TDoubleIntMap map) { + super(map.size()); + if (map instanceof TDoubleIntHashMap) { + TDoubleIntHashMap hashmap = (TDoubleIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(double key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(double key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(double key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleIntMap map) { + ensureCapacity(map.size()); + TDoubleIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(double key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIntIterator iterator() { + return new TDoubleIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleIntProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(double key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleIntKeyHashIterator(TDoubleIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TDoubleIntValueHashIterator(TDoubleIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TDoubleIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TDoubleIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TDoubleIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TDoubleIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TDoubleIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TDoubleIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleIntKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleIntHashIterator extends THashPrimitiveIterator implements TDoubleIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleIntHashMap we will be iterating over. + */ + TDoubleIntHashIterator(TDoubleIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleIntMap)) { + return false; + } + TDoubleIntMap that = (TDoubleIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + int val = in.readInt(); + put(key, val); + } + } +} // TDoubleIntHashMap diff --git a/src/gnu/trove/map/hash/TDoubleLongHashMap.java b/src/gnu/trove/map/hash/TDoubleLongHashMap.java new file mode 100644 index 0000000..419853a --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleLongHashMap extends TDoubleLongHash implements TDoubleLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TDoubleLongHashMap instance with the default + * capacity and load factor. + */ + public TDoubleLongHashMap() { + super(); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TDoubleLongHashMap(int initialCapacity, float loadFactor, double noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TDoubleLongHashMap(double[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleLongMap that will be duplicated. + */ + public TDoubleLongHashMap(TDoubleLongMap map) { + super(map.size()); + if (map instanceof TDoubleLongHashMap) { + TDoubleLongHashMap hashmap = (TDoubleLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(double key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(double key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(double key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleLongMap map) { + ensureCapacity(map.size()); + TDoubleLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(double key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleLongIterator iterator() { + return new TDoubleLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleLongProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(double key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleLongKeyHashIterator(TDoubleLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TDoubleLongValueHashIterator(TDoubleLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TDoubleLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TDoubleLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TDoubleLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TDoubleLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TDoubleLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TDoubleLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleLongKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleLongHashIterator extends THashPrimitiveIterator implements TDoubleLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleLongHashMap we will be iterating over. + */ + TDoubleLongHashIterator(TDoubleLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleLongMap)) { + return false; + } + TDoubleLongMap that = (TDoubleLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + long val = in.readLong(); + put(key, val); + } + } +} // TDoubleLongHashMap diff --git a/src/gnu/trove/map/hash/TDoubleObjectHashMap.java b/src/gnu/trove/map/hash/TDoubleObjectHashMap.java new file mode 100644 index 0000000..18ad697 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TDoubleObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TDoubleObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.TDoubleObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TDoubleSet; +import gnu.trove.TDoubleCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for double keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TDoubleObjectHashMap extends TDoubleHash implements TDoubleObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TDoubleObjectProcedure PUT_ALL_PROC = new TDoubleObjectProcedure() { + @Override + public boolean execute(double key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected double no_entry_key; + + /** + * Creates a new TDoubleObjectHashMap instance with the default + * capacity and load factor. + */ + public TDoubleObjectHashMap() { + super(); + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TDoubleObjectHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TDoubleObjectHashMap(int initialCapacity, float loadFactor, double noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TDoubleObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TDoubleObjectMap to be copied. + */ + public TDoubleObjectHashMap(TDoubleObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(double key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(double key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(double key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(double key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public double[] keys() { + double[] keys = new double[size()]; + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public double[] keys(double[] dest) { + if (dest.length < _size) { + dest = new double[_size]; + } + + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TDoubleObjectIterator iterator() { + return new TDoubleObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TDoubleObjectProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TDoubleObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleObjectMap)) { + return false; + } + TDoubleObjectMap that = (TDoubleObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TDoubleObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + double key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleHashIterator(TDoubleObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return null != TDoubleObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TDoubleObjectHashMap.this.containsKey(((Double) element).doubleValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + if (collection == this) { + return true; + } + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TDoubleHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** the collection on which the iterator operates */ + private final TDoubleHash _hash; + + /** {@inheritDoc} */ + public TDoubleHashIterator(TDoubleHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TDoubleObjectValueHashIterator(TDoubleObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TDoubleObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TDoubleObjectHashMap _map; + + public TDoubleObjectValueHashIterator(TDoubleObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TDoubleObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TDoubleObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TDoubleObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleObjectHashIterator extends THashPrimitiveIterator implements TDoubleObjectIterator { + + /** the collection being iterated over */ + private final TDoubleObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TDoubleObjectHashIterator(TDoubleObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeDouble(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TDoubleObjectHashMap diff --git a/src/gnu/trove/map/hash/TDoubleShortHashMap.java b/src/gnu/trove/map/hash/TDoubleShortHashMap.java new file mode 100644 index 0000000..3cfeea9 --- /dev/null +++ b/src/gnu/trove/map/hash/TDoubleShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TDoubleShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for double keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TDoubleShortHashMap extends TDoubleShortHash implements TDoubleShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TDoubleShortHashMap instance with the default + * capacity and load factor. + */ + public TDoubleShortHashMap() { + super(); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TDoubleShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TDoubleShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a double value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TDoubleShortHashMap(int initialCapacity, float loadFactor, double noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TDoubleShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a double array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TDoubleShortHashMap(double[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TDoubleShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TDoubleShortMap that will be duplicated. + */ + public TDoubleShortHashMap(TDoubleShortMap map) { + super(map.size()); + if (map instanceof TDoubleShortHashMap) { + TDoubleShortHashMap hashmap = (TDoubleShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(double key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(double key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(double key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().doubleValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TDoubleShortMap map) { + ensureCapacity(map.size()); + TDoubleShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(double key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(double key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TDoubleSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public double[] keys() { + double[] keys = new double[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + double[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public double[] keys(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(double key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TDoubleShortIterator iterator() { + return new TDoubleShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TDoubleProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TDoubleShortProcedure procedure) { + byte[] states = _states; + double[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TDoubleShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + double[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(double key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(double key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(double key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TDoubleSet { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleShortKeyHashIterator(TDoubleShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TDoubleShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TDoubleShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TDoubleShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + return no_entry_value != TDoubleShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TDoubleShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TDoubleShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TDoubleShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TDoubleShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + final TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TDoubleShortValueHashIterator(TDoubleShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TDoubleShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TDoubleShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TDoubleShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + double[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TDoubleShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TDoubleShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TDoubleShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TDoubleShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TDoubleShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TDoubleShortKeyHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TDoubleShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TDoubleShortHashIterator extends THashPrimitiveIterator implements TDoubleShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TDoubleShortHashMap we will be iterating over. + */ + TDoubleShortHashIterator(TDoubleShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public double key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TDoubleShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleShortMap)) { + return false; + } + TDoubleShortMap that = (TDoubleShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + double key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TDoubleShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(double key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + double key = in.readDouble(); + short val = in.readShort(); + put(key, val); + } + } +} // TDoubleShortHashMap diff --git a/src/gnu/trove/map/hash/TFloatByteHashMap.java b/src/gnu/trove/map/hash/TFloatByteHashMap.java new file mode 100644 index 0000000..82bff6a --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatByteHashMap extends TFloatByteHash implements TFloatByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TFloatByteHashMap instance with the default + * capacity and load factor. + */ + public TFloatByteHashMap() { + super(); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TFloatByteHashMap(int initialCapacity, float loadFactor, float noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TFloatByteHashMap(float[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatByteMap that will be duplicated. + */ + public TFloatByteHashMap(TFloatByteMap map) { + super(map.size()); + if (map instanceof TFloatByteHashMap) { + TFloatByteHashMap hashmap = (TFloatByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(float key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(float key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(float key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatByteMap map) { + ensureCapacity(map.size()); + TFloatByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(float key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatByteIterator iterator() { + return new TFloatByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatByteProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(float key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatByteKeyHashIterator(TFloatByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TFloatByteValueHashIterator(TFloatByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TFloatByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TFloatByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TFloatByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TFloatByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TFloatByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TFloatByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatByteKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatByteHashIterator extends THashPrimitiveIterator implements TFloatByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatByteHashMap we will be iterating over. + */ + TFloatByteHashIterator(TFloatByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatByteMap)) { + return false; + } + TFloatByteMap that = (TFloatByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + byte val = in.readByte(); + put(key, val); + } + } +} // TFloatByteHashMap diff --git a/src/gnu/trove/map/hash/TFloatCharHashMap.java b/src/gnu/trove/map/hash/TFloatCharHashMap.java new file mode 100644 index 0000000..e8ddba2 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatCharHashMap extends TFloatCharHash implements TFloatCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TFloatCharHashMap instance with the default + * capacity and load factor. + */ + public TFloatCharHashMap() { + super(); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TFloatCharHashMap(int initialCapacity, float loadFactor, float noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TFloatCharHashMap(float[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatCharMap that will be duplicated. + */ + public TFloatCharHashMap(TFloatCharMap map) { + super(map.size()); + if (map instanceof TFloatCharHashMap) { + TFloatCharHashMap hashmap = (TFloatCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(float key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(float key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(float key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatCharMap map) { + ensureCapacity(map.size()); + TFloatCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(float key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatCharIterator iterator() { + return new TFloatCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatCharProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(float key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatCharKeyHashIterator(TFloatCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TFloatCharValueHashIterator(TFloatCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TFloatCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TFloatCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TFloatCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TFloatCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TFloatCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TFloatCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatCharKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatCharHashIterator extends THashPrimitiveIterator implements TFloatCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatCharHashMap we will be iterating over. + */ + TFloatCharHashIterator(TFloatCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatCharMap)) { + return false; + } + TFloatCharMap that = (TFloatCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + char val = in.readChar(); + put(key, val); + } + } +} // TFloatCharHashMap diff --git a/src/gnu/trove/map/hash/TFloatDoubleHashMap.java b/src/gnu/trove/map/hash/TFloatDoubleHashMap.java new file mode 100644 index 0000000..625007d --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatDoubleHashMap extends TFloatDoubleHash implements TFloatDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TFloatDoubleHashMap instance with the default + * capacity and load factor. + */ + public TFloatDoubleHashMap() { + super(); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TFloatDoubleHashMap(int initialCapacity, float loadFactor, float noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TFloatDoubleHashMap(float[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatDoubleMap that will be duplicated. + */ + public TFloatDoubleHashMap(TFloatDoubleMap map) { + super(map.size()); + if (map instanceof TFloatDoubleHashMap) { + TFloatDoubleHashMap hashmap = (TFloatDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(float key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(float key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(float key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatDoubleMap map) { + ensureCapacity(map.size()); + TFloatDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(float key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatDoubleIterator iterator() { + return new TFloatDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatDoubleProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(float key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatDoubleKeyHashIterator(TFloatDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TFloatDoubleValueHashIterator(TFloatDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TFloatDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TFloatDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TFloatDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TFloatDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TFloatDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TFloatDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatDoubleKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatDoubleHashIterator extends THashPrimitiveIterator implements TFloatDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatDoubleHashMap we will be iterating over. + */ + TFloatDoubleHashIterator(TFloatDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatDoubleMap)) { + return false; + } + TFloatDoubleMap that = (TFloatDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + double val = in.readDouble(); + put(key, val); + } + } +} // TFloatDoubleHashMap diff --git a/src/gnu/trove/map/hash/TFloatFloatHashMap.java b/src/gnu/trove/map/hash/TFloatFloatHashMap.java new file mode 100644 index 0000000..68a68ae --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatFloatHashMap extends TFloatFloatHash implements TFloatFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TFloatFloatHashMap instance with the default + * capacity and load factor. + */ + public TFloatFloatHashMap() { + super(); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TFloatFloatHashMap(int initialCapacity, float loadFactor, float noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TFloatFloatHashMap(float[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatFloatMap that will be duplicated. + */ + public TFloatFloatHashMap(TFloatFloatMap map) { + super(map.size()); + if (map instanceof TFloatFloatHashMap) { + TFloatFloatHashMap hashmap = (TFloatFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(float key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(float key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(float key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatFloatMap map) { + ensureCapacity(map.size()); + TFloatFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(float key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatFloatIterator iterator() { + return new TFloatFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatFloatProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(float key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatFloatKeyHashIterator(TFloatFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatFloatValueHashIterator(TFloatFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatFloatKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatFloatHashIterator extends THashPrimitiveIterator implements TFloatFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatFloatHashMap we will be iterating over. + */ + TFloatFloatHashIterator(TFloatFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatFloatMap)) { + return false; + } + TFloatFloatMap that = (TFloatFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + float val = in.readFloat(); + put(key, val); + } + } +} // TFloatFloatHashMap diff --git a/src/gnu/trove/map/hash/TFloatIntHashMap.java b/src/gnu/trove/map/hash/TFloatIntHashMap.java new file mode 100644 index 0000000..a0b81f7 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatIntHashMap extends TFloatIntHash implements TFloatIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TFloatIntHashMap instance with the default + * capacity and load factor. + */ + public TFloatIntHashMap() { + super(); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TFloatIntHashMap(int initialCapacity, float loadFactor, float noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TFloatIntHashMap(float[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatIntMap that will be duplicated. + */ + public TFloatIntHashMap(TFloatIntMap map) { + super(map.size()); + if (map instanceof TFloatIntHashMap) { + TFloatIntHashMap hashmap = (TFloatIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(float key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(float key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(float key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatIntMap map) { + ensureCapacity(map.size()); + TFloatIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(float key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatIntIterator iterator() { + return new TFloatIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatIntProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(float key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatIntKeyHashIterator(TFloatIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TFloatIntValueHashIterator(TFloatIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TFloatIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TFloatIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TFloatIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TFloatIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TFloatIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TFloatIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatIntKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatIntHashIterator extends THashPrimitiveIterator implements TFloatIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatIntHashMap we will be iterating over. + */ + TFloatIntHashIterator(TFloatIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatIntMap)) { + return false; + } + TFloatIntMap that = (TFloatIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + int val = in.readInt(); + put(key, val); + } + } +} // TFloatIntHashMap diff --git a/src/gnu/trove/map/hash/TFloatLongHashMap.java b/src/gnu/trove/map/hash/TFloatLongHashMap.java new file mode 100644 index 0000000..fa4a77e --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatLongHashMap extends TFloatLongHash implements TFloatLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TFloatLongHashMap instance with the default + * capacity and load factor. + */ + public TFloatLongHashMap() { + super(); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TFloatLongHashMap(int initialCapacity, float loadFactor, float noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TFloatLongHashMap(float[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatLongMap that will be duplicated. + */ + public TFloatLongHashMap(TFloatLongMap map) { + super(map.size()); + if (map instanceof TFloatLongHashMap) { + TFloatLongHashMap hashmap = (TFloatLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(float key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(float key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(float key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatLongMap map) { + ensureCapacity(map.size()); + TFloatLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(float key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatLongIterator iterator() { + return new TFloatLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatLongProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(float key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatLongKeyHashIterator(TFloatLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TFloatLongValueHashIterator(TFloatLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TFloatLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TFloatLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TFloatLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TFloatLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TFloatLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TFloatLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatLongKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatLongHashIterator extends THashPrimitiveIterator implements TFloatLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatLongHashMap we will be iterating over. + */ + TFloatLongHashIterator(TFloatLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatLongMap)) { + return false; + } + TFloatLongMap that = (TFloatLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + long val = in.readLong(); + put(key, val); + } + } +} // TFloatLongHashMap diff --git a/src/gnu/trove/map/hash/TFloatObjectHashMap.java b/src/gnu/trove/map/hash/TFloatObjectHashMap.java new file mode 100644 index 0000000..0963fb5 --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TFloatObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TFloatObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.TFloatObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TFloatSet; +import gnu.trove.TFloatCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for float keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TFloatObjectHashMap extends TFloatHash implements TFloatObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TFloatObjectProcedure PUT_ALL_PROC = new TFloatObjectProcedure() { + @Override + public boolean execute(float key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected float no_entry_key; + + /** + * Creates a new TFloatObjectHashMap instance with the default + * capacity and load factor. + */ + public TFloatObjectHashMap() { + super(); + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TFloatObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TFloatObjectHashMap(int initialCapacity, float loadFactor, float noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TFloatObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TFloatObjectMap to be copied. + */ + public TFloatObjectHashMap(TFloatObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(float key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(float key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(float key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(float key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public float[] keys() { + float[] keys = new float[size()]; + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public float[] keys(float[] dest) { + if (dest.length < _size) { + dest = new float[_size]; + } + + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TFloatObjectIterator iterator() { + return new TFloatObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TFloatObjectProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TFloatObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatObjectMap)) { + return false; + } + TFloatObjectMap that = (TFloatObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TFloatObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + float key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatHashIterator(TFloatObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return null != TFloatObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TFloatObjectHashMap.this.containsKey(((Float) element).floatValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + if (collection == this) { + return true; + } + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TFloatHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** the collection on which the iterator operates */ + private final TFloatHash _hash; + + /** {@inheritDoc} */ + public TFloatHashIterator(TFloatHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TFloatObjectValueHashIterator(TFloatObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TFloatObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TFloatObjectHashMap _map; + + public TFloatObjectValueHashIterator(TFloatObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TFloatObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TFloatObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TFloatObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatObjectHashIterator extends THashPrimitiveIterator implements TFloatObjectIterator { + + /** the collection being iterated over */ + private final TFloatObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TFloatObjectHashIterator(TFloatObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeFloat(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TFloatObjectHashMap diff --git a/src/gnu/trove/map/hash/TFloatShortHashMap.java b/src/gnu/trove/map/hash/TFloatShortHashMap.java new file mode 100644 index 0000000..f1e6dce --- /dev/null +++ b/src/gnu/trove/map/hash/TFloatShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TFloatShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for float keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TFloatShortHashMap extends TFloatShortHash implements TFloatShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TFloatShortHashMap instance with the default + * capacity and load factor. + */ + public TFloatShortHashMap() { + super(); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TFloatShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TFloatShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TFloatShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a float value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TFloatShortHashMap(int initialCapacity, float loadFactor, float noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TFloatShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a float array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TFloatShortHashMap(float[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TFloatShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TFloatShortMap that will be duplicated. + */ + public TFloatShortHashMap(TFloatShortMap map) { + super(map.size()); + if (map instanceof TFloatShortHashMap) { + TFloatShortHashMap hashmap = (TFloatShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(float key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(float key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(float key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().floatValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TFloatShortMap map) { + ensureCapacity(map.size()); + TFloatShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(float key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(float key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TFloatSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public float[] keys() { + float[] keys = new float[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + float[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public float[] keys(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(float key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TFloatShortIterator iterator() { + return new TFloatShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TFloatProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TFloatShortProcedure procedure) { + byte[] states = _states; + float[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TFloatShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + float[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(float key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(float key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(float key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TFloatSet { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatShortKeyHashIterator(TFloatShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TFloatShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TFloatShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TFloatShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + return no_entry_value != TFloatShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TFloatShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TFloatShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TFloatShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TFloatShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + final TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TFloatShortValueHashIterator(TFloatShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TFloatShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TFloatShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TFloatShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + float[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TFloatShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TFloatShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TFloatShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TFloatShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TFloatShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TFloatShortKeyHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TFloatShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TFloatShortHashIterator extends THashPrimitiveIterator implements TFloatShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TFloatShortHashMap we will be iterating over. + */ + TFloatShortHashIterator(TFloatShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public float key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TFloatShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatShortMap)) { + return false; + } + TFloatShortMap that = (TFloatShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + float key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TFloatShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(float key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + float key = in.readFloat(); + short val = in.readShort(); + put(key, val); + } + } +} // TFloatShortHashMap diff --git a/src/gnu/trove/map/hash/THashMap.java b/src/gnu/trove/map/hash/THashMap.java new file mode 100644 index 0000000..483d5d1 --- /dev/null +++ b/src/gnu/trove/map/hash/THashMap.java @@ -0,0 +1,914 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.function.TObjectFunction; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.map.TMap; +import gnu.trove.procedure.TObjectObjectProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.util.*; + +/** + * An implementation of the Map interface which uses an open addressed hash + * table to store its contents. + *

+ * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: THashMap.java,v 1.1.2.8 2010/03/02 04:09:50 robeden Exp $ + */ + +public class THashMap extends TObjectHash implements TMap, Externalizable { + + static final long serialVersionUID = 1L; + + /** + * the values of the map + */ + protected transient V[] _values; + + /** + * Creates a new THashMap instance with the default capacity and + * load factor. + */ + public THashMap() { + super(); + } + + /** + * Creates a new THashMap instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashMap instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashMap instance which contains the key/value + * pairs in map. + * + * @param map + * a Map value + */ + public THashMap(Map map) { + this(map.size()); + putAll(map); + } + + /** + * Creates a new THashMap instance which contains the key/value + * pairs in map. + * + * @param map + * a Map value + */ + public THashMap(THashMap map) { + this(map.size()); + putAll(map); + } + + /** + * initialize the value array of the map. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + // noinspection unchecked + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** + * Inserts a key/value pair into the map. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V put(K key, V value) { + // insertKey() inserts the key if a slot if found and returns the index + int index = insertKey(key); + return doPut(value, index); + } + + /** + * Inserts a key/value pair into the map if the specified key is not already + * associated with a value. + * + * @param key + * an Object value + * @param value + * an Object value + * @return the previous value associated with key, or {@code null} if + * none was found. + */ + @Override + public V putIfAbsent(K key, V value) { + // insertKey() inserts the key if a slot if found and returns the index + int index = insertKey(key); + if (index < 0) { + return _values[-index - 1]; + } + return doPut(value, index); + } + + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + @SuppressWarnings({ "unchecked", "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Map)) { + return false; + } + Map that = (Map) other; + if (that.size() != this.size()) { + return false; + } + return forEachEntry(new EqProcedure(that)); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEachEntry(p); + return p.getHashCode(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, V value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + private final class HashProcedure implements TObjectObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(K key, V value) { + h += HashFunctions.hash(key) ^ (value == null ? 0 : value.hashCode()); + return true; + } + } + + private final class EqProcedure implements TObjectObjectProcedure { + private final Map _otherMap; + + EqProcedure(Map otherMap) { + _otherMap = otherMap; + } + + @Override + public final boolean execute(K key, V value) { + // Check to make sure the key is there. This avoids problems that come up with + // null values. Since it is only caused in that cause, only do this when the + // value is null (to avoid extra work). + if (value == null && !_otherMap.containsKey(key)) { + return false; + } + + V oValue = _otherMap.get(key); + return oValue == value || (oValue != null && THashMap.this.equals(oValue, value)); + } + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TObjectObjectProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectObjectProcedure procedure) { + Object[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TObjectObjectProcedure procedure) { + boolean modified = false; + Object[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TObjectFunction value + */ + @Override + public void transformValues(TObjectFunction function) { + V[] values = _values; + Object[] set = _set; + for (int i = values.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldKeys[] = _set; + V oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = (V[]) new Object[newCapacity]; + + // Process entries from the old array, skipping free and removed slots. Put the + // values into the appropriate place in the new array. + int count = 0; + for (int i = oldCapacity; i-- > 0;) { + Object o = oldKeys[i]; + + if (o == FREE || o == REMOVED) + continue; + + int index = insertKey((K) o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldKeys); + } + _values[index] = oldVals[i]; + // + count++; + } + + // Last check: size before and after should be the same + reportPotentialConcurrentMod(size(), oldSize); + } + + /** + * retrieves the value for key + * + * @param key + * an Object value + * @return the value of key or null if no such mapping exists. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V get(Object key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + /** + * Empties the map. + */ + @Override + public void clear() { + if (size() == 0) { + return; // optimization + } + + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + /** + * Deletes a key/value pair from the map. + * + * @param key + * an Object value + * @return an Object value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public V remove(Object key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * removes the mapping at index from the map. + * + * @param index + * an int value + */ + @Override + public void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + /** + * Returns a view on the values of the map. + * + * @return a Collection value + */ + @Override + public Collection values() { + return new ValueView(); + } + + /** + * returns a Set view on the keys of the map. + * + * @return a Set value + */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** + * Returns a Set view on the entries of the map. + * + * @return a Set value + */ + @Override + public Set> entrySet() { + return new EntryView(); + } + + /** + * checks for the presence of val in the values of the map. + * + * @param val + * an Object value + * @return a boolean value + */ + @Override + public boolean containsValue(Object val) { + Object[] set = _set; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && val == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && (val == vals[i] || equals(val, vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** + * checks for the present of key in the keys of the map. + * + * @param key + * an Object value + * @return a boolean value + */ + @Override + public boolean containsKey(Object key) { + // noinspection unchecked + return contains(key); + } + + /** + * copies the key/value mappings in map into this map. + * + * @param map + * a Map value + */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry e : map.entrySet()) { + put(e.getKey(), e.getValue()); + } + } + + /** + * a view onto the values of the map. + */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(THashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + Object[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && value == values[i] + || (null != values[i] && THashMap.this.equals(values[i], value))) { + + removeAt(i); + return true; + } + } + + return false; + } + } + + /** + * a view onto the entries of the map. + */ + protected class EntryView extends MapBackedView> { + + private final class EntryIterator extends TObjectHashIterator { + + EntryIterator(THashMap map) { + super(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Entry objectAtIndex(final int index) { + return new Entry((K) _set[index], _values[index], index); + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator> iterator() { + return new EntryIterator(THashMap.this); + } + + @Override + public boolean removeElement(Map.Entry entry) { + if (entry == null) + return false; + + // have to effectively reimplement Map.remove here + // because we need to return true/false depending on + // whether the removal took place. Since the Entry's + // value can be null, this means that we can't rely + // on the value of the object returned by Map.remove() + // to determine whether a deletion actually happened. + // + // Note also that the deletion is only legal if + // both the key and the value match. + V val; + int index; + + K key = keyForEntry(entry); + index = index(key); + if (index >= 0) { + val = valueForEntry(entry); + if (val == _values[index] || (null != val && THashMap.this.equals(val, _values[index]))) { + removeAt(index); // clear key,state; adjust size + return true; + } + } + return false; + } + + @Override + public boolean containsElement(Map.Entry entry) { + V val = get(keyForEntry(entry)); + V entryValue = entry.getValue(); + return entryValue == val || (null != val && THashMap.this.equals(val, entryValue)); + } + + protected V valueForEntry(Map.Entry entry) { + return entry.getValue(); + } + + protected K keyForEntry(Map.Entry entry) { + return entry.getKey(); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + try { + return removeElement((E) o); + } catch (ClassCastException ex) { + return false; + } + } + + // public boolean containsAll( Collection collection ) { + // for ( Object element : collection ) { + // if ( !contains( element ) ) { + // return false; + // } + // } + // return true; + // } + + @Override + public void clear() { + THashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return THashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return THashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + Iterator i = iterator(); + if (!i.hasNext()) + return "{}"; + + StringBuilder sb = new StringBuilder(); + sb.append('{'); + for (;;) { + E e = i.next(); + sb.append(e == this ? "(this Collection)" : e); + if (!i.hasNext()) + return sb.append('}').toString(); + sb.append(", "); + } + } + } + + /** + * a view onto the keys of the map. + */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(THashMap.this); + } + + @Override + public boolean removeElement(K key) { + return null != THashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return THashMap.this.contains(key); + } + } + + final class Entry implements Map.Entry { + + private K key; + private V val; + private final int index; + + Entry(final K key, V value, final int index) { + this.key = key; + this.val = value; + this.index = index; + } + + @Override + public K getKey() { + return key; + } + + @Override + public V getValue() { + return val; + } + + @Override + public V setValue(V o) { + if (_values[index] != val) { + throw new ConcurrentModificationException(); + } + // need to return previous value + V retval = val; + // update this entry's value, in case setValue is called again + _values[index] = o; + val = o; + return retval; + } + + @Override + public boolean equals(Object o) { + if (o instanceof Map.Entry) { + Map.Entry e1 = this; + Map.Entry e2 = (Map.Entry) o; + return (THashMap.this.equals(e1.getKey(), e2.getKey())) + && (THashMap.this.equals(e1.getValue(), e1.getValue())); + } + return false; + } + + @Override + public int hashCode() { + return (getKey() == null ? 0 : getKey().hashCode()) ^ (getValue() == null ? 0 : getValue().hashCode()); + } + + @Override + public String toString() { + return key + "=" + val; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + // noinspection unchecked + V val = (V) in.readObject(); + put(key, val); + } + } +} // THashMap diff --git a/src/gnu/trove/map/hash/TIntByteHashMap.java b/src/gnu/trove/map/hash/TIntByteHashMap.java new file mode 100644 index 0000000..6b8b159 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntByteHashMap extends TIntByteHash implements TIntByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TIntByteHashMap instance with the default capacity + * and load factor. + */ + public TIntByteHashMap() { + super(); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TIntByteHashMap(int initialCapacity, float loadFactor, int noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TIntByteHashMap(int[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntByteMap that will be duplicated. + */ + public TIntByteHashMap(TIntByteMap map) { + super(map.size()); + if (map instanceof TIntByteHashMap) { + TIntByteHashMap hashmap = (TIntByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(int key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(int key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(int key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntByteMap map) { + ensureCapacity(map.size()); + TIntByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(int key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntByteIterator iterator() { + return new TIntByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntByteProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(int key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntByteKeyHashIterator(TIntByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TIntByteValueHashIterator(TIntByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TIntByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TIntByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TIntByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TIntByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TIntByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TIntByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntByteKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntByteHashIterator extends THashPrimitiveIterator implements TIntByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntByteHashMap we will be iterating over. + */ + TIntByteHashIterator(TIntByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntByteMap)) { + return false; + } + TIntByteMap that = (TIntByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + byte val = in.readByte(); + put(key, val); + } + } +} // TIntByteHashMap diff --git a/src/gnu/trove/map/hash/TIntCharHashMap.java b/src/gnu/trove/map/hash/TIntCharHashMap.java new file mode 100644 index 0000000..13aba88 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntCharHashMap extends TIntCharHash implements TIntCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TIntCharHashMap instance with the default capacity + * and load factor. + */ + public TIntCharHashMap() { + super(); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TIntCharHashMap(int initialCapacity, float loadFactor, int noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TIntCharHashMap(int[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntCharMap that will be duplicated. + */ + public TIntCharHashMap(TIntCharMap map) { + super(map.size()); + if (map instanceof TIntCharHashMap) { + TIntCharHashMap hashmap = (TIntCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(int key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(int key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(int key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntCharMap map) { + ensureCapacity(map.size()); + TIntCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(int key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntCharIterator iterator() { + return new TIntCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntCharProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(int key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntCharKeyHashIterator(TIntCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TIntCharValueHashIterator(TIntCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TIntCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TIntCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TIntCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TIntCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TIntCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TIntCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntCharKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntCharHashIterator extends THashPrimitiveIterator implements TIntCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntCharHashMap we will be iterating over. + */ + TIntCharHashIterator(TIntCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntCharMap)) { + return false; + } + TIntCharMap that = (TIntCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + char val = in.readChar(); + put(key, val); + } + } +} // TIntCharHashMap diff --git a/src/gnu/trove/map/hash/TIntDoubleHashMap.java b/src/gnu/trove/map/hash/TIntDoubleHashMap.java new file mode 100644 index 0000000..8914c53 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntDoubleHashMap extends TIntDoubleHash implements TIntDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TIntDoubleHashMap instance with the default + * capacity and load factor. + */ + public TIntDoubleHashMap() { + super(); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TIntDoubleHashMap(int initialCapacity, float loadFactor, int noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TIntDoubleHashMap(int[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntDoubleMap that will be duplicated. + */ + public TIntDoubleHashMap(TIntDoubleMap map) { + super(map.size()); + if (map instanceof TIntDoubleHashMap) { + TIntDoubleHashMap hashmap = (TIntDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(int key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(int key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(int key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntDoubleMap map) { + ensureCapacity(map.size()); + TIntDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(int key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntDoubleIterator iterator() { + return new TIntDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntDoubleProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(int key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntDoubleKeyHashIterator(TIntDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TIntDoubleValueHashIterator(TIntDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TIntDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TIntDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TIntDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TIntDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TIntDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TIntDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntDoubleKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntDoubleHashIterator extends THashPrimitiveIterator implements TIntDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntDoubleHashMap we will be iterating over. + */ + TIntDoubleHashIterator(TIntDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntDoubleMap)) { + return false; + } + TIntDoubleMap that = (TIntDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + double val = in.readDouble(); + put(key, val); + } + } +} // TIntDoubleHashMap diff --git a/src/gnu/trove/map/hash/TIntFloatHashMap.java b/src/gnu/trove/map/hash/TIntFloatHashMap.java new file mode 100644 index 0000000..7b5c088 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntFloatHashMap extends TIntFloatHash implements TIntFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TIntFloatHashMap instance with the default + * capacity and load factor. + */ + public TIntFloatHashMap() { + super(); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TIntFloatHashMap(int initialCapacity, float loadFactor, int noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TIntFloatHashMap(int[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntFloatMap that will be duplicated. + */ + public TIntFloatHashMap(TIntFloatMap map) { + super(map.size()); + if (map instanceof TIntFloatHashMap) { + TIntFloatHashMap hashmap = (TIntFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(int key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(int key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(int key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntFloatMap map) { + ensureCapacity(map.size()); + TIntFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(int key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntFloatIterator iterator() { + return new TIntFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntFloatProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(int key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntFloatKeyHashIterator(TIntFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TIntFloatValueHashIterator(TIntFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TIntFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TIntFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TIntFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TIntFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TIntFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TIntFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntFloatKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntFloatHashIterator extends THashPrimitiveIterator implements TIntFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntFloatHashMap we will be iterating over. + */ + TIntFloatHashIterator(TIntFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntFloatMap)) { + return false; + } + TIntFloatMap that = (TIntFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + float val = in.readFloat(); + put(key, val); + } + } +} // TIntFloatHashMap diff --git a/src/gnu/trove/map/hash/TIntIntHashMap.java b/src/gnu/trove/map/hash/TIntIntHashMap.java new file mode 100644 index 0000000..fdb68d5 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntIntHashMap extends TIntIntHash implements TIntIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TIntIntHashMap instance with the default capacity + * and load factor. + */ + public TIntIntHashMap() { + super(); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TIntIntHashMap(int initialCapacity, float loadFactor, int noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TIntIntHashMap(int[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntIntMap that will be duplicated. + */ + public TIntIntHashMap(TIntIntMap map) { + super(map.size()); + if (map instanceof TIntIntHashMap) { + TIntIntHashMap hashmap = (TIntIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(int key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(int key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(int key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntIntMap map) { + ensureCapacity(map.size()); + TIntIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(int key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntIntIterator iterator() { + return new TIntIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntIntProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(int key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIntKeyHashIterator(TIntIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntIntValueHashIterator(TIntIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntIntKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntIntHashIterator extends THashPrimitiveIterator implements TIntIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntIntHashMap we will be iterating over. + */ + TIntIntHashIterator(TIntIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntIntMap)) { + return false; + } + TIntIntMap that = (TIntIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + int val = in.readInt(); + put(key, val); + } + } +} // TIntIntHashMap diff --git a/src/gnu/trove/map/hash/TIntLongHashMap.java b/src/gnu/trove/map/hash/TIntLongHashMap.java new file mode 100644 index 0000000..918cc65 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntLongHashMap extends TIntLongHash implements TIntLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TIntLongHashMap instance with the default capacity + * and load factor. + */ + public TIntLongHashMap() { + super(); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TIntLongHashMap(int initialCapacity, float loadFactor, int noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TIntLongHashMap(int[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntLongMap that will be duplicated. + */ + public TIntLongHashMap(TIntLongMap map) { + super(map.size()); + if (map instanceof TIntLongHashMap) { + TIntLongHashMap hashmap = (TIntLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(int key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(int key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(int key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntLongMap map) { + ensureCapacity(map.size()); + TIntLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(int key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntLongIterator iterator() { + return new TIntLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntLongProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(int key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntLongKeyHashIterator(TIntLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TIntLongValueHashIterator(TIntLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TIntLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TIntLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TIntLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TIntLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TIntLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TIntLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntLongKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntLongHashIterator extends THashPrimitiveIterator implements TIntLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntLongHashMap we will be iterating over. + */ + TIntLongHashIterator(TIntLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntLongMap)) { + return false; + } + TIntLongMap that = (TIntLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + long val = in.readLong(); + put(key, val); + } + } +} // TIntLongHashMap diff --git a/src/gnu/trove/map/hash/TIntObjectHashMap.java b/src/gnu/trove/map/hash/TIntObjectHashMap.java new file mode 100644 index 0000000..91c0456 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntObjectHashMap.java @@ -0,0 +1,1000 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TIntObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TIntObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.TIntObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TIntSet; +import gnu.trove.TIntCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for int keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TIntObjectHashMap extends TIntHash implements TIntObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TIntObjectProcedure PUT_ALL_PROC = new TIntObjectProcedure() { + @Override + public boolean execute(int key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected int no_entry_key; + + /** + * Creates a new TIntObjectHashMap instance with the default + * capacity and load factor. + */ + public TIntObjectHashMap() { + super(); + } + + /** + * Creates a new TIntObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TIntObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TIntObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TIntObjectHashMap(int initialCapacity, float loadFactor, int noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TIntObjectHashMap that contains the entries in the + * map passed to it. + * + * @param map + * the TIntObjectMap to be copied. + */ + public TIntObjectHashMap(TIntObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + @Override + public int getNoEntryKey() { + return no_entry_key; + } + + @Override + public boolean containsKey(int key) { + return contains(key); + } + + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + @Override + public V get(int key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + @Override + public V put(int key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + @Override + public V putIfAbsent(int key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + @Override + public V remove(int key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + @Override + public void putAll(TIntObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + @Override + public TIntSet keySet() { + return new KeyView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public int[] keys() { + int[] keys = new int[size()]; + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public int[] keys(int[] dest) { + if (dest.length < _size) { + dest = new int[_size]; + } + + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + @Override + public Collection valueCollection() { + return new ValueView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + @Override + public TIntObjectIterator iterator() { + return new TIntObjectHashIterator(this); + } + + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TIntObjectProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TIntObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntObjectMap)) { + return false; + } + TIntObjectMap that = (TIntObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TIntObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + int key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TIntSet { + + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + @Override + public int size() { + return _size; + } + + @Override + public boolean isEmpty() { + return _size == 0; + } + + @Override + public boolean contains(int entry) { + return TIntObjectHashMap.this.containsKey(entry); + } + + @Override + public TIntIterator iterator() { + return new TIntHashIterator(TIntObjectHashMap.this); + } + + @Override + public int[] toArray() { + return keys(); + } + + @Override + public int[] toArray(int[] dest) { + return keys(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(int entry) { + return null != TIntObjectHashMap.this.remove(entry); + } + + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TIntObjectHashMap.this.containsKey(((Integer) element).intValue())) { + + return false; + } + } + return true; + } + + @Override + public boolean containsAll(TIntCollection collection) { + if (collection == this) { + return true; + } + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + @Override + public boolean removeAll(TIntCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + @Override + public void clear() { + TIntObjectHashMap.this.clear(); + } + + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntObjectHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TIntHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** the collection on which the iterator operates */ + private final TIntHash _hash; + + public TIntHashIterator(TIntHash hash) { + super(hash); + this._hash = hash; + } + + @Override + public int next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TIntObjectValueHashIterator(TIntObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TIntObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TIntObjectHashMap _map; + + public TIntObjectValueHashIterator(TIntObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TIntObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TIntObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TIntObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntObjectHashIterator extends THashPrimitiveIterator implements TIntObjectIterator { + + /** the collection being iterated over */ + private final TIntObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TIntObjectHashIterator(TIntObjectHashMap map) { + super(map); + this._map = map; + } + + @Override + public void advance() { + moveToNextIndex(); + } + + @Override + public int key() { + return _map._set[_index]; + } + + @Override + public V value() { + return _map._values[_index]; + } + + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeInt(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TIntObjectHashMap diff --git a/src/gnu/trove/map/hash/TIntShortHashMap.java b/src/gnu/trove/map/hash/TIntShortHashMap.java new file mode 100644 index 0000000..70e09b1 --- /dev/null +++ b/src/gnu/trove/map/hash/TIntShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TIntShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for int keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TIntShortHashMap extends TIntShortHash implements TIntShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TIntShortHashMap instance with the default + * capacity and load factor. + */ + public TIntShortHashMap() { + super(); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TIntShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TIntShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TIntShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a int value that represents null for the Key + * set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TIntShortHashMap(int initialCapacity, float loadFactor, int noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TIntShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a int array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TIntShortHashMap(int[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TIntShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TIntShortMap that will be duplicated. + */ + public TIntShortHashMap(TIntShortMap map) { + super(map.size()); + if (map instanceof TIntShortHashMap) { + TIntShortHashMap hashmap = (TIntShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(int key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(int key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(int key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().intValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TIntShortMap map) { + ensureCapacity(map.size()); + TIntShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(int key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(int key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TIntSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public int[] keys() { + int[] keys = new int[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + int[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public int[] keys(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(int key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TIntShortIterator iterator() { + return new TIntShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TIntProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TIntShortProcedure procedure) { + byte[] states = _states; + int[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TIntShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + int[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(int key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(int key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(int key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TIntSet { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntShortKeyHashIterator(TIntShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TIntShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TIntShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TIntShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + return no_entry_value != TIntShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TIntShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TIntShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TIntShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TIntShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + final TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TIntShortValueHashIterator(TIntShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TIntShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TIntShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TIntShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + int[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TIntShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TIntShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TIntShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TIntShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TIntShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TIntShortKeyHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TIntShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TIntShortHashIterator extends THashPrimitiveIterator implements TIntShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TIntShortHashMap we will be iterating over. + */ + TIntShortHashIterator(TIntShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public int key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TIntShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntShortMap)) { + return false; + } + TIntShortMap that = (TIntShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + int key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TIntShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(int key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + int key = in.readInt(); + short val = in.readShort(); + put(key, val); + } + } +} // TIntShortHashMap diff --git a/src/gnu/trove/map/hash/TLongByteHashMap.java b/src/gnu/trove/map/hash/TLongByteHashMap.java new file mode 100644 index 0000000..177ba00 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongByteHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongByteHashMap extends TLongByteHash implements TLongByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TLongByteHashMap instance with the default + * capacity and load factor. + */ + public TLongByteHashMap() { + super(); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TLongByteHashMap(int initialCapacity, float loadFactor, long noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a byte array containing the values. + */ + public TLongByteHashMap(long[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongByteMap that will be duplicated. + */ + public TLongByteHashMap(TLongByteMap map) { + super(map.size()); + if (map instanceof TLongByteHashMap) { + TLongByteHashMap hashmap = (TLongByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(long key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(long key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(long key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongByteMap map) { + ensureCapacity(map.size()); + TLongByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(long key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongByteIterator iterator() { + return new TLongByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongByteProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(long key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongByteKeyHashIterator(TLongByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TLongByteValueHashIterator(TLongByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TLongByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TLongByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TLongByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TLongByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TLongByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TLongByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongByteKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongByteHashIterator extends THashPrimitiveIterator implements TLongByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongByteHashMap we will be iterating over. + */ + TLongByteHashIterator(TLongByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongByteMap)) { + return false; + } + TLongByteMap that = (TLongByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + byte val = in.readByte(); + put(key, val); + } + } +} // TLongByteHashMap diff --git a/src/gnu/trove/map/hash/TLongCharHashMap.java b/src/gnu/trove/map/hash/TLongCharHashMap.java new file mode 100644 index 0000000..0a45bba --- /dev/null +++ b/src/gnu/trove/map/hash/TLongCharHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongCharHashMap extends TLongCharHash implements TLongCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TLongCharHashMap instance with the default + * capacity and load factor. + */ + public TLongCharHashMap() { + super(); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TLongCharHashMap(int initialCapacity, float loadFactor, long noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a char array containing the values. + */ + public TLongCharHashMap(long[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongCharMap that will be duplicated. + */ + public TLongCharHashMap(TLongCharMap map) { + super(map.size()); + if (map instanceof TLongCharHashMap) { + TLongCharHashMap hashmap = (TLongCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(long key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(long key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(long key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongCharMap map) { + ensureCapacity(map.size()); + TLongCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(long key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongCharIterator iterator() { + return new TLongCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongCharProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(long key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongCharKeyHashIterator(TLongCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TLongCharValueHashIterator(TLongCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TLongCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TLongCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TLongCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TLongCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TLongCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TLongCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongCharKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongCharHashIterator extends THashPrimitiveIterator implements TLongCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongCharHashMap we will be iterating over. + */ + TLongCharHashIterator(TLongCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongCharMap)) { + return false; + } + TLongCharMap that = (TLongCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + char val = in.readChar(); + put(key, val); + } + } +} // TLongCharHashMap diff --git a/src/gnu/trove/map/hash/TLongDoubleHashMap.java b/src/gnu/trove/map/hash/TLongDoubleHashMap.java new file mode 100644 index 0000000..fd67bd8 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongDoubleHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongDoubleHashMap extends TLongDoubleHash implements TLongDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TLongDoubleHashMap instance with the default + * capacity and load factor. + */ + public TLongDoubleHashMap() { + super(); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TLongDoubleHashMap(int initialCapacity, float loadFactor, long noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a double array containing the values. + */ + public TLongDoubleHashMap(long[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongDoubleMap that will be duplicated. + */ + public TLongDoubleHashMap(TLongDoubleMap map) { + super(map.size()); + if (map instanceof TLongDoubleHashMap) { + TLongDoubleHashMap hashmap = (TLongDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(long key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(long key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(long key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongDoubleMap map) { + ensureCapacity(map.size()); + TLongDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(long key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongDoubleIterator iterator() { + return new TLongDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongDoubleProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(long key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongDoubleKeyHashIterator(TLongDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TLongDoubleValueHashIterator(TLongDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TLongDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TLongDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TLongDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TLongDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TLongDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TLongDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongDoubleKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongDoubleHashIterator extends THashPrimitiveIterator implements TLongDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongDoubleHashMap we will be iterating over. + */ + TLongDoubleHashIterator(TLongDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongDoubleMap)) { + return false; + } + TLongDoubleMap that = (TLongDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + double val = in.readDouble(); + put(key, val); + } + } +} // TLongDoubleHashMap diff --git a/src/gnu/trove/map/hash/TLongFloatHashMap.java b/src/gnu/trove/map/hash/TLongFloatHashMap.java new file mode 100644 index 0000000..e5c47d1 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongFloatHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongFloatHashMap extends TLongFloatHash implements TLongFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TLongFloatHashMap instance with the default + * capacity and load factor. + */ + public TLongFloatHashMap() { + super(); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TLongFloatHashMap(int initialCapacity, float loadFactor, long noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a float array containing the values. + */ + public TLongFloatHashMap(long[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongFloatMap that will be duplicated. + */ + public TLongFloatHashMap(TLongFloatMap map) { + super(map.size()); + if (map instanceof TLongFloatHashMap) { + TLongFloatHashMap hashmap = (TLongFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(long key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(long key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(long key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongFloatMap map) { + ensureCapacity(map.size()); + TLongFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(long key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongFloatIterator iterator() { + return new TLongFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongFloatProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(long key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongFloatKeyHashIterator(TLongFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TLongFloatValueHashIterator(TLongFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TLongFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TLongFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TLongFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TLongFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TLongFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TLongFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongFloatKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongFloatHashIterator extends THashPrimitiveIterator implements TLongFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongFloatHashMap we will be iterating over. + */ + TLongFloatHashIterator(TLongFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongFloatMap)) { + return false; + } + TLongFloatMap that = (TLongFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + float val = in.readFloat(); + put(key, val); + } + } +} // TLongFloatHashMap diff --git a/src/gnu/trove/map/hash/TLongIntHashMap.java b/src/gnu/trove/map/hash/TLongIntHashMap.java new file mode 100644 index 0000000..48632ba --- /dev/null +++ b/src/gnu/trove/map/hash/TLongIntHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongIntHashMap extends TLongIntHash implements TLongIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TLongIntHashMap instance with the default capacity + * and load factor. + */ + public TLongIntHashMap() { + super(); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TLongIntHashMap(int initialCapacity, float loadFactor, long noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a int array containing the values. + */ + public TLongIntHashMap(long[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongIntMap that will be duplicated. + */ + public TLongIntHashMap(TLongIntMap map) { + super(map.size()); + if (map instanceof TLongIntHashMap) { + TLongIntHashMap hashmap = (TLongIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(long key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(long key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(long key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongIntMap map) { + ensureCapacity(map.size()); + TLongIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(long key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongIntIterator iterator() { + return new TLongIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongIntProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(long key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongIntKeyHashIterator(TLongIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TLongIntValueHashIterator(TLongIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TLongIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TLongIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TLongIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TLongIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TLongIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TLongIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongIntKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongIntHashIterator extends THashPrimitiveIterator implements TLongIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongIntHashMap we will be iterating over. + */ + TLongIntHashIterator(TLongIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongIntMap)) { + return false; + } + TLongIntMap that = (TLongIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + int val = in.readInt(); + put(key, val); + } + } +} // TLongIntHashMap diff --git a/src/gnu/trove/map/hash/TLongLongHashMap.java b/src/gnu/trove/map/hash/TLongLongHashMap.java new file mode 100644 index 0000000..915d53b --- /dev/null +++ b/src/gnu/trove/map/hash/TLongLongHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongLongHashMap extends TLongLongHash implements TLongLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TLongLongHashMap instance with the default + * capacity and load factor. + */ + public TLongLongHashMap() { + super(); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TLongLongHashMap(int initialCapacity, float loadFactor, long noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a long array containing the values. + */ + public TLongLongHashMap(long[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongLongMap that will be duplicated. + */ + public TLongLongHashMap(TLongLongMap map) { + super(map.size()); + if (map instanceof TLongLongHashMap) { + TLongLongHashMap hashmap = (TLongLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(long key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(long key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(long key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongLongMap map) { + ensureCapacity(map.size()); + TLongLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(long key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongLongIterator iterator() { + return new TLongLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongLongProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(long key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongLongKeyHashIterator(TLongLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongLongValueHashIterator(TLongLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongLongKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongLongHashIterator extends THashPrimitiveIterator implements TLongLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongLongHashMap we will be iterating over. + */ + TLongLongHashIterator(TLongLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongLongMap)) { + return false; + } + TLongLongMap that = (TLongLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + long val = in.readLong(); + put(key, val); + } + } +} // TLongLongHashMap diff --git a/src/gnu/trove/map/hash/TLongObjectHashMap.java b/src/gnu/trove/map/hash/TLongObjectHashMap.java new file mode 100644 index 0000000..9fe430c --- /dev/null +++ b/src/gnu/trove/map/hash/TLongObjectHashMap.java @@ -0,0 +1,1000 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TLongObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TLongObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.TLongObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TLongSet; +import gnu.trove.TLongCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for long keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TLongObjectHashMap extends TLongHash implements TLongObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TLongObjectProcedure PUT_ALL_PROC = new TLongObjectProcedure() { + @Override + public boolean execute(long key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected long no_entry_key; + + /** + * Creates a new TLongObjectHashMap instance with the default + * capacity and load factor. + */ + public TLongObjectHashMap() { + super(); + } + + /** + * Creates a new TLongObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TLongObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TLongObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TLongObjectHashMap(int initialCapacity, float loadFactor, long noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TLongObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TLongObjectMap to be copied. + */ + public TLongObjectHashMap(TLongObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + @Override + public long getNoEntryKey() { + return no_entry_key; + } + + @Override + public boolean containsKey(long key) { + return contains(key); + } + + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + @Override + public V get(long key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + @Override + public V put(long key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + @Override + public V putIfAbsent(long key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + @Override + public V remove(long key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + @Override + public void putAll(TLongObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + @Override + public TLongSet keySet() { + return new KeyView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public long[] keys() { + long[] keys = new long[size()]; + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public long[] keys(long[] dest) { + if (dest.length < _size) { + dest = new long[_size]; + } + + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + @Override + public Collection valueCollection() { + return new ValueView(); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + @Override + public TLongObjectIterator iterator() { + return new TLongObjectHashIterator(this); + } + + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TLongObjectProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TLongObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongObjectMap)) { + return false; + } + TLongObjectMap that = (TLongObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TLongObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + long key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TLongSet { + + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + @Override + public int size() { + return _size; + } + + @Override + public boolean isEmpty() { + return _size == 0; + } + + @Override + public boolean contains(long entry) { + return TLongObjectHashMap.this.containsKey(entry); + } + + @Override + public TLongIterator iterator() { + return new TLongHashIterator(TLongObjectHashMap.this); + } + + @Override + public long[] toArray() { + return keys(); + } + + @Override + public long[] toArray(long[] dest) { + return keys(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean remove(long entry) { + return null != TLongObjectHashMap.this.remove(entry); + } + + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TLongObjectHashMap.this.containsKey(((Long) element).longValue())) { + + return false; + } + } + return true; + } + + @Override + public boolean containsAll(TLongCollection collection) { + if (collection == this) { + return true; + } + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + @Override + public boolean removeAll(TLongCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + @Override + public void clear() { + TLongObjectHashMap.this.clear(); + } + + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongObjectHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TLongHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** the collection on which the iterator operates */ + private final TLongHash _hash; + + public TLongHashIterator(TLongHash hash) { + super(hash); + this._hash = hash; + } + + @Override + public long next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TLongObjectValueHashIterator(TLongObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TLongObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TLongObjectHashMap _map; + + public TLongObjectValueHashIterator(TLongObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TLongObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TLongObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TLongObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongObjectHashIterator extends THashPrimitiveIterator implements TLongObjectIterator { + + /** the collection being iterated over */ + private final TLongObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TLongObjectHashIterator(TLongObjectHashMap map) { + super(map); + this._map = map; + } + + @Override + public void advance() { + moveToNextIndex(); + } + + @Override + public long key() { + return _map._set[_index]; + } + + @Override + public V value() { + return _map._values[_index]; + } + + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeLong(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TLongObjectHashMap diff --git a/src/gnu/trove/map/hash/TLongShortHashMap.java b/src/gnu/trove/map/hash/TLongShortHashMap.java new file mode 100644 index 0000000..07cfca3 --- /dev/null +++ b/src/gnu/trove/map/hash/TLongShortHashMap.java @@ -0,0 +1,1303 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TLongShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for long keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TLongShortHashMap extends TLongShortHash implements TLongShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TLongShortHashMap instance with the default + * capacity and load factor. + */ + public TLongShortHashMap() { + super(); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TLongShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLongShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TLongShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a long value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TLongShortHashMap(int initialCapacity, float loadFactor, long noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TLongShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a long array containing the keys for the matching values. + * @param values + * a short array containing the values. + */ + public TLongShortHashMap(long[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TLongShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TLongShortMap that will be duplicated. + */ + public TLongShortHashMap(TLongShortMap map) { + super(map.size()); + if (map instanceof TLongShortHashMap) { + TLongShortHashMap hashmap = (TLongShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(long key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(long key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(long key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().longValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TLongShortMap map) { + ensureCapacity(map.size()); + TLongShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(long key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(long key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TLongSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public long[] keys() { + long[] keys = new long[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + long[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public long[] keys(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(long key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TLongShortIterator iterator() { + return new TLongShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TLongProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TLongShortProcedure procedure) { + byte[] states = _states; + long[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TLongShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + long[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(long key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(long key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(long key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TLongSet { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongShortKeyHashIterator(TLongShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TLongShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TLongShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TLongShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + return no_entry_value != TLongShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TLongShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TLongShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TLongShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TLongShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + final TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TLongShortValueHashIterator(TLongShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TLongShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TLongShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TLongShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + long[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TLongShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TLongShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TLongShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TLongShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TLongShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TLongShortKeyHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TLongShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TLongShortHashIterator extends THashPrimitiveIterator implements TLongShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TLongShortHashMap we will be iterating over. + */ + TLongShortHashIterator(TLongShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public long key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TLongShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongShortMap)) { + return false; + } + TLongShortMap that = (TLongShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + long key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TLongShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(long key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + long key = in.readLong(); + short val = in.readShort(); + put(key, val); + } + } +} // TLongShortHashMap diff --git a/src/gnu/trove/map/hash/TObjectByteHashMap.java b/src/gnu/trove/map/hash/TObjectByteHashMap.java new file mode 100644 index 0000000..fbcaf39 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectByteHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectByteProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.iterator.TObjectByteIterator; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TByteFunction; +import gnu.trove.map.TObjectByteMap; +import gnu.trove.TByteCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and byte values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectByteHashMap extends TObjectHash implements TObjectByteMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectByteProcedure PUT_ALL_PROC = new TObjectByteProcedure() { + @Override + public boolean execute(K key, byte value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient byte[] _values; + + /** the value that represents null */ + protected byte no_entry_value; + + /** + * Creates a new TObjectByteHashMap instance with the default + * capacity and load factor. + */ + public TObjectByteHashMap() { + super(); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectByteHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_BYTE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectByteHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectByteHashMap(int initialCapacity, float loadFactor, byte noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectByteHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectByteMap to be copied. + */ + public TObjectByteHashMap(TObjectByteMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectByteHashMap) { + TObjectByteHashMap hashmap = (TObjectByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + byte oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new byte[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + Object[] keys = _set; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public byte get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public byte put(K key, byte value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(K key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private byte doPut(byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public byte remove(Object key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectByteMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TByteValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectByteIterator iterator() { + return new TObjectByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(final K key, final byte adjust_amount, final byte put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectByteProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectByteProcedure procedure) { + Object[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectByteProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TByteFunction value + */ + @Override + public void transformValues(TByteFunction function) { + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectByteMap)) { + return false; + } + TObjectByteMap that = (TObjectByteMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectByteIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + byte value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectByteHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectByteHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectByteHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectByteHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectByteHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectByteHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TByteValueCollection implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TObjectByteValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TObjectByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TObjectByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TObjectByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TObjectByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TObjectByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TObjectByteHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectByteValueHashIterator implements TByteIterator { + + protected THash _hash = TObjectByteHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectByteValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectByteHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectByteHashIterator extends TObjectHashIterator implements TObjectByteIterator { + + /** the collection being iterated over */ + private final TObjectByteHashMap _map; + + public TObjectByteHashIterator(TObjectByteHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeByte(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeByte(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readByte(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + byte val = in.readByte(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, byte value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectByteHashMap diff --git a/src/gnu/trove/map/hash/TObjectCharHashMap.java b/src/gnu/trove/map/hash/TObjectCharHashMap.java new file mode 100644 index 0000000..2644754 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectCharHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectCharProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.iterator.TObjectCharIterator; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TCharFunction; +import gnu.trove.map.TObjectCharMap; +import gnu.trove.TCharCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and char values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectCharHashMap extends TObjectHash implements TObjectCharMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectCharProcedure PUT_ALL_PROC = new TObjectCharProcedure() { + @Override + public boolean execute(K key, char value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient char[] _values; + + /** the value that represents null */ + protected char no_entry_value; + + /** + * Creates a new TObjectCharHashMap instance with the default + * capacity and load factor. + */ + public TObjectCharHashMap() { + super(); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectCharHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_CHAR_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectCharHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectCharHashMap(int initialCapacity, float loadFactor, char noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectCharHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectCharMap to be copied. + */ + public TObjectCharHashMap(TObjectCharMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectCharHashMap) { + TObjectCharHashMap hashmap = (TObjectCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + char oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new char[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + Object[] keys = _set; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public char get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public char put(K key, char value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(K key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private char doPut(char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public char remove(Object key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectCharMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TCharValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectCharIterator iterator() { + return new TObjectCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(final K key, final char adjust_amount, final char put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectCharProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectCharProcedure procedure) { + Object[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectCharProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TCharFunction value + */ + @Override + public void transformValues(TCharFunction function) { + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectCharMap)) { + return false; + } + TObjectCharMap that = (TObjectCharMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectCharIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + char value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectCharHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectCharHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectCharHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectCharHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectCharHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectCharHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TCharValueCollection implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TObjectCharValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TObjectCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TObjectCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TObjectCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TObjectCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TObjectCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TObjectCharHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectCharValueHashIterator implements TCharIterator { + + protected THash _hash = TObjectCharHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectCharValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectCharHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectCharHashIterator extends TObjectHashIterator implements TObjectCharIterator { + + /** the collection being iterated over */ + private final TObjectCharHashMap _map; + + public TObjectCharHashIterator(TObjectCharHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeChar(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeChar(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readChar(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + char val = in.readChar(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, char value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectCharHashMap diff --git a/src/gnu/trove/map/hash/TObjectDoubleHashMap.java b/src/gnu/trove/map/hash/TObjectDoubleHashMap.java new file mode 100644 index 0000000..e0bd61a --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectDoubleHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectDoubleProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.iterator.TObjectDoubleIterator; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.map.TObjectDoubleMap; +import gnu.trove.TDoubleCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and double values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectDoubleHashMap extends TObjectHash implements TObjectDoubleMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectDoubleProcedure PUT_ALL_PROC = new TObjectDoubleProcedure() { + @Override + public boolean execute(K key, double value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient double[] _values; + + /** the value that represents null */ + protected double no_entry_value; + + /** + * Creates a new TObjectDoubleHashMap instance with the default + * capacity and load factor. + */ + public TObjectDoubleHashMap() { + super(); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * default load factor. + * + * @param initialCapacity + * an int value + */ + public TObjectDoubleHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime + * capacity equal to or greater than initialCapacity and with the + * specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_DOUBLE_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectDoubleHashMap instance with a prime value + * at or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectDoubleHashMap(int initialCapacity, float loadFactor, double noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectDoubleHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectDoubleMap to be copied. + */ + public TObjectDoubleHashMap(TObjectDoubleMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectDoubleHashMap) { + TObjectDoubleHashMap hashmap = (TObjectDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + double oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new double[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + Object[] keys = _set; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public double get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public double put(K key, double value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(K key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private double doPut(double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public double remove(Object key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectDoubleMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TDoubleValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectDoubleIterator iterator() { + return new TObjectDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(final K key, final double adjust_amount, final double put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectDoubleProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectDoubleProcedure procedure) { + Object[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectDoubleProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TDoubleFunction value + */ + @Override + public void transformValues(TDoubleFunction function) { + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectDoubleMap)) { + return false; + } + TObjectDoubleMap that = (TObjectDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectDoubleIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + double value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectDoubleHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectDoubleHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectDoubleHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectDoubleHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectDoubleHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectDoubleHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TDoubleValueCollection implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TObjectDoubleValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TObjectDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TObjectDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TObjectDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TObjectDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TObjectDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TObjectDoubleHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectDoubleValueHashIterator implements TDoubleIterator { + + protected THash _hash = TObjectDoubleHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectDoubleValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectDoubleHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectDoubleHashIterator extends TObjectHashIterator implements TObjectDoubleIterator { + + /** the collection being iterated over */ + private final TObjectDoubleHashMap _map; + + public TObjectDoubleHashIterator(TObjectDoubleHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeDouble(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readDouble(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + double val = in.readDouble(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, double value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectDoubleHashMap diff --git a/src/gnu/trove/map/hash/TObjectFloatHashMap.java b/src/gnu/trove/map/hash/TObjectFloatHashMap.java new file mode 100644 index 0000000..cde4272 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectFloatHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectFloatProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.iterator.TObjectFloatIterator; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TFloatFunction; +import gnu.trove.map.TObjectFloatMap; +import gnu.trove.TFloatCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and float values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectFloatHashMap extends TObjectHash implements TObjectFloatMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectFloatProcedure PUT_ALL_PROC = new TObjectFloatProcedure() { + @Override + public boolean execute(K key, float value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient float[] _values; + + /** the value that represents null */ + protected float no_entry_value; + + /** + * Creates a new TObjectFloatHashMap instance with the default + * capacity and load factor. + */ + public TObjectFloatHashMap() { + super(); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectFloatHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_FLOAT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectFloatHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectFloatHashMap(int initialCapacity, float loadFactor, float noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectFloatHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectFloatMap to be copied. + */ + public TObjectFloatHashMap(TObjectFloatMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectFloatHashMap) { + TObjectFloatHashMap hashmap = (TObjectFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + float oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new float[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + Object[] keys = _set; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public float get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public float put(K key, float value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(K key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private float doPut(float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public float remove(Object key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectFloatMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TFloatValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectFloatIterator iterator() { + return new TObjectFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(final K key, final float adjust_amount, final float put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectFloatProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectFloatProcedure procedure) { + Object[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectFloatProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TFloatFunction value + */ + @Override + public void transformValues(TFloatFunction function) { + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectFloatMap)) { + return false; + } + TObjectFloatMap that = (TObjectFloatMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectFloatIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + float value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectFloatHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectFloatHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectFloatHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectFloatHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectFloatHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectFloatHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TFloatValueCollection implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TObjectFloatValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TObjectFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TObjectFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TObjectFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TObjectFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TObjectFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TObjectFloatHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectFloatValueHashIterator implements TFloatIterator { + + protected THash _hash = TObjectFloatHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectFloatValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectFloatHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectFloatHashIterator extends TObjectHashIterator implements TObjectFloatIterator { + + /** the collection being iterated over */ + private final TObjectFloatHashMap _map; + + public TObjectFloatHashIterator(TObjectFloatHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeFloat(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readFloat(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + float val = in.readFloat(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, float value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectFloatHashMap diff --git a/src/gnu/trove/map/hash/TObjectIntHashMap.java b/src/gnu/trove/map/hash/TObjectIntHashMap.java new file mode 100644 index 0000000..3d38df8 --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectIntHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectIntProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.iterator.TObjectIntIterator; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TIntFunction; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.TIntCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and int values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectIntHashMap extends TObjectHash implements TObjectIntMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectIntProcedure PUT_ALL_PROC = new TObjectIntProcedure() { + @Override + public boolean execute(K key, int value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient int[] _values; + + /** the value that represents null */ + protected int no_entry_value; + + /** + * Creates a new TObjectIntHashMap instance with the default + * capacity and load factor. + */ + public TObjectIntHashMap() { + super(); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectIntHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_INT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectIntHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectIntHashMap(int initialCapacity, float loadFactor, int noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectIntHashMap that contains the entries in the + * map passed to it. + * + * @param map + * the TObjectIntMap to be copied. + */ + public TObjectIntHashMap(TObjectIntMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectIntHashMap) { + TObjectIntHashMap hashmap = (TObjectIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + int oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new int[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + Object[] keys = _set; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public int get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public int put(K key, int value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(K key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private int doPut(int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public int remove(Object key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectIntMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TIntValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectIntIterator iterator() { + return new TObjectIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(final K key, final int adjust_amount, final int put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectIntProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectIntProcedure procedure) { + Object[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectIntProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TIntFunction value + */ + @Override + public void transformValues(TIntFunction function) { + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectIntMap)) { + return false; + } + TObjectIntMap that = (TObjectIntMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectIntIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + int value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectIntHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectIntHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectIntHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectIntHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectIntHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectIntHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TIntValueCollection implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TObjectIntValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TObjectIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TObjectIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TObjectIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TObjectIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TObjectIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TObjectIntHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectIntValueHashIterator implements TIntIterator { + + protected THash _hash = TObjectIntHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectIntValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectIntHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectIntHashIterator extends TObjectHashIterator implements TObjectIntIterator { + + /** the collection being iterated over */ + private final TObjectIntHashMap _map; + + public TObjectIntHashIterator(TObjectIntHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeInt(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeInt(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readInt(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + int val = in.readInt(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, int value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectIntHashMap diff --git a/src/gnu/trove/map/hash/TObjectLongHashMap.java b/src/gnu/trove/map/hash/TObjectLongHashMap.java new file mode 100644 index 0000000..6c96d3e --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectLongHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectLongProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.iterator.TObjectLongIterator; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TLongFunction; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.TLongCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and long values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectLongHashMap extends TObjectHash implements TObjectLongMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectLongProcedure PUT_ALL_PROC = new TObjectLongProcedure() { + @Override + public boolean execute(K key, long value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient long[] _values; + + /** the value that represents null */ + protected long no_entry_value; + + /** + * Creates a new TObjectLongHashMap instance with the default + * capacity and load factor. + */ + public TObjectLongHashMap() { + super(); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectLongHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_LONG_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectLongHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectLongHashMap(int initialCapacity, float loadFactor, long noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectLongHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectLongMap to be copied. + */ + public TObjectLongHashMap(TObjectLongMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectLongHashMap) { + TObjectLongHashMap hashmap = (TObjectLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + long oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new long[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + Object[] keys = _set; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public long get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public long put(K key, long value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(K key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private long doPut(long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public long remove(Object key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectLongMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TLongValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectLongIterator iterator() { + return new TObjectLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(final K key, final long adjust_amount, final long put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectLongProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectLongProcedure procedure) { + Object[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectLongProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TLongFunction value + */ + @Override + public void transformValues(TLongFunction function) { + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectLongMap)) { + return false; + } + TObjectLongMap that = (TObjectLongMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectLongIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + long value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectLongHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectLongHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectLongHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectLongHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectLongHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectLongHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TLongValueCollection implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TObjectLongValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TObjectLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TObjectLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TObjectLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TObjectLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TObjectLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TObjectLongHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectLongValueHashIterator implements TLongIterator { + + protected THash _hash = TObjectLongHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectLongValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectLongHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectLongHashIterator extends TObjectHashIterator implements TObjectLongIterator { + + /** the collection being iterated over */ + private final TObjectLongHashMap _map; + + public TObjectLongHashIterator(TObjectLongHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeLong(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeLong(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readLong(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + long val = in.readLong(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, long value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectLongHashMap diff --git a/src/gnu/trove/map/hash/TObjectShortHashMap.java b/src/gnu/trove/map/hash/TObjectShortHashMap.java new file mode 100644 index 0000000..a2dc56b --- /dev/null +++ b/src/gnu/trove/map/hash/TObjectShortHashMap.java @@ -0,0 +1,1170 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.THash; +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.procedure.TObjectShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.iterator.TObjectShortIterator; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.function.TShortFunction; +import gnu.trove.map.TObjectShortMap; +import gnu.trove.TShortCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for Object keys and short values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TObjectShortHashMap extends TObjectHash implements TObjectShortMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TObjectShortProcedure PUT_ALL_PROC = new TObjectShortProcedure() { + @Override + public boolean execute(K key, short value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient short[] _values; + + /** the value that represents null */ + protected short no_entry_value; + + /** + * Creates a new TObjectShortHashMap instance with the default + * capacity and load factor. + */ + public TObjectShortHashMap() { + super(); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TObjectShortHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TObjectShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_value = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TObjectShortHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryValue + * the value used to represent null. + */ + public TObjectShortHashMap(int initialCapacity, float loadFactor, short noEntryValue) { + super(initialCapacity, loadFactor); + no_entry_value = noEntryValue; + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_values, no_entry_value); + } + } + + /** + * Creates a new TObjectShortHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TObjectShortMap to be copied. + */ + public TObjectShortHashMap(TObjectShortMap map) { + this(map.size(), 0.5f, map.getNoEntryValue()); + if (map instanceof TObjectShortHashMap) { + TObjectShortHashMap hashmap = (TObjectShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + public int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + // noinspection unchecked + K oldKeys[] = (K[]) _set; + short oldVals[] = _values; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + _values = new short[newCapacity]; + Arrays.fill(_values, no_entry_value); + + for (int i = oldCapacity; i-- > 0;) { + if (oldKeys[i] != FREE && oldKeys[i] != REMOVED) { + K o = oldKeys[i]; + int index = insertKey(o); + if (index < 0) { + throwObjectContractViolation(_set[(-index - 1)], o); + } + _set[index] = o; + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(Object key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + Object[] keys = _set; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public short get(Object key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public short put(K key, short value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(K key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + private short doPut(short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + // noinspection unchecked + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + return previous; + } + + /** {@inheritDoc} */ + @Override + public short remove(Object key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** + * Removes the mapping at index from the map. This method is used + * internally and public mainly because of packaging reasons. Caveat Programmer. + * + * @param index + * an int value + */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TObjectShortMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, FREE); + Arrays.fill(_values, 0, _values.length, no_entry_value); + } + + // Views + + /** {@inheritDoc} */ + @Override + public Set keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + public Object[] keys() { + // noinspection unchecked + K[] keys = (K[]) new Object[size()]; + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + keys[j++] = (K) k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public K[] keys(K[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (K[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Object[] k = _set; + + for (int i = k.length, j = 0; i-- > 0;) { + if (k[i] != FREE && k[i] != REMOVED) { + // noinspection unchecked + a[j++] = (K) k[i]; + } + } + return a; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TShortValueCollection(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + Object[] keys = _set; + + for (int i = v.length, j = 0; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + array[j++] = v[i]; + } + } + if (array.length > size) { + array[size] = no_entry_value; + } + return array; + } + + /** + * @return an iterator over the entries in this map + */ + @Override + public TObjectShortIterator iterator() { + return new TObjectShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "RedundantCast" }) + public boolean increment(K key) { + // noinspection RedundantCast + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(K key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(final K key, final short adjust_amount, final short put_amount) { + + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + // noinspection unchecked + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** + * Executes procedure for each key in the map. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the keys terminated because the procedure + * returned false for some key. + */ + @Override + public boolean forEachKey(TObjectProcedure procedure) { + return forEach(procedure); + } + + /** + * Executes procedure for each value in the map. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the values terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** + * Executes procedure for each key/value entry in the map. + * + * @param procedure + * a TOObjectShortProcedure value + * @return false if the loop over the entries terminated because the procedure + * returned false for some entry. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TObjectShortProcedure procedure) { + Object[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute((K) keys[i], values[i])) { + return false; + } + } + return true; + } + + /** + * Retains only those entries in the map for which the procedure returns a true + * value. + * + * @param procedure + * determines which entries to keep + * @return true if the map was modified. + */ + @Override + public boolean retainEntries(TObjectShortProcedure procedure) { + boolean modified = false; + // noinspection unchecked + K[] keys = (K[]) _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** + * Transform the values in this map using function. + * + * @param function + * a TShortFunction value + */ + @Override + public void transformValues(TShortFunction function) { + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != null && keys[i] != REMOVED) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** + * Compares this map with another map for equality of their stored entries. + * + * @param other + * an Object value + * @return a boolean value + */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TObjectShortMap)) { + return false; + } + TObjectShortMap that = (TObjectShortMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TObjectShortIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + Object key = iter.key(); + short value = iter.value(); + if (value == no_entry_value) { + if (!(that.get(key) == that.getNoEntryValue() && that.containsKey(key))) { + + return false; + } + } else { + if (value != that.get(key)) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + Object[] keys = _set; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (keys[i] != FREE && keys[i] != REMOVED) { + hashcode += HashFunctions.hash(values[i]) ^ (keys[i] == null ? 0 : keys[i].hashCode()); + } + } + return hashcode; + } + + /** a view onto the keys of the map. */ + protected class KeyView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TObjectHashIterator(TObjectShortHashMap.this); + } + + @Override + public boolean removeElement(K key) { + return no_entry_value != TObjectShortHashMap.this.remove(key); + } + + @Override + public boolean containsElement(K key) { + return TObjectShortHashMap.this.contains(key); + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TObjectShortHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TObjectShortHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + // noinspection unchecked + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TObjectShortHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortValueCollection implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TObjectShortValueHashIterator(); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TObjectShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TObjectShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TObjectShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + Object[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TObjectShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TObjectShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TObjectShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + + Object[] set = _set; + for (int i = set.length; i-- > 0;) { + if (set[i] != FREE && set[i] != REMOVED && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TObjectShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TObjectShortHashMap.this.forEachValue(procedure); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + class TObjectShortValueHashIterator implements TShortIterator { + + protected THash _hash = TObjectShortHashMap.this; + + /** + * the number of elements this iterator believes are in the data structure it + * accesses. + */ + protected int _expectedSize; + + /** the index used for iteration. */ + protected int _index; + + /** Creates an iterator over the specified map */ + TObjectShortValueHashIterator() { + _expectedSize = _hash.size(); + _index = _hash.capacity(); + } + + /** {@inheritDoc} */ + @Override + public boolean hasNext() { + return nextIndex() >= 0; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for + // bug 1642768. + try { + _hash.tempDisableAutoCompaction(); + TObjectShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + + /** + * Sets the internal index so that the `next' object can be returned. + */ + protected final void moveToNextIndex() { + // doing the assignment && < 0 in one line shaves + // 3 opcodes... + if ((_index = nextIndex()) < 0) { + throw new NoSuchElementException(); + } + } + + /** + * Returns the index of the next value in the data structure or a negative value + * if the iterator is exhausted. + * + * @return an int value + * @throws ConcurrentModificationException + * if the underlying collection's size has been modified since the + * iterator was created. + */ + protected final int nextIndex() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + Object[] set = TObjectShortHashMap.this._set; + int i = _index; + while (i-- > 0 && (set[i] == TObjectHash.FREE || set[i] == TObjectHash.REMOVED)) { + + // do nothing + } + return i; + } + } + } + + class TObjectShortHashIterator extends TObjectHashIterator implements TObjectShortIterator { + + /** the collection being iterated over */ + private final TObjectShortHashMap _map; + + public TObjectShortHashIterator(TObjectShortHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public K key() { + return (K) _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _map._values[_index] = val; + return old; + } + } + + // Externalization + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_VALUE + out.writeShort(no_entry_value); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + out.writeShort(_values[i]); + } + } + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_VALUE + no_entry_value = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + // noinspection unchecked + K key = (K) in.readObject(); + short val = in.readShort(); + put(key, val); + } + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TObjectShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(K key, short value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key).append("=").append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TObjectShortHashMap diff --git a/src/gnu/trove/map/hash/TShortByteHashMap.java b/src/gnu/trove/map/hash/TShortByteHashMap.java new file mode 100644 index 0000000..ae6e524 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortByteHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortByteMap; +import gnu.trove.function.TByteFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and byte values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortByteHashMap extends TShortByteHash implements TShortByteMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient byte[] _values; + + /** + * Creates a new TShortByteHashMap instance with the default + * capacity and load factor. + */ + public TShortByteHashMap() { + super(); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortByteHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortByteHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortByteHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a byte value that represents null for the + * Value set. + */ + public TShortByteHashMap(int initialCapacity, float loadFactor, short noEntryKey, byte noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a byte array containing the values. + */ + public TShortByteHashMap(short[] keys, byte[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortByteHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortByteMap that will be duplicated. + */ + public TShortByteHashMap(TShortByteMap map) { + super(map.size()); + if (map instanceof TShortByteHashMap) { + TShortByteHashMap hashmap = (TShortByteHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new byte[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + byte oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public byte put(short key, byte value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public byte putIfAbsent(short key, byte value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private byte doPut(short key, byte value, int index) { + byte previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().byteValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortByteMap map) { + ensureCapacity(map.size()); + TShortByteIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public byte get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public byte remove(short key) { + byte prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TByteCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public byte[] values() { + byte[] vals = new byte[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public byte[] values(byte[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new byte[size]; + } + + byte[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(byte val) { + byte[] states = _states; + byte[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortByteIterator iterator() { + return new TShortByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TByteProcedure procedure) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortByteProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + byte[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TByteFunction function) { + byte[] states = _states; + byte[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortByteProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + byte[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (byte) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, byte amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public byte adjustOrPutValue(short key, byte adjust_amount, byte put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final byte newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortByteKeyHashIterator(TShortByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortByteHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortByteHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortByteHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortByteHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortByteHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortByteHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortByteHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortByteMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortByteHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TByteCollection { + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TShortByteValueHashIterator(TShortByteHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public byte getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(byte entry) { + return TShortByteHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + return TShortByteHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + return TShortByteHashMap.this.values(dest); + } + + @Override + public boolean add(byte entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte entry) { + byte[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte ele = ((Byte) element).byteValue(); + if (!TShortByteHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortByteHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (byte element : array) { + if (!TShortByteHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortByteHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TByteProcedure procedure) { + return TShortByteHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(byte value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortByteKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortByteKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortByteValueHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortByteValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortByteHashIterator extends THashPrimitiveIterator implements TShortByteIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortByteHashMap we will be iterating over. + */ + TShortByteHashIterator(TShortByteHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public byte setValue(byte val) { + byte old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortByteHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortByteMap)) { + return false; + } + TShortByteMap that = (TShortByteMap) other; + if (that.size() != this.size()) { + return false; + } + byte[] values = _values; + byte[] states = _states; + byte this_no_entry_value = getNoEntryValue(); + byte that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + byte that_value = that.get(key); + byte this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortByteProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, byte value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeByte(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + byte val = in.readByte(); + put(key, val); + } + } +} // TShortByteHashMap diff --git a/src/gnu/trove/map/hash/TShortCharHashMap.java b/src/gnu/trove/map/hash/TShortCharHashMap.java new file mode 100644 index 0000000..af15ef2 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortCharHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortCharMap; +import gnu.trove.function.TCharFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and char values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortCharHashMap extends TShortCharHash implements TShortCharMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient char[] _values; + + /** + * Creates a new TShortCharHashMap instance with the default + * capacity and load factor. + */ + public TShortCharHashMap() { + super(); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortCharHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortCharHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortCharHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a char value that represents null for the + * Value set. + */ + public TShortCharHashMap(int initialCapacity, float loadFactor, short noEntryKey, char noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a char array containing the values. + */ + public TShortCharHashMap(short[] keys, char[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortCharHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortCharMap that will be duplicated. + */ + public TShortCharHashMap(TShortCharMap map) { + super(map.size()); + if (map instanceof TShortCharHashMap) { + TShortCharHashMap hashmap = (TShortCharHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new char[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + char oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public char put(short key, char value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public char putIfAbsent(short key, char value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private char doPut(short key, char value, int index) { + char previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().charValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortCharMap map) { + ensureCapacity(map.size()); + TShortCharIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public char get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public char remove(short key) { + char prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TCharCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public char[] values() { + char[] vals = new char[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public char[] values(char[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new char[size]; + } + + char[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(char val) { + byte[] states = _states; + char[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortCharIterator iterator() { + return new TShortCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TCharProcedure procedure) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortCharProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + char[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TCharFunction function) { + byte[] states = _states; + char[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortCharProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + char[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (char) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, char amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public char adjustOrPutValue(short key, char adjust_amount, char put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final char newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortCharKeyHashIterator(TShortCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortCharHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortCharHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortCharHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortCharHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortCharHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortCharHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortCharHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortCharMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortCharHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TCharCollection { + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TShortCharValueHashIterator(TShortCharHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public char getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(char entry) { + return TShortCharHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + return TShortCharHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + return TShortCharHashMap.this.values(dest); + } + + @Override + public boolean add(char entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char entry) { + char[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char ele = ((Character) element).charValue(); + if (!TShortCharHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortCharHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (char element : array) { + if (!TShortCharHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortCharHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TCharProcedure procedure) { + return TShortCharHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(char value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortCharKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortCharKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortCharValueHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortCharValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortCharHashIterator extends THashPrimitiveIterator implements TShortCharIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortCharHashMap we will be iterating over. + */ + TShortCharHashIterator(TShortCharHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public char value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public char setValue(char val) { + char old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortCharHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortCharMap)) { + return false; + } + TShortCharMap that = (TShortCharMap) other; + if (that.size() != this.size()) { + return false; + } + char[] values = _values; + byte[] states = _states; + char this_no_entry_value = getNoEntryValue(); + char that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + char that_value = that.get(key); + char this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortCharProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, char value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeChar(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + char val = in.readChar(); + put(key, val); + } + } +} // TShortCharHashMap diff --git a/src/gnu/trove/map/hash/TShortDoubleHashMap.java b/src/gnu/trove/map/hash/TShortDoubleHashMap.java new file mode 100644 index 0000000..0399e8d --- /dev/null +++ b/src/gnu/trove/map/hash/TShortDoubleHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortDoubleMap; +import gnu.trove.function.TDoubleFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and double values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortDoubleHashMap extends TShortDoubleHash implements TShortDoubleMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient double[] _values; + + /** + * Creates a new TShortDoubleHashMap instance with the default + * capacity and load factor. + */ + public TShortDoubleHashMap() { + super(); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortDoubleHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortDoubleHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortDoubleHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a double value that represents null for the + * Value set. + */ + public TShortDoubleHashMap(int initialCapacity, float loadFactor, short noEntryKey, double noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a double array containing the values. + */ + public TShortDoubleHashMap(short[] keys, double[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortDoubleHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortDoubleMap that will be duplicated. + */ + public TShortDoubleHashMap(TShortDoubleMap map) { + super(map.size()); + if (map instanceof TShortDoubleHashMap) { + TShortDoubleHashMap hashmap = (TShortDoubleHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new double[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + double oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public double put(short key, double value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public double putIfAbsent(short key, double value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private double doPut(short key, double value, int index) { + double previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().doubleValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortDoubleMap map) { + ensureCapacity(map.size()); + TShortDoubleIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public double get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public double remove(short key) { + double prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TDoubleCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public double[] values() { + double[] vals = new double[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public double[] values(double[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new double[size]; + } + + double[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(double val) { + byte[] states = _states; + double[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortDoubleIterator iterator() { + return new TShortDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TDoubleProcedure procedure) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortDoubleProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + double[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TDoubleFunction function) { + byte[] states = _states; + double[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortDoubleProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + double[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, double amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public double adjustOrPutValue(short key, double adjust_amount, double put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final double newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortDoubleKeyHashIterator(TShortDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortDoubleHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortDoubleHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortDoubleHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortDoubleHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortDoubleHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortDoubleHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortDoubleHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortDoubleMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortDoubleHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TDoubleCollection { + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TShortDoubleValueHashIterator(TShortDoubleHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public double getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(double entry) { + return TShortDoubleHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + return TShortDoubleHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + return TShortDoubleHashMap.this.values(dest); + } + + @Override + public boolean add(double entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double entry) { + double[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double ele = ((Double) element).doubleValue(); + if (!TShortDoubleHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortDoubleHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (double element : array) { + if (!TShortDoubleHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortDoubleHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TDoubleProcedure procedure) { + return TShortDoubleHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(double value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortDoubleKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortDoubleKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortDoubleValueHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortDoubleValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortDoubleHashIterator extends THashPrimitiveIterator implements TShortDoubleIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortDoubleHashMap we will be iterating over. + */ + TShortDoubleHashIterator(TShortDoubleHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public double value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public double setValue(double val) { + double old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortDoubleHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortDoubleMap)) { + return false; + } + TShortDoubleMap that = (TShortDoubleMap) other; + if (that.size() != this.size()) { + return false; + } + double[] values = _values; + byte[] states = _states; + double this_no_entry_value = getNoEntryValue(); + double that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + double that_value = that.get(key); + double this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortDoubleProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, double value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeDouble(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + double val = in.readDouble(); + put(key, val); + } + } +} // TShortDoubleHashMap diff --git a/src/gnu/trove/map/hash/TShortFloatHashMap.java b/src/gnu/trove/map/hash/TShortFloatHashMap.java new file mode 100644 index 0000000..a1d1792 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortFloatHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortFloatMap; +import gnu.trove.function.TFloatFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and float values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortFloatHashMap extends TShortFloatHash implements TShortFloatMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient float[] _values; + + /** + * Creates a new TShortFloatHashMap instance with the default + * capacity and load factor. + */ + public TShortFloatHashMap() { + super(); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortFloatHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortFloatHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortFloatHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a float value that represents null for the + * Value set. + */ + public TShortFloatHashMap(int initialCapacity, float loadFactor, short noEntryKey, float noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a float array containing the values. + */ + public TShortFloatHashMap(short[] keys, float[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortFloatHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortFloatMap that will be duplicated. + */ + public TShortFloatHashMap(TShortFloatMap map) { + super(map.size()); + if (map instanceof TShortFloatHashMap) { + TShortFloatHashMap hashmap = (TShortFloatHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new float[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + float oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public float put(short key, float value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public float putIfAbsent(short key, float value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private float doPut(short key, float value, int index) { + float previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().floatValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortFloatMap map) { + ensureCapacity(map.size()); + TShortFloatIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public float get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public float remove(short key) { + float prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TFloatCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public float[] values() { + float[] vals = new float[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public float[] values(float[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new float[size]; + } + + float[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(float val) { + byte[] states = _states; + float[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortFloatIterator iterator() { + return new TShortFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TFloatProcedure procedure) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortFloatProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + float[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TFloatFunction function) { + byte[] states = _states; + float[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortFloatProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + float[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, float amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public float adjustOrPutValue(short key, float adjust_amount, float put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final float newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortFloatKeyHashIterator(TShortFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortFloatHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortFloatHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortFloatHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortFloatHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortFloatHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortFloatHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortFloatHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortFloatMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortFloatHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TFloatCollection { + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TShortFloatValueHashIterator(TShortFloatHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public float getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(float entry) { + return TShortFloatHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + return TShortFloatHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + return TShortFloatHashMap.this.values(dest); + } + + @Override + public boolean add(float entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float entry) { + float[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float ele = ((Float) element).floatValue(); + if (!TShortFloatHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortFloatHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (float element : array) { + if (!TShortFloatHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortFloatHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TFloatProcedure procedure) { + return TShortFloatHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(float value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortFloatKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortFloatKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortFloatValueHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortFloatValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortFloatHashIterator extends THashPrimitiveIterator implements TShortFloatIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortFloatHashMap we will be iterating over. + */ + TShortFloatHashIterator(TShortFloatHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public float value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public float setValue(float val) { + float old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortFloatHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortFloatMap)) { + return false; + } + TShortFloatMap that = (TShortFloatMap) other; + if (that.size() != this.size()) { + return false; + } + float[] values = _values; + byte[] states = _states; + float this_no_entry_value = getNoEntryValue(); + float that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + float that_value = that.get(key); + float this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortFloatProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, float value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeFloat(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + float val = in.readFloat(); + put(key, val); + } + } +} // TShortFloatHashMap diff --git a/src/gnu/trove/map/hash/TShortIntHashMap.java b/src/gnu/trove/map/hash/TShortIntHashMap.java new file mode 100644 index 0000000..29ba707 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortIntHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortIntMap; +import gnu.trove.function.TIntFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and int values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortIntHashMap extends TShortIntHash implements TShortIntMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient int[] _values; + + /** + * Creates a new TShortIntHashMap instance with the default + * capacity and load factor. + */ + public TShortIntHashMap() { + super(); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortIntHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortIntHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortIntHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a int value that represents null for the + * Value set. + */ + public TShortIntHashMap(int initialCapacity, float loadFactor, short noEntryKey, int noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a int array containing the values. + */ + public TShortIntHashMap(short[] keys, int[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortIntHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortIntMap that will be duplicated. + */ + public TShortIntHashMap(TShortIntMap map) { + super(map.size()); + if (map instanceof TShortIntHashMap) { + TShortIntHashMap hashmap = (TShortIntHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new int[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + int oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public int put(short key, int value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public int putIfAbsent(short key, int value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private int doPut(short key, int value, int index) { + int previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().intValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortIntMap map) { + ensureCapacity(map.size()); + TShortIntIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public int get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public int remove(short key) { + int prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TIntCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public int[] values() { + int[] vals = new int[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public int[] values(int[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new int[size]; + } + + int[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(int val) { + byte[] states = _states; + int[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortIntIterator iterator() { + return new TShortIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TIntProcedure procedure) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortIntProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + int[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TIntFunction function) { + byte[] states = _states; + int[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortIntProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + int[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, int amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public int adjustOrPutValue(short key, int adjust_amount, int put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final int newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortIntKeyHashIterator(TShortIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortIntHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortIntHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortIntHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortIntHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortIntHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortIntHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortIntHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortIntMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortIntHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TIntCollection { + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TShortIntValueHashIterator(TShortIntHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public int getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(int entry) { + return TShortIntHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + return TShortIntHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + return TShortIntHashMap.this.values(dest); + } + + @Override + public boolean add(int entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int entry) { + int[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int ele = ((Integer) element).intValue(); + if (!TShortIntHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortIntHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int element : array) { + if (!TShortIntHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortIntHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TIntProcedure procedure) { + return TShortIntHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(int value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortIntKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortIntKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortIntValueHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortIntValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortIntHashIterator extends THashPrimitiveIterator implements TShortIntIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortIntHashMap we will be iterating over. + */ + TShortIntHashIterator(TShortIntHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public int value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public int setValue(int val) { + int old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortIntHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortIntMap)) { + return false; + } + TShortIntMap that = (TShortIntMap) other; + if (that.size() != this.size()) { + return false; + } + int[] values = _values; + byte[] states = _states; + int this_no_entry_value = getNoEntryValue(); + int that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + int that_value = that.get(key); + int this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortIntProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, int value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeInt(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + int val = in.readInt(); + put(key, val); + } + } +} // TShortIntHashMap diff --git a/src/gnu/trove/map/hash/TShortLongHashMap.java b/src/gnu/trove/map/hash/TShortLongHashMap.java new file mode 100644 index 0000000..e80c1d6 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortLongHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortLongMap; +import gnu.trove.function.TLongFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and long values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortLongHashMap extends TShortLongHash implements TShortLongMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient long[] _values; + + /** + * Creates a new TShortLongHashMap instance with the default + * capacity and load factor. + */ + public TShortLongHashMap() { + super(); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortLongHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortLongHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortLongHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a long value that represents null for the + * Value set. + */ + public TShortLongHashMap(int initialCapacity, float loadFactor, short noEntryKey, long noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a long array containing the values. + */ + public TShortLongHashMap(short[] keys, long[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortLongHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortLongMap that will be duplicated. + */ + public TShortLongHashMap(TShortLongMap map) { + super(map.size()); + if (map instanceof TShortLongHashMap) { + TShortLongHashMap hashmap = (TShortLongHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new long[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + long oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public long put(short key, long value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public long putIfAbsent(short key, long value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private long doPut(short key, long value, int index) { + long previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().longValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortLongMap map) { + ensureCapacity(map.size()); + TShortLongIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public long get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public long remove(short key) { + long prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TLongCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public long[] values() { + long[] vals = new long[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public long[] values(long[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new long[size]; + } + + long[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(long val) { + byte[] states = _states; + long[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortLongIterator iterator() { + return new TShortLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TLongProcedure procedure) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortLongProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + long[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TLongFunction function) { + byte[] states = _states; + long[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortLongProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + long[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, long amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public long adjustOrPutValue(short key, long adjust_amount, long put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final long newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortLongKeyHashIterator(TShortLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortLongHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortLongHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortLongHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortLongHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortLongHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortLongHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortLongHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortLongMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortLongHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TLongCollection { + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TShortLongValueHashIterator(TShortLongHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public long getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(long entry) { + return TShortLongHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + return TShortLongHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + return TShortLongHashMap.this.values(dest); + } + + @Override + public boolean add(long entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long entry) { + long[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long ele = ((Long) element).longValue(); + if (!TShortLongHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortLongHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (long element : array) { + if (!TShortLongHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortLongHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TLongProcedure procedure) { + return TShortLongHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(long value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortLongKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortLongKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortLongValueHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortLongValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortLongHashIterator extends THashPrimitiveIterator implements TShortLongIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortLongHashMap we will be iterating over. + */ + TShortLongHashIterator(TShortLongHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public long value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public long setValue(long val) { + long old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortLongHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortLongMap)) { + return false; + } + TShortLongMap that = (TShortLongMap) other; + if (that.size() != this.size()) { + return false; + } + long[] values = _values; + byte[] states = _states; + long this_no_entry_value = getNoEntryValue(); + long that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + long that_value = that.get(key); + long this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortLongProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, long value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeLong(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + long val = in.readLong(); + put(key, val); + } + } +} // TShortLongHashMap diff --git a/src/gnu/trove/map/hash/TShortObjectHashMap.java b/src/gnu/trove/map/hash/TShortObjectHashMap.java new file mode 100644 index 0000000..b5842d6 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortObjectHashMap.java @@ -0,0 +1,1060 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +import gnu.trove.map.TShortObjectMap; +import gnu.trove.impl.Constants; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.*; +import gnu.trove.procedure.TShortObjectProcedure; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.iterator.TShortObjectIterator; +import gnu.trove.function.TObjectFunction; +import gnu.trove.set.TShortSet; +import gnu.trove.TShortCollection; + +import java.io.*; +import java.util.*; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed Map implementation for short keys and Object values. + * + * Created: Sun Nov 4 08:52:45 2001 + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ +public class TShortObjectHashMap extends TShortHash implements TShortObjectMap, Externalizable { + + static final long serialVersionUID = 1L; + + private final TShortObjectProcedure PUT_ALL_PROC = new TShortObjectProcedure() { + @Override + public boolean execute(short key, V value) { + put(key, value); + return true; + } + }; + + /** the values of the map */ + protected transient V[] _values; + + /** the value that represents null in the key set. */ + protected short no_entry_key; + + /** + * Creates a new TShortObjectHashMap instance with the default + * capacity and load factor. + */ + public TShortObjectHashMap() { + super(); + } + + /** + * Creates a new TShortObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortObjectHashMap(int initialCapacity) { + super(initialCapacity); + no_entry_key = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TShortObjectHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortObjectHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + no_entry_key = Constants.DEFAULT_SHORT_NO_ENTRY_VALUE; + } + + /** + * Creates a new TShortObjectHashMap instance with a prime value at + * or near the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param loadFactor + * used to calculate the threshold over which rehashing takes place. + * @param noEntryKey + * the value used to represent null in the key set. + */ + public TShortObjectHashMap(int initialCapacity, float loadFactor, short noEntryKey) { + super(initialCapacity, loadFactor); + no_entry_key = noEntryKey; + } + + /** + * Creates a new TShortObjectHashMap that contains the entries in + * the map passed to it. + * + * @param map + * the TShortObjectMap to be copied. + */ + public TShortObjectHashMap(TShortObjectMap map) { + this(map.size(), 0.5f, map.getNoEntryKey()); + putAll(map); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = (V[]) new Object[capacity]; + return capacity; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + V oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = (V[]) new Object[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + // Query Operations + + /** {@inheritDoc} */ + @Override + public short getNoEntryKey() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(Object val) { + byte[] states = _states; + V[] vals = _values; + + // special case null values so that we don't have to + // perform null checks before every call to equals() + if (null == val) { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && null == vals[i]) { + return true; + } + } + } else { + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && (val == vals[i] || val.equals(vals[i]))) { + return true; + } + } + } // end of else + return false; + } + + /** {@inheritDoc} */ + @Override + public V get(short key) { + int index = index(key); + return index < 0 ? null : _values[index]; + } + + // Modification Operations + + /** {@inheritDoc} */ + @Override + public V put(short key, V value) { + int index = insertKey(key); + return doPut(value, index); + } + + /** {@inheritDoc} */ + @Override + public V putIfAbsent(short key, V value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(value, index); + } + + @SuppressWarnings({ "unchecked" }) + private V doPut(V value, int index) { + V previous = null; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public V remove(short key) { + V prev = null; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = null; + super.removeAt(index); // clear key, state; adjust size + } + + // Bulk Operations + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + Set> set = map.entrySet(); + for (Map.Entry entry : set) { + put(entry.getKey(), entry.getValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortObjectMap map) { + map.forEachEntry(PUT_ALL_PROC); + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_states, 0, _states.length, FREE); + Arrays.fill(_values, 0, _values.length, null); + } + + // Views + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new KeyView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public short[] keys() { + short[] keys = new short[size()]; + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public short[] keys(short[] dest) { + if (dest.length < _size) { + dest = new short[_size]; + } + + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = k[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public Collection valueCollection() { + return new ValueView(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] values() { + Object[] vals = new Object[size()]; + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public V[] values(V[] dest) { + if (dest.length < _size) { + dest = (V[]) java.lang.reflect.Array.newInstance(dest.getClass().getComponentType(), _size); + } + + V[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = v[i]; + } + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public TShortObjectIterator iterator() { + return new TShortObjectHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TObjectProcedure procedure) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean forEachEntry(TShortObjectProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + V[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean retainEntries(TShortObjectProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + V[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TObjectFunction function) { + byte[] states = _states; + V[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + // Comparison and hashing + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortObjectMap)) { + return false; + } + TShortObjectMap that = (TShortObjectMap) other; + if (that.size() != this.size()) { + return false; + } + try { + TShortObjectIterator iter = this.iterator(); + while (iter.hasNext()) { + iter.advance(); + short key = iter.key(); + Object value = iter.value(); + if (value == null) { + if (!(that.get(key) == null && that.containsKey(key))) { + return false; + } + } else { + if (!value.equals(that.get(key))) { + return false; + } + } + } + } catch (ClassCastException ex) { + // unused. + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + V[] values = _values; + byte[] states = _states; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ (values[i] == null ? 0 : values[i].hashCode()); + } + } + return hashcode; + } + + class KeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return _size == 0; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortObjectHashMap.this.containsKey(entry); + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortHashIterator(TShortObjectHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return keys(dest); + } + + /** {@inheritDoc} */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return null != TShortObjectHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (!TShortObjectHashMap.this.containsKey(((Short) element).shortValue())) { + + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + if (collection == this) { + return true; + } + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortObjectHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortObjectHashMap.this.containsKey(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + // noinspection SuspiciousMethodCalls + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (collection == this) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortObjectHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortObjectHashMap.this.forEachKey(procedure); + } + + /** {@inheritDoc) */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (first) + first = false; + else + buf.append(","); + buf.append(_set[i]); + } + } + return buf.toString(); + } + + class TShortHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** the collection on which the iterator operates */ + private final TShortHash _hash; + + /** {@inheritDoc} */ + public TShortHashIterator(TShortHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + } + + /** a view onto the values of the map. */ + protected class ValueView extends MapBackedView { + + @Override + @SuppressWarnings({ "unchecked" }) + public Iterator iterator() { + return new TShortObjectValueHashIterator(TShortObjectHashMap.this) { + @Override + protected V objectAtIndex(int index) { + return _values[index]; + } + }; + } + + @Override + public boolean containsElement(V value) { + return containsValue(value); + } + + @Override + public boolean removeElement(V value) { + V[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + if (value == values[i] || (null != values[i] && values[i].equals(value))) { + removeAt(i); + return true; + } + } + } + return false; + } + + class TShortObjectValueHashIterator extends THashPrimitiveIterator implements Iterator { + + protected final TShortObjectHashMap _map; + + public TShortObjectValueHashIterator(TShortObjectHashMap map) { + super(map); + _map = map; + } + + @SuppressWarnings("unchecked") + protected V objectAtIndex(int index) { + byte[] states = _states; + Object value = _map._values[index]; + if (states[index] != FULL) { + return null; + } + return (V) value; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings("unchecked") + public V next() { + moveToNextIndex(); + return (V) _map._values[_index]; + } + } + } + + private abstract class MapBackedView extends AbstractSet implements Set, Iterable { + + @Override + public abstract Iterator iterator(); + + public abstract boolean removeElement(E key); + + public abstract boolean containsElement(E key); + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean contains(Object key) { + return containsElement((E) key); + } + + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object o) { + return removeElement((E) o); + } + + @Override + public void clear() { + TShortObjectHashMap.this.clear(); + } + + @Override + public boolean add(E obj) { + throw new UnsupportedOperationException(); + } + + @Override + public int size() { + return TShortObjectHashMap.this.size(); + } + + @Override + public Object[] toArray() { + Object[] result = new Object[size()]; + Iterator e = iterator(); + for (int i = 0; e.hasNext(); i++) { + result[i] = e.next(); + } + return result; + } + + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) java.lang.reflect.Array.newInstance(a.getClass().getComponentType(), size); + } + + Iterator it = iterator(); + Object[] result = a; + for (int i = 0; i < size; i++) { + result[i] = it.next(); + } + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + @Override + public boolean isEmpty() { + return TShortObjectHashMap.this.isEmpty(); + } + + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + Iterator i = iterator(); + while (i.hasNext()) { + if (!collection.contains(i.next())) { + i.remove(); + changed = true; + } + } + return changed; + } + } + + class TShortObjectHashIterator extends THashPrimitiveIterator implements TShortObjectIterator { + + /** the collection being iterated over */ + private final TShortObjectHashMap _map; + + /** + * Creates an iterator over the specified map + * + * @param map + * map to iterate over. + */ + public TShortObjectHashIterator(TShortObjectHashMap map) { + super(map); + this._map = map; + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _map._set[_index]; + } + + /** {@inheritDoc} */ + @Override + public V value() { + return _map._values[_index]; + } + + /** {@inheritDoc} */ + @Override + public V setValue(V val) { + V old = value(); + _map._values[_index] = val; + return old; + } + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NO_ENTRY_KEY + out.writeShort(no_entry_key); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeObject(_values[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NO_ENTRY_KEY + no_entry_key = in.readShort(); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + V val = (V) in.readObject(); + put(key, val); + } + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, Object value) { + if (first) + first = false; + else + buf.append(","); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } +} // TShortObjectHashMap diff --git a/src/gnu/trove/map/hash/TShortShortHashMap.java b/src/gnu/trove/map/hash/TShortShortHashMap.java new file mode 100644 index 0000000..a7c2571 --- /dev/null +++ b/src/gnu/trove/map/hash/TShortShortHashMap.java @@ -0,0 +1,1304 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.map.hash; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.map.TShortShortMap; +import gnu.trove.function.TShortFunction; +import gnu.trove.procedure.*; +import gnu.trove.set.*; +import gnu.trove.iterator.*; +import gnu.trove.impl.hash.*; +import gnu.trove.impl.HashFunctions; +import gnu.trove.*; + +import java.io.*; +import java.util.*; + +/** + * An open addressed Map implementation for short keys and short values. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: _K__V_HashMap.template,v 1.1.2.16 2010/03/02 04:09:50 robeden + * Exp $ + */ +public class TShortShortHashMap extends TShortShortHash implements TShortShortMap, Externalizable { + static final long serialVersionUID = 1L; + + /** the values of the map */ + protected transient short[] _values; + + /** + * Creates a new TShortShortHashMap instance with the default + * capacity and load factor. + */ + public TShortShortHashMap() { + super(); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TShortShortHashMap(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TShortShortHashMap(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new TShortShortHashMap instance with a prime capacity + * equal to or greater than initialCapacity and with the specified load + * factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + * @param noEntryKey + * a short value that represents null for the + * Key set. + * @param noEntryValue + * a short value that represents null for the + * Value set. + */ + public TShortShortHashMap(int initialCapacity, float loadFactor, short noEntryKey, short noEntryValue) { + super(initialCapacity, loadFactor, noEntryKey, noEntryValue); + } + + /** + * Creates a new TShortShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param keys + * a short array containing the keys for the matching + * values. + * @param values + * a short array containing the values. + */ + public TShortShortHashMap(short[] keys, short[] values) { + super(Math.max(keys.length, values.length)); + + int size = Math.min(keys.length, values.length); + for (int i = 0; i < size; i++) { + this.put(keys[i], values[i]); + } + } + + /** + * Creates a new TShortShortHashMap instance containing all of the + * entries in the map passed in. + * + * @param map + * a TShortShortMap that will be duplicated. + */ + public TShortShortHashMap(TShortShortMap map) { + super(map.size()); + if (map instanceof TShortShortHashMap) { + TShortShortHashMap hashmap = (TShortShortHashMap) map; + this._loadFactor = hashmap._loadFactor; + this.no_entry_key = hashmap.no_entry_key; + this.no_entry_value = hashmap.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_key != (short) 0) { + Arrays.fill(_set, this.no_entry_key); + } + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_values, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + putAll(map); + } + + /** + * initializes the hashtable to a prime capacity which is at least + * initialCapacity + 1. + * + * @param initialCapacity + * an int value + * @return the actual capacity chosen + */ + @Override + protected int setUp(int initialCapacity) { + int capacity; + + capacity = super.setUp(initialCapacity); + _values = new short[capacity]; + return capacity; + } + + /** + * rehashes the map to the new capacity. + * + * @param newCapacity + * an int value + */ + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldKeys[] = _set; + short oldVals[] = _values; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _values = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldKeys[i]; + int index = insertKey(o); + _values[index] = oldVals[i]; + } + } + } + + /** {@inheritDoc} */ + @Override + public short put(short key, short value) { + int index = insertKey(key); + return doPut(key, value, index); + } + + /** {@inheritDoc} */ + @Override + public short putIfAbsent(short key, short value) { + int index = insertKey(key); + if (index < 0) + return _values[-index - 1]; + return doPut(key, value, index); + } + + private short doPut(short key, short value, int index) { + short previous = no_entry_value; + boolean isNewMapping = true; + if (index < 0) { + index = -index - 1; + previous = _values[index]; + isNewMapping = false; + } + _values[index] = value; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return previous; + } + + /** {@inheritDoc} */ + @Override + public void putAll(Map map) { + ensureCapacity(map.size()); + // could optimize this for cases when map instanceof THashMap + for (Map.Entry entry : map.entrySet()) { + this.put(entry.getKey().shortValue(), entry.getValue().shortValue()); + } + } + + /** {@inheritDoc} */ + @Override + public void putAll(TShortShortMap map) { + ensureCapacity(map.size()); + TShortShortIterator iter = map.iterator(); + while (iter.hasNext()) { + iter.advance(); + this.put(iter.key(), iter.value()); + } + } + + /** {@inheritDoc} */ + @Override + public short get(short key) { + int index = index(key); + return index < 0 ? no_entry_value : _values[index]; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + Arrays.fill(_set, 0, _set.length, no_entry_key); + Arrays.fill(_values, 0, _values.length, no_entry_value); + Arrays.fill(_states, 0, _states.length, FREE); + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public short remove(short key) { + short prev = no_entry_value; + int index = index(key); + if (index >= 0) { + prev = _values[index]; + removeAt(index); // clear key,state; adjust size + } + return prev; + } + + /** {@inheritDoc} */ + @Override + protected void removeAt(int index) { + _values[index] = no_entry_value; + super.removeAt(index); // clear key, state; adjust size + } + + /** {@inheritDoc} */ + @Override + public TShortSet keySet() { + return new TKeyView(); + } + + /** {@inheritDoc} */ + @Override + public short[] keys() { + short[] keys = new short[size()]; + if (keys.length == 0) { + return keys; // nothing to copy + } + short[] k = _set; + byte[] states = _states; + + for (int i = k.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + keys[j++] = k[i]; + } + } + return keys; + } + + /** {@inheritDoc} */ + @Override + public short[] keys(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] keys = _set; + byte[] states = _states; + + for (int i = keys.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = keys[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public TShortCollection valueCollection() { + return new TValueView(); + } + + /** {@inheritDoc} */ + @Override + public short[] values() { + short[] vals = new short[size()]; + if (vals.length == 0) { + return vals; // nothing to copy + } + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + vals[j++] = v[i]; + } + } + return vals; + } + + /** {@inheritDoc} */ + @Override + public short[] values(short[] array) { + int size = size(); + if (size == 0) { + return array; // nothing to copy + } + if (array.length < size) { + array = new short[size]; + } + + short[] v = _values; + byte[] states = _states; + + for (int i = v.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + array[j++] = v[i]; + } + } + return array; + } + + /** {@inheritDoc} */ + @Override + public boolean containsValue(short val) { + byte[] states = _states; + short[] vals = _values; + + for (int i = vals.length; i-- > 0;) { + if (states[i] == FULL && val == vals[i]) { + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsKey(short key) { + return contains(key); + } + + /** {@inheritDoc} */ + @Override + public TShortShortIterator iterator() { + return new TShortShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachKey(TShortProcedure procedure) { + return forEach(procedure); + } + + /** {@inheritDoc} */ + @Override + public boolean forEachValue(TShortProcedure procedure) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean forEachEntry(TShortShortProcedure procedure) { + byte[] states = _states; + short[] keys = _set; + short[] values = _values; + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public void transformValues(TShortFunction function) { + byte[] states = _states; + short[] values = _values; + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + values[i] = function.execute(values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean retainEntries(TShortShortProcedure procedure) { + boolean modified = false; + byte[] states = _states; + short[] keys = _set; + short[] values = _values; + + // Temporarily disable compaction. This is a fix for bug #1738760 + tempDisableAutoCompaction(); + try { + for (int i = keys.length; i-- > 0;) { + if (states[i] == FULL && !procedure.execute(keys[i], values[i])) { + removeAt(i); + modified = true; + } + } + } finally { + reenableAutoCompaction(true); + } + + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean increment(short key) { + return adjustValue(key, (short) 1); + } + + /** {@inheritDoc} */ + @Override + public boolean adjustValue(short key, short amount) { + int index = index(key); + if (index < 0) { + return false; + } else { + _values[index] += amount; + return true; + } + } + + /** {@inheritDoc} */ + @Override + public short adjustOrPutValue(short key, short adjust_amount, short put_amount) { + int index = insertKey(key); + final boolean isNewMapping; + final short newValue; + if (index < 0) { + index = -index - 1; + newValue = (_values[index] += adjust_amount); + isNewMapping = false; + } else { + newValue = (_values[index] = put_amount); + isNewMapping = true; + } + + byte previousState = _states[index]; + + if (isNewMapping) { + postInsertHook(consumeFreeSlot); + } + + return newValue; + } + + /** a view onto the keys of the map. */ + protected class TKeyView implements TShortSet { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortShortKeyHashIterator(TShortShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_key; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortShortHashMap.this.contains(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortShortHashMap.this.keys(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortShortHashMap.this.keys(dest); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + return no_entry_value != TShortShortHashMap.this.remove(entry); + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortShortHashMap.this.containsKey(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortShortHashMap.this.containsKey(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortShortHashMap.this.contains(element)) { + return false; + } + } + return true; + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** + * Unsupported when operating upon a Key Set view of a TShortShortMap + *

+ * {@inheritDoc} + */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortShortHashMap.this.forEachKey(procedure); + } + + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + final TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachKey(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(key); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + /** a view onto the values of the map. */ + protected class TValueView implements TShortCollection { + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortShortValueHashIterator(TShortShortHashMap.this); + } + + /** {@inheritDoc} */ + @Override + public short getNoEntryValue() { + return no_entry_value; + } + + /** {@inheritDoc} */ + @Override + public int size() { + return _size; + } + + /** {@inheritDoc} */ + @Override + public boolean isEmpty() { + return 0 == _size; + } + + /** {@inheritDoc} */ + @Override + public boolean contains(short entry) { + return TShortShortHashMap.this.containsValue(entry); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + return TShortShortHashMap.this.values(); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + return TShortShortHashMap.this.values(dest); + } + + @Override + public boolean add(short entry) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short entry) { + short[] values = _values; + short[] set = _set; + + for (int i = values.length; i-- > 0;) { + if ((set[i] != FREE && set[i] != REMOVED) && entry == values[i]) { + removeAt(i); + return true; + } + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short ele = ((Short) element).shortValue(); + if (!TShortShortHashMap.this.containsValue(ele)) { + return false; + } + } else { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + if (!TShortShortHashMap.this.containsValue(iter.next())) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (short element : array) { + if (!TShortShortHashMap.this.containsValue(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + throw new UnsupportedOperationException(); + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] values = _values; + byte[] states = _states; + + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, values[i]) < 0)) { + removeAt(i); + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + if (this == collection) { + clear(); + return true; + } + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + TShortShortHashMap.this.clear(); + } + + /** {@inheritDoc} */ + @Override + public boolean forEach(TShortProcedure procedure) { + return TShortShortHashMap.this.forEachValue(procedure); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachValue(new TShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + } + + class TShortShortKeyHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortShortKeyHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _set[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortShortValueHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param hash + * the TPrimitiveHash we will be iterating over. + */ + TShortShortValueHashIterator(TPrimitiveHash hash) { + super(hash); + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _values[_index]; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + + _expectedSize--; + } + } + + class TShortShortHashIterator extends THashPrimitiveIterator implements TShortShortIterator { + + /** + * Creates an iterator over the specified map + * + * @param map + * the TShortShortHashMap we will be iterating over. + */ + TShortShortHashIterator(TShortShortHashMap map) { + super(map); + } + + /** {@inheritDoc} */ + @Override + public void advance() { + moveToNextIndex(); + } + + /** {@inheritDoc} */ + @Override + public short key() { + return _set[_index]; + } + + /** {@inheritDoc} */ + @Override + public short value() { + return _values[_index]; + } + + /** {@inheritDoc} */ + @Override + public short setValue(short val) { + short old = value(); + _values[_index] = val; + return old; + } + + /** @{inheritDoc} */ + @Override + public void remove() { + if (_expectedSize != _hash.size()) { + throw new ConcurrentModificationException(); + } + // Disable auto compaction during the remove. This is a workaround for bug + // 1642768. + try { + _hash.tempDisableAutoCompaction(); + TShortShortHashMap.this.removeAt(_index); + } finally { + _hash.reenableAutoCompaction(false); + } + _expectedSize--; + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortShortMap)) { + return false; + } + TShortShortMap that = (TShortShortMap) other; + if (that.size() != this.size()) { + return false; + } + short[] values = _values; + byte[] states = _states; + short this_no_entry_value = getNoEntryValue(); + short that_no_entry_value = that.getNoEntryValue(); + for (int i = values.length; i-- > 0;) { + if (states[i] == FULL) { + short key = _set[i]; + short that_value = that.get(key); + short this_value = values[i]; + if ((this_value != that_value) && (this_value != this_no_entry_value) + && (that_value != that_no_entry_value)) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + byte[] states = _states; + for (int i = _values.length; i-- > 0;) { + if (states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]) ^ HashFunctions.hash(_values[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEachEntry(new TShortShortProcedure() { + private boolean first = true; + + @Override + public boolean execute(short key, short value) { + if (first) + first = false; + else + buf.append(", "); + + buf.append(key); + buf.append("="); + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + out.writeShort(_values[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + // VERSION + in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + short key = in.readShort(); + short val = in.readShort(); + put(key, val); + } + } +} // TShortShortHashMap diff --git a/src/gnu/trove/procedure/TByteByteProcedure.java b/src/gnu/trove/procedure/TByteByteProcedure.java new file mode 100644 index 0000000..7db91f6 --- /dev/null +++ b/src/gnu/trove/procedure/TByteByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and byte. + */ +public interface TByteByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, byte b); +} diff --git a/src/gnu/trove/procedure/TByteCharProcedure.java b/src/gnu/trove/procedure/TByteCharProcedure.java new file mode 100644 index 0000000..335f252 --- /dev/null +++ b/src/gnu/trove/procedure/TByteCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and char. + */ +public interface TByteCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, char b); +} diff --git a/src/gnu/trove/procedure/TByteDoubleProcedure.java b/src/gnu/trove/procedure/TByteDoubleProcedure.java new file mode 100644 index 0000000..ee037f6 --- /dev/null +++ b/src/gnu/trove/procedure/TByteDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and double. + */ +public interface TByteDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, double b); +} diff --git a/src/gnu/trove/procedure/TByteFloatProcedure.java b/src/gnu/trove/procedure/TByteFloatProcedure.java new file mode 100644 index 0000000..268bfbb --- /dev/null +++ b/src/gnu/trove/procedure/TByteFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and float. + */ +public interface TByteFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, float b); +} diff --git a/src/gnu/trove/procedure/TByteIntProcedure.java b/src/gnu/trove/procedure/TByteIntProcedure.java new file mode 100644 index 0000000..20318fb --- /dev/null +++ b/src/gnu/trove/procedure/TByteIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and int. + */ +public interface TByteIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, int b); +} diff --git a/src/gnu/trove/procedure/TByteLongProcedure.java b/src/gnu/trove/procedure/TByteLongProcedure.java new file mode 100644 index 0000000..b8525ae --- /dev/null +++ b/src/gnu/trove/procedure/TByteLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and long. + */ +public interface TByteLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, long b); +} diff --git a/src/gnu/trove/procedure/TByteObjectProcedure.java b/src/gnu/trove/procedure/TByteObjectProcedure.java new file mode 100644 index 0000000..facc4b4 --- /dev/null +++ b/src/gnu/trove/procedure/TByteObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and Object. + */ +public interface TByteObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, T b); +} diff --git a/src/gnu/trove/procedure/TByteProcedure.java b/src/gnu/trove/procedure/TByteProcedure.java new file mode 100644 index 0000000..318dd76 --- /dev/null +++ b/src/gnu/trove/procedure/TByteProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one byte parameter. + */ +public interface TByteProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type byte + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte value); +} diff --git a/src/gnu/trove/procedure/TByteShortProcedure.java b/src/gnu/trove/procedure/TByteShortProcedure.java new file mode 100644 index 0000000..a54d2ec --- /dev/null +++ b/src/gnu/trove/procedure/TByteShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type byte and short. + */ +public interface TByteShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a byte value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(byte a, short b); +} diff --git a/src/gnu/trove/procedure/TCharByteProcedure.java b/src/gnu/trove/procedure/TCharByteProcedure.java new file mode 100644 index 0000000..ff7a99e --- /dev/null +++ b/src/gnu/trove/procedure/TCharByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and byte. + */ +public interface TCharByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, byte b); +} diff --git a/src/gnu/trove/procedure/TCharCharProcedure.java b/src/gnu/trove/procedure/TCharCharProcedure.java new file mode 100644 index 0000000..c00cd73 --- /dev/null +++ b/src/gnu/trove/procedure/TCharCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and char. + */ +public interface TCharCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, char b); +} diff --git a/src/gnu/trove/procedure/TCharDoubleProcedure.java b/src/gnu/trove/procedure/TCharDoubleProcedure.java new file mode 100644 index 0000000..26bc854 --- /dev/null +++ b/src/gnu/trove/procedure/TCharDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and double. + */ +public interface TCharDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, double b); +} diff --git a/src/gnu/trove/procedure/TCharFloatProcedure.java b/src/gnu/trove/procedure/TCharFloatProcedure.java new file mode 100644 index 0000000..b17249c --- /dev/null +++ b/src/gnu/trove/procedure/TCharFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and float. + */ +public interface TCharFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, float b); +} diff --git a/src/gnu/trove/procedure/TCharIntProcedure.java b/src/gnu/trove/procedure/TCharIntProcedure.java new file mode 100644 index 0000000..ec40420 --- /dev/null +++ b/src/gnu/trove/procedure/TCharIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and int. + */ +public interface TCharIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, int b); +} diff --git a/src/gnu/trove/procedure/TCharLongProcedure.java b/src/gnu/trove/procedure/TCharLongProcedure.java new file mode 100644 index 0000000..852835f --- /dev/null +++ b/src/gnu/trove/procedure/TCharLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and long. + */ +public interface TCharLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, long b); +} diff --git a/src/gnu/trove/procedure/TCharObjectProcedure.java b/src/gnu/trove/procedure/TCharObjectProcedure.java new file mode 100644 index 0000000..9b83fcf --- /dev/null +++ b/src/gnu/trove/procedure/TCharObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and Object. + */ +public interface TCharObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, T b); +} diff --git a/src/gnu/trove/procedure/TCharProcedure.java b/src/gnu/trove/procedure/TCharProcedure.java new file mode 100644 index 0000000..53b156b --- /dev/null +++ b/src/gnu/trove/procedure/TCharProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one char parameter. + */ +public interface TCharProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type char + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char value); +} diff --git a/src/gnu/trove/procedure/TCharShortProcedure.java b/src/gnu/trove/procedure/TCharShortProcedure.java new file mode 100644 index 0000000..b464a15 --- /dev/null +++ b/src/gnu/trove/procedure/TCharShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type char and short. + */ +public interface TCharShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a char value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(char a, short b); +} diff --git a/src/gnu/trove/procedure/TDoubleByteProcedure.java b/src/gnu/trove/procedure/TDoubleByteProcedure.java new file mode 100644 index 0000000..419d5a8 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and byte. + */ +public interface TDoubleByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, byte b); +} diff --git a/src/gnu/trove/procedure/TDoubleCharProcedure.java b/src/gnu/trove/procedure/TDoubleCharProcedure.java new file mode 100644 index 0000000..15f930a --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and char. + */ +public interface TDoubleCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, char b); +} diff --git a/src/gnu/trove/procedure/TDoubleDoubleProcedure.java b/src/gnu/trove/procedure/TDoubleDoubleProcedure.java new file mode 100644 index 0000000..2499501 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and double. + */ +public interface TDoubleDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, double b); +} diff --git a/src/gnu/trove/procedure/TDoubleFloatProcedure.java b/src/gnu/trove/procedure/TDoubleFloatProcedure.java new file mode 100644 index 0000000..a2cda60 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and float. + */ +public interface TDoubleFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, float b); +} diff --git a/src/gnu/trove/procedure/TDoubleIntProcedure.java b/src/gnu/trove/procedure/TDoubleIntProcedure.java new file mode 100644 index 0000000..758e2e8 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and int. + */ +public interface TDoubleIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, int b); +} diff --git a/src/gnu/trove/procedure/TDoubleLongProcedure.java b/src/gnu/trove/procedure/TDoubleLongProcedure.java new file mode 100644 index 0000000..559199d --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and long. + */ +public interface TDoubleLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, long b); +} diff --git a/src/gnu/trove/procedure/TDoubleObjectProcedure.java b/src/gnu/trove/procedure/TDoubleObjectProcedure.java new file mode 100644 index 0000000..c585c7b --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and Object. + */ +public interface TDoubleObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, T b); +} diff --git a/src/gnu/trove/procedure/TDoubleProcedure.java b/src/gnu/trove/procedure/TDoubleProcedure.java new file mode 100644 index 0000000..f7f0779 --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one double parameter. + */ +public interface TDoubleProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type double + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double value); +} diff --git a/src/gnu/trove/procedure/TDoubleShortProcedure.java b/src/gnu/trove/procedure/TDoubleShortProcedure.java new file mode 100644 index 0000000..582ad4b --- /dev/null +++ b/src/gnu/trove/procedure/TDoubleShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type double and short. + */ +public interface TDoubleShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a double value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(double a, short b); +} diff --git a/src/gnu/trove/procedure/TFloatByteProcedure.java b/src/gnu/trove/procedure/TFloatByteProcedure.java new file mode 100644 index 0000000..8274243 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and byte. + */ +public interface TFloatByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, byte b); +} diff --git a/src/gnu/trove/procedure/TFloatCharProcedure.java b/src/gnu/trove/procedure/TFloatCharProcedure.java new file mode 100644 index 0000000..443b4d3 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and char. + */ +public interface TFloatCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, char b); +} diff --git a/src/gnu/trove/procedure/TFloatDoubleProcedure.java b/src/gnu/trove/procedure/TFloatDoubleProcedure.java new file mode 100644 index 0000000..5fa8ec9 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and double. + */ +public interface TFloatDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, double b); +} diff --git a/src/gnu/trove/procedure/TFloatFloatProcedure.java b/src/gnu/trove/procedure/TFloatFloatProcedure.java new file mode 100644 index 0000000..58f7564 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and float. + */ +public interface TFloatFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, float b); +} diff --git a/src/gnu/trove/procedure/TFloatIntProcedure.java b/src/gnu/trove/procedure/TFloatIntProcedure.java new file mode 100644 index 0000000..30637c3 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and int. + */ +public interface TFloatIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, int b); +} diff --git a/src/gnu/trove/procedure/TFloatLongProcedure.java b/src/gnu/trove/procedure/TFloatLongProcedure.java new file mode 100644 index 0000000..1dfc596 --- /dev/null +++ b/src/gnu/trove/procedure/TFloatLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and long. + */ +public interface TFloatLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, long b); +} diff --git a/src/gnu/trove/procedure/TFloatObjectProcedure.java b/src/gnu/trove/procedure/TFloatObjectProcedure.java new file mode 100644 index 0000000..d0fd95e --- /dev/null +++ b/src/gnu/trove/procedure/TFloatObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and Object. + */ +public interface TFloatObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, T b); +} diff --git a/src/gnu/trove/procedure/TFloatProcedure.java b/src/gnu/trove/procedure/TFloatProcedure.java new file mode 100644 index 0000000..7732a1a --- /dev/null +++ b/src/gnu/trove/procedure/TFloatProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one float parameter. + */ +public interface TFloatProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type float + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float value); +} diff --git a/src/gnu/trove/procedure/TFloatShortProcedure.java b/src/gnu/trove/procedure/TFloatShortProcedure.java new file mode 100644 index 0000000..fc4fb5b --- /dev/null +++ b/src/gnu/trove/procedure/TFloatShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type float and short. + */ +public interface TFloatShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a float value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(float a, short b); +} diff --git a/src/gnu/trove/procedure/TIntByteProcedure.java b/src/gnu/trove/procedure/TIntByteProcedure.java new file mode 100644 index 0000000..453045b --- /dev/null +++ b/src/gnu/trove/procedure/TIntByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and byte. + */ +public interface TIntByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, byte b); +} diff --git a/src/gnu/trove/procedure/TIntCharProcedure.java b/src/gnu/trove/procedure/TIntCharProcedure.java new file mode 100644 index 0000000..017a3b5 --- /dev/null +++ b/src/gnu/trove/procedure/TIntCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and char. + */ +public interface TIntCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, char b); +} diff --git a/src/gnu/trove/procedure/TIntDoubleProcedure.java b/src/gnu/trove/procedure/TIntDoubleProcedure.java new file mode 100644 index 0000000..a02577f --- /dev/null +++ b/src/gnu/trove/procedure/TIntDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and double. + */ +public interface TIntDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, double b); +} diff --git a/src/gnu/trove/procedure/TIntFloatProcedure.java b/src/gnu/trove/procedure/TIntFloatProcedure.java new file mode 100644 index 0000000..8d2045f --- /dev/null +++ b/src/gnu/trove/procedure/TIntFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and float. + */ +public interface TIntFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, float b); +} diff --git a/src/gnu/trove/procedure/TIntIntProcedure.java b/src/gnu/trove/procedure/TIntIntProcedure.java new file mode 100644 index 0000000..72b328c --- /dev/null +++ b/src/gnu/trove/procedure/TIntIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and int. + */ +public interface TIntIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, int b); +} diff --git a/src/gnu/trove/procedure/TIntLongProcedure.java b/src/gnu/trove/procedure/TIntLongProcedure.java new file mode 100644 index 0000000..f4dd5d4 --- /dev/null +++ b/src/gnu/trove/procedure/TIntLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and long. + */ +public interface TIntLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, long b); +} diff --git a/src/gnu/trove/procedure/TIntObjectProcedure.java b/src/gnu/trove/procedure/TIntObjectProcedure.java new file mode 100644 index 0000000..d0311d1 --- /dev/null +++ b/src/gnu/trove/procedure/TIntObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and Object. + */ +public interface TIntObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, T b); +} diff --git a/src/gnu/trove/procedure/TIntProcedure.java b/src/gnu/trove/procedure/TIntProcedure.java new file mode 100644 index 0000000..12a2958 --- /dev/null +++ b/src/gnu/trove/procedure/TIntProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one int parameter. + */ +public interface TIntProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int value); +} diff --git a/src/gnu/trove/procedure/TIntShortProcedure.java b/src/gnu/trove/procedure/TIntShortProcedure.java new file mode 100644 index 0000000..4b52a07 --- /dev/null +++ b/src/gnu/trove/procedure/TIntShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type int and short. + */ +public interface TIntShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a int value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(int a, short b); +} diff --git a/src/gnu/trove/procedure/TLongByteProcedure.java b/src/gnu/trove/procedure/TLongByteProcedure.java new file mode 100644 index 0000000..cc30058 --- /dev/null +++ b/src/gnu/trove/procedure/TLongByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and byte. + */ +public interface TLongByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, byte b); +} diff --git a/src/gnu/trove/procedure/TLongCharProcedure.java b/src/gnu/trove/procedure/TLongCharProcedure.java new file mode 100644 index 0000000..d115f1a --- /dev/null +++ b/src/gnu/trove/procedure/TLongCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and char. + */ +public interface TLongCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, char b); +} diff --git a/src/gnu/trove/procedure/TLongDoubleProcedure.java b/src/gnu/trove/procedure/TLongDoubleProcedure.java new file mode 100644 index 0000000..90667c2 --- /dev/null +++ b/src/gnu/trove/procedure/TLongDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and double. + */ +public interface TLongDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, double b); +} diff --git a/src/gnu/trove/procedure/TLongFloatProcedure.java b/src/gnu/trove/procedure/TLongFloatProcedure.java new file mode 100644 index 0000000..0651631 --- /dev/null +++ b/src/gnu/trove/procedure/TLongFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and float. + */ +public interface TLongFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, float b); +} diff --git a/src/gnu/trove/procedure/TLongIntProcedure.java b/src/gnu/trove/procedure/TLongIntProcedure.java new file mode 100644 index 0000000..c500d50 --- /dev/null +++ b/src/gnu/trove/procedure/TLongIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and int. + */ +public interface TLongIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, int b); +} diff --git a/src/gnu/trove/procedure/TLongLongProcedure.java b/src/gnu/trove/procedure/TLongLongProcedure.java new file mode 100644 index 0000000..a00d6e3 --- /dev/null +++ b/src/gnu/trove/procedure/TLongLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and long. + */ +public interface TLongLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, long b); +} diff --git a/src/gnu/trove/procedure/TLongObjectProcedure.java b/src/gnu/trove/procedure/TLongObjectProcedure.java new file mode 100644 index 0000000..4f2b50d --- /dev/null +++ b/src/gnu/trove/procedure/TLongObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and Object. + */ +public interface TLongObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, T b); +} diff --git a/src/gnu/trove/procedure/TLongProcedure.java b/src/gnu/trove/procedure/TLongProcedure.java new file mode 100644 index 0000000..86fe384 --- /dev/null +++ b/src/gnu/trove/procedure/TLongProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one long parameter. + */ +public interface TLongProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type long + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long value); +} diff --git a/src/gnu/trove/procedure/TLongShortProcedure.java b/src/gnu/trove/procedure/TLongShortProcedure.java new file mode 100644 index 0000000..6ceda35 --- /dev/null +++ b/src/gnu/trove/procedure/TLongShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type long and short. + */ +public interface TLongShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a long value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(long a, short b); +} diff --git a/src/gnu/trove/procedure/TObjectByteProcedure.java b/src/gnu/trove/procedure/TObjectByteProcedure.java new file mode 100644 index 0000000..b6f0918 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and byte. + */ +public interface TObjectByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, byte b); +} diff --git a/src/gnu/trove/procedure/TObjectCharProcedure.java b/src/gnu/trove/procedure/TObjectCharProcedure.java new file mode 100644 index 0000000..74a0528 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and char. + */ +public interface TObjectCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, char b); +} diff --git a/src/gnu/trove/procedure/TObjectDoubleProcedure.java b/src/gnu/trove/procedure/TObjectDoubleProcedure.java new file mode 100644 index 0000000..4eaf03d --- /dev/null +++ b/src/gnu/trove/procedure/TObjectDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and double. + */ +public interface TObjectDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, double b); +} diff --git a/src/gnu/trove/procedure/TObjectFloatProcedure.java b/src/gnu/trove/procedure/TObjectFloatProcedure.java new file mode 100644 index 0000000..69b93f3 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and float. + */ +public interface TObjectFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, float b); +} diff --git a/src/gnu/trove/procedure/TObjectIntProcedure.java b/src/gnu/trove/procedure/TObjectIntProcedure.java new file mode 100644 index 0000000..520f045 --- /dev/null +++ b/src/gnu/trove/procedure/TObjectIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and int. + */ +public interface TObjectIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, int b); +} diff --git a/src/gnu/trove/procedure/TObjectLongProcedure.java b/src/gnu/trove/procedure/TObjectLongProcedure.java new file mode 100644 index 0000000..4510e2a --- /dev/null +++ b/src/gnu/trove/procedure/TObjectLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and long. + */ +public interface TObjectLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, long b); +} diff --git a/src/gnu/trove/procedure/TObjectObjectProcedure.java b/src/gnu/trove/procedure/TObjectObjectProcedure.java new file mode 100644 index 0000000..60d226f --- /dev/null +++ b/src/gnu/trove/procedure/TObjectObjectProcedure.java @@ -0,0 +1,44 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +/** + * Interface for procedures that take two Object parameters. + *

+ * Created: Mon Nov 5 22:03:30 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectObjectProcedure.java,v 1.1.2.1 2009/09/06 17:02:20 + * upholderoftruth Exp $ + */ + +public interface TObjectObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, V b); +}// TObjectObjectProcedure diff --git a/src/gnu/trove/procedure/TObjectProcedure.java b/src/gnu/trove/procedure/TObjectProcedure.java new file mode 100644 index 0000000..4dff70d --- /dev/null +++ b/src/gnu/trove/procedure/TObjectProcedure.java @@ -0,0 +1,41 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +/** + * Interface for procedures with one Object parameter. + * + * Created: Mon Nov 5 21:45:49 2001 + * + * @author Eric D. Friedman + * @version $Id: TObjectProcedure.java,v 1.1.2.1 2009/09/02 21:52:33 + * upholderoftruth Exp $ + */ + +public interface TObjectProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param object + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(T object); +}// TObjectProcedure diff --git a/src/gnu/trove/procedure/TObjectShortProcedure.java b/src/gnu/trove/procedure/TObjectShortProcedure.java new file mode 100644 index 0000000..41f080a --- /dev/null +++ b/src/gnu/trove/procedure/TObjectShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type Object and short. + */ +public interface TObjectShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * an Object value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(K a, short b); +} diff --git a/src/gnu/trove/procedure/TShortByteProcedure.java b/src/gnu/trove/procedure/TShortByteProcedure.java new file mode 100644 index 0000000..e63ef7f --- /dev/null +++ b/src/gnu/trove/procedure/TShortByteProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and byte. + */ +public interface TShortByteProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a byte value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, byte b); +} diff --git a/src/gnu/trove/procedure/TShortCharProcedure.java b/src/gnu/trove/procedure/TShortCharProcedure.java new file mode 100644 index 0000000..d887290 --- /dev/null +++ b/src/gnu/trove/procedure/TShortCharProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and char. + */ +public interface TShortCharProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a char value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, char b); +} diff --git a/src/gnu/trove/procedure/TShortDoubleProcedure.java b/src/gnu/trove/procedure/TShortDoubleProcedure.java new file mode 100644 index 0000000..f9ff1a1 --- /dev/null +++ b/src/gnu/trove/procedure/TShortDoubleProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and double. + */ +public interface TShortDoubleProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a double value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, double b); +} diff --git a/src/gnu/trove/procedure/TShortFloatProcedure.java b/src/gnu/trove/procedure/TShortFloatProcedure.java new file mode 100644 index 0000000..87d2f53 --- /dev/null +++ b/src/gnu/trove/procedure/TShortFloatProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and float. + */ +public interface TShortFloatProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a float value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, float b); +} diff --git a/src/gnu/trove/procedure/TShortIntProcedure.java b/src/gnu/trove/procedure/TShortIntProcedure.java new file mode 100644 index 0000000..8b1c1a9 --- /dev/null +++ b/src/gnu/trove/procedure/TShortIntProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and int. + */ +public interface TShortIntProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a int value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, int b); +} diff --git a/src/gnu/trove/procedure/TShortLongProcedure.java b/src/gnu/trove/procedure/TShortLongProcedure.java new file mode 100644 index 0000000..827c50b --- /dev/null +++ b/src/gnu/trove/procedure/TShortLongProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and long. + */ +public interface TShortLongProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a long value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, long b); +} diff --git a/src/gnu/trove/procedure/TShortObjectProcedure.java b/src/gnu/trove/procedure/TShortObjectProcedure.java new file mode 100644 index 0000000..91b8a22 --- /dev/null +++ b/src/gnu/trove/procedure/TShortObjectProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and Object. + */ +public interface TShortObjectProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * an Object value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, T b); +} diff --git a/src/gnu/trove/procedure/TShortProcedure.java b/src/gnu/trove/procedure/TShortProcedure.java new file mode 100644 index 0000000..96ec21e --- /dev/null +++ b/src/gnu/trove/procedure/TShortProcedure.java @@ -0,0 +1,38 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures with one short parameter. + */ +public interface TShortProcedure { + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type short + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short value); +} diff --git a/src/gnu/trove/procedure/TShortShortProcedure.java b/src/gnu/trove/procedure/TShortShortProcedure.java new file mode 100644 index 0000000..0b19c7a --- /dev/null +++ b/src/gnu/trove/procedure/TShortShortProcedure.java @@ -0,0 +1,42 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * Interface for procedures that take two parameters of type short and short. + */ +public interface TShortShortProcedure { + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param a + * a short value + * @param b + * a short value + * @return true if additional invocations of the procedure are allowed. + */ + public boolean execute(short a, short b); +} diff --git a/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java b/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java new file mode 100644 index 0000000..583cb6a --- /dev/null +++ b/src/gnu/trove/procedure/array/ToObjectArrayProceedure.java @@ -0,0 +1,47 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.procedure.array; + +import gnu.trove.procedure.TObjectProcedure; + +/** + * A procedure which stores each value it receives into a target array. + *

+ * Created: Sat Jan 12 10:13:42 2002 + * + * @author Eric D. Friedman + * @version $Id: ToObjectArrayProceedure.java,v 1.1.2.1 2009/09/02 21:52:33 + * upholderoftruth Exp $ + */ + +public final class ToObjectArrayProceedure implements TObjectProcedure { + + private final T[] target; + private int pos = 0; + + public ToObjectArrayProceedure(final T[] target) { + this.target = target; + } + + @Override + public final boolean execute(T value) { + target[pos++] = value; + return true; + } +} // ToObjectArrayProcedure \ No newline at end of file diff --git a/src/gnu/trove/queue/TByteQueue.java b/src/gnu/trove/queue/TByteQueue.java new file mode 100644 index 0000000..3c9bca5 --- /dev/null +++ b/src/gnu/trove/queue/TByteQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TByteCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TByteQueue extends TByteCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public byte element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(byte e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public byte peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public byte poll(); +} diff --git a/src/gnu/trove/queue/TCharQueue.java b/src/gnu/trove/queue/TCharQueue.java new file mode 100644 index 0000000..3713793 --- /dev/null +++ b/src/gnu/trove/queue/TCharQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TCharCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TCharQueue extends TCharCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public char element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(char e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public char peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public char poll(); +} diff --git a/src/gnu/trove/queue/TDoubleQueue.java b/src/gnu/trove/queue/TDoubleQueue.java new file mode 100644 index 0000000..78474c2 --- /dev/null +++ b/src/gnu/trove/queue/TDoubleQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TDoubleCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TDoubleQueue extends TDoubleCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public double element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(double e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public double peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public double poll(); +} diff --git a/src/gnu/trove/queue/TFloatQueue.java b/src/gnu/trove/queue/TFloatQueue.java new file mode 100644 index 0000000..fa5b977 --- /dev/null +++ b/src/gnu/trove/queue/TFloatQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TFloatCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TFloatQueue extends TFloatCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public float element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(float e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public float peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public float poll(); +} diff --git a/src/gnu/trove/queue/TIntQueue.java b/src/gnu/trove/queue/TIntQueue.java new file mode 100644 index 0000000..5926dbe --- /dev/null +++ b/src/gnu/trove/queue/TIntQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TIntCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TIntQueue extends TIntCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public int element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(int e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public int peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public int poll(); +} diff --git a/src/gnu/trove/queue/TLongQueue.java b/src/gnu/trove/queue/TLongQueue.java new file mode 100644 index 0000000..7171d55 --- /dev/null +++ b/src/gnu/trove/queue/TLongQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TLongCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TLongQueue extends TLongCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public long element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(long e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public long peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public long poll(); +} diff --git a/src/gnu/trove/queue/TShortQueue.java b/src/gnu/trove/queue/TShortQueue.java new file mode 100644 index 0000000..da65657 --- /dev/null +++ b/src/gnu/trove/queue/TShortQueue.java @@ -0,0 +1,67 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.queue; + +import gnu.trove.TShortCollection; + +/** + * Interface for Trove queue implementations. + * + * @see java.util.Queue + */ +public interface TShortQueue extends TShortCollection { + /** + * Retrieves and removes the head of this queue. This method differs from + * {@link #poll} only in that it throws an exception if this queue is empty. + */ + public short element(); + + /** + * Inserts the specified element into this queue if it is possible to do so + * immediately without violating capacity restrictions. When using a + * capacity-restricted queue, this method is generally preferable to + * {@link #add}, which can fail to insert an element only by throwing an + * exception. + * + * @param e + * The element to add. + * + * @return true if the element was added to this queue, else + * false + */ + public boolean offer(short e); + + /** + * Retrieves, but does not remove, the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public short peek(); + + /** + * Retrieves and removes the head of this queue, or returns + * {@link #getNoEntryValue} if this queue is empty. + * + * @return the head of this queue, or {@link #getNoEntryValue} if this queue is + * empty + */ + public short poll(); +} diff --git a/src/gnu/trove/set/TByteSet.java b/src/gnu/trove/set/TByteSet.java new file mode 100644 index 0000000..2f5f0c5 --- /dev/null +++ b/src/gnu/trove/set/TByteSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TByteIterator; +import gnu.trove.procedure.TByteProcedure; +import gnu.trove.TByteCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TByteSet extends TByteCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + byte getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an byte value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(byte entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TByteIterator value + */ + @Override + TByteIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + byte[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an byte[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + byte[] toArray(byte[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a byte value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(byte entry); + + /** + * Removes entry from the set. + * + * @param entry + * an byte value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(byte entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TByteCollection + * are present. + * + * @param collection + * a TByteCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TByteCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of byte primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(byte[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TByteCollection to the set. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TByteCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of byte primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(byte[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TByteCollection. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TByteCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of byte primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(byte[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TByteCollection from the set. + * + * @param collection + * a TByteCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TByteCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of byte primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(byte[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TByteProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TByteProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TCharSet.java b/src/gnu/trove/set/TCharSet.java new file mode 100644 index 0000000..a444222 --- /dev/null +++ b/src/gnu/trove/set/TCharSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TCharIterator; +import gnu.trove.procedure.TCharProcedure; +import gnu.trove.TCharCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TCharSet extends TCharCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + char getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an char value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(char entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TCharIterator value + */ + @Override + TCharIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + char[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an char[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + char[] toArray(char[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a char value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(char entry); + + /** + * Removes entry from the set. + * + * @param entry + * an char value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(char entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TCharCollection + * are present. + * + * @param collection + * a TCharCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TCharCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of char primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(char[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TCharCollection to the set. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TCharCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of char primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(char[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TCharCollection. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TCharCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of char primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(char[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TCharCollection from the set. + * + * @param collection + * a TCharCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TCharCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of char primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(char[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TCharProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TCharProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TDoubleSet.java b/src/gnu/trove/set/TDoubleSet.java new file mode 100644 index 0000000..52f8140 --- /dev/null +++ b/src/gnu/trove/set/TDoubleSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.procedure.TDoubleProcedure; +import gnu.trove.TDoubleCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TDoubleSet extends TDoubleCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + double getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an double value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(double entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TDoubleIterator value + */ + @Override + TDoubleIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + double[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an double[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + double[] toArray(double[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a double value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(double entry); + + /** + * Removes entry from the set. + * + * @param entry + * an double value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(double entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TDoubleCollection are present. + * + * @param collection + * a TDoubleCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TDoubleCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of double primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(double[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TDoubleCollection to the set. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TDoubleCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of double primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(double[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TDoubleCollection. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TDoubleCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of double primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(double[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TDoubleCollection from the set. + * + * @param collection + * a TDoubleCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TDoubleCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of double primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(double[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TDoubleProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TDoubleProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TFloatSet.java b/src/gnu/trove/set/TFloatSet.java new file mode 100644 index 0000000..862c4f2 --- /dev/null +++ b/src/gnu/trove/set/TFloatSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.procedure.TFloatProcedure; +import gnu.trove.TFloatCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TFloatSet extends TFloatCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + float getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an float value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(float entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TFloatIterator value + */ + @Override + TFloatIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + float[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an float[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + float[] toArray(float[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a float value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(float entry); + + /** + * Removes entry from the set. + * + * @param entry + * an float value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(float entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TFloatCollection are present. + * + * @param collection + * a TFloatCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TFloatCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of float primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(float[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TFloatCollection to the set. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TFloatCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of float primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(float[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TFloatCollection. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TFloatCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of float primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(float[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TFloatCollection from the set. + * + * @param collection + * a TFloatCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TFloatCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of float primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(float[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TFloatProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TFloatProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TIntSet.java b/src/gnu/trove/set/TIntSet.java new file mode 100644 index 0000000..1589edf --- /dev/null +++ b/src/gnu/trove/set/TIntSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.TIntCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TIntSet extends TIntCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + int getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an int value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(int entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TIntIterator value + */ + @Override + TIntIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + int[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an int[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + int[] toArray(int[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a int value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(int entry); + + /** + * Removes entry from the set. + * + * @param entry + * an int value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(int entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TIntCollection + * are present. + * + * @param collection + * a TIntCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TIntCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of int primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(int[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TIntCollection to the set. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TIntCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of int primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(int[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TIntCollection. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TIntCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of int primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(int[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TIntCollection from the set. + * + * @param collection + * a TIntCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TIntCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of int primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(int[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TIntProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TIntProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TLongSet.java b/src/gnu/trove/set/TLongSet.java new file mode 100644 index 0000000..cd8820e --- /dev/null +++ b/src/gnu/trove/set/TLongSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TLongIterator; +import gnu.trove.procedure.TLongProcedure; +import gnu.trove.TLongCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TLongSet extends TLongCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + long getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an long value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(long entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TLongIterator value + */ + @Override + TLongIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + long[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an long[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + long[] toArray(long[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a long value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(long entry); + + /** + * Removes entry from the set. + * + * @param entry + * an long value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(long entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in TLongCollection + * are present. + * + * @param collection + * a TLongCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TLongCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of long primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(long[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TLongCollection to the set. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TLongCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of long primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(long[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TLongCollection. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TLongCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of long primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(long[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TLongCollection from the set. + * + * @param collection + * a TLongCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TLongCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of long primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(long[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TLongProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TLongProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/TShortSet.java b/src/gnu/trove/set/TShortSet.java new file mode 100644 index 0000000..fc76362 --- /dev/null +++ b/src/gnu/trove/set/TShortSet.java @@ -0,0 +1,331 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +import gnu.trove.iterator.TShortIterator; +import gnu.trove.procedure.TShortProcedure; +import gnu.trove.TShortCollection; + +import java.util.Collection; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * Created: Sat Nov 3 10:38:17 2001 + * + * @author Eric D. Friedman, Rob Eden, Jeff Randall + * @version $Id: _E_Set.template,v 1.1.2.5 2009/09/15 02:38:31 upholderoftruth + * Exp $ + */ + +public interface TShortSet extends TShortCollection { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + short getNoEntryValue(); + + /** + * Returns the number of elements in this set (its cardinality). If this set + * contains more than Integer.MAX_VALUE elements, returns + * Integer.MAX_VALUE. + * + * @return the number of elements in this set (its cardinality) + */ + @Override + int size(); + + /** + * Returns true if this set contains no elements. + * + * @return true if this set contains no elements + */ + @Override + boolean isEmpty(); + + /** + * Returns true if this set contains the specified element. + * + * @param entry + * an short value + * @return true if the set contains the specified element. + */ + @Override + boolean contains(short entry); + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an TShortIterator value + */ + @Override + TShortIterator iterator(); + + /** + * Returns an array containing all of the elements in this set. If this set + * makes any guarantees as to what order its elements are returned by its + * iterator, this method must return the elements in the same order. + * + *

+ * The returned array will be "safe" in that no references to it are maintained + * by this set. (In other words, this method must allocate a new array even if + * this set is backed by an array). The caller is thus free to modify the + * returned array. + * + *

+ * This method acts as bridge between array-based and collection-based APIs. + * + * @return an array containing all the elements in this set + */ + @Override + short[] toArray(); + + /** + * Returns an array containing elements in this set. + * + *

+ * If this set fits in the specified array with room to spare (i.e., the array + * has more elements than this set), the element in the array immediately + * following the end of the set is set to {@link #getNoEntryValue()}. + * (This is useful in determining the length of this set only if the + * caller knows that this set does not contain any elements representing null.) + * + *

+ * If the native array is smaller than the set size, the array will be filled + * with elements in Iterator order until it is full and exclude the remainder. + * + *

+ * If this set makes any guarantees as to what order its elements are returned + * by its iterator, this method must return the elements in the same order. + * + * @param dest + * the array into which the elements of this set are to be stored. + * @return an short[] containing all the elements in this set + * @throws NullPointerException + * if the specified array is null + */ + @Override + short[] toArray(short[] dest); + + /** + * Inserts a value into the set. + * + * @param entry + * a short value + * @return true if the set was modified by the add operation + */ + @Override + boolean add(short entry); + + /** + * Removes entry from the set. + * + * @param entry + * an short value + * @return true if the set was modified by the remove operation. + */ + @Override + boolean remove(short entry); + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(Collection collection); + + /** + * Tests the set to determine if all of the elements in + * TShortCollection are present. + * + * @param collection + * a TShortCollection value + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(TShortCollection collection); + + /** + * Tests the set to determine if all of the elements in array are + * present. + * + * @param array + * as array of short primitives. + * @return true if all elements were present in the set. + */ + @Override + boolean containsAll(short[] array); + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(Collection collection); + + /** + * Adds all of the elements in the TShortCollection to the set. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(TShortCollection collection); + + /** + * Adds all of the elements in the array to the set. + * + * @param array + * a array of short primitives. + * @return true if the set was modified by the add all operation. + */ + @Override + boolean addAll(short[] array); + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(Collection collection); + + /** + * Removes any values in the set which are not contained in + * TShortCollection. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(TShortCollection collection); + + /** + * Removes any values in the set which are not contained in array. + * + * @param array + * an array of short primitives. + * @return true if the set was modified by the retain all operation + */ + @Override + boolean retainAll(short[] array); + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(Collection collection); + + /** + * Removes all of the elements in TShortCollection from the set. + * + * @param collection + * a TShortCollection value + * @return true if the set was modified by the remove all operation. + */ + @Override + boolean removeAll(TShortCollection collection); + + /** + * Removes all of the elements in array from the set. + * + * @param array + * an array of short primitives. + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(short[] array); + + /** + * Empties the set. + */ + @Override + void clear(); + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TShortProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + boolean forEach(TShortProcedure procedure); + + // Comparison and hashing + + /** + * Compares the specified object with this set for equality. Returns + * true if the specified object is also a set, the two sets have the + * same size, and every member of the specified set is contained in this set (or + * equivalently, every member of this set is contained in the specified set). + * This definition ensures that the equals method works properly across + * different implementations of the set interface. + * + * @param o + * object to be compared for equality with this set + * @return true if the specified object is equal to this set + */ + @Override + boolean equals(Object o); + + /** + * Returns the hash code value for this set. The hash code of a set is defined + * to be the sum of the hash codes of the elements in the set. This ensures that + * s1.equals(s2) implies that s1.hashCode()==s2.hashCode() for + * any two sets s1 and s2, as required by the general contract + * of {@link Object#hashCode}. + * + * @return the hash code value for this set + * @see Object#equals(Object) + * @see Set#equals(Object) + */ + @Override + int hashCode(); + +} // THashSet diff --git a/src/gnu/trove/set/hash/TByteHashSet.java b/src/gnu/trove/set/hash/TByteHashSet.java new file mode 100644 index 0000000..62eadd0 --- /dev/null +++ b/src/gnu/trove/set/hash/TByteHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TByteSet; +import gnu.trove.iterator.TByteIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TByteCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for byte primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TByteHashSet extends TByteHash implements TByteSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TByteHashSet instance with the default capacity + * and load factor. + */ + public TByteHashSet() { + super(); + } + + /** + * Creates a new TByteHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TByteHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TByteHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TByteHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a byte value that represents null. + */ + public TByteHashSet(int initial_capacity, float load_factor, byte no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TByteHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TByteHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TByteHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TByteSet that will be duplicated. + */ + public TByteHashSet(TByteCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TByteHashSet) { + TByteHashSet hashset = (TByteHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (byte) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TByteHashSet instance containing the elements of + * array. + * + * @param array + * an array of byte primitives + */ + public TByteHashSet(byte[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TByteIterator iterator() { + return new TByteHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray() { + byte[] result = new byte[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + byte[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public byte[] toArray(byte[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + byte[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(byte val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(byte val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TByteCollection collection) { + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(byte[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Byte element : collection) { + byte e = element.byteValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Byte.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TByteCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TByteIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(byte[] array) { + boolean changed = false; + Arrays.sort(array); + byte[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Byte) { + byte c = ((Byte) element).byteValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TByteCollection collection) { + boolean changed = false; + TByteIterator iter = collection.iterator(); + while (iter.hasNext()) { + byte element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(byte[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + byte[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + byte oldSet[] = _set; + byte oldStates[] = _states; + + _set = new byte[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + byte o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TByteSet)) { + return false; + } + TByteSet that = (TByteSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TByteHashIterator extends THashPrimitiveIterator implements TByteIterator { + + /** the collection on which the iterator operates */ + private final TByteHash _hash; + + /** {@inheritDoc} */ + public TByteHashIterator(TByteHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public byte next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeByte(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeByte(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readByte(); + // noinspection RedundantCast + if (no_entry_value != (byte) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + byte val = in.readByte(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TCharHashSet.java b/src/gnu/trove/set/hash/TCharHashSet.java new file mode 100644 index 0000000..283a9c9 --- /dev/null +++ b/src/gnu/trove/set/hash/TCharHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TCharSet; +import gnu.trove.iterator.TCharIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TCharCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for char primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TCharHashSet extends TCharHash implements TCharSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TCharHashSet instance with the default capacity + * and load factor. + */ + public TCharHashSet() { + super(); + } + + /** + * Creates a new TCharHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TCharHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TCharHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TCharHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a char value that represents null. + */ + public TCharHashSet(int initial_capacity, float load_factor, char no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TCharHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TCharHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TCharHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TCharSet that will be duplicated. + */ + public TCharHashSet(TCharCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TCharHashSet) { + TCharHashSet hashset = (TCharHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (char) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TCharHashSet instance containing the elements of + * array. + * + * @param array + * an array of char primitives + */ + public TCharHashSet(char[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TCharIterator iterator() { + return new TCharHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public char[] toArray() { + char[] result = new char[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + char[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public char[] toArray(char[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + char[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(char val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(char val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TCharCollection collection) { + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(char[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Character element : collection) { + char e = element.charValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Character.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TCharCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TCharIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(char[] array) { + boolean changed = false; + Arrays.sort(array); + char[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Character) { + char c = ((Character) element).charValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TCharCollection collection) { + boolean changed = false; + TCharIterator iter = collection.iterator(); + while (iter.hasNext()) { + char element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(char[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + char[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + char oldSet[] = _set; + byte oldStates[] = _states; + + _set = new char[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + char o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TCharSet)) { + return false; + } + TCharSet that = (TCharSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TCharHashIterator extends THashPrimitiveIterator implements TCharIterator { + + /** the collection on which the iterator operates */ + private final TCharHash _hash; + + /** {@inheritDoc} */ + public TCharHashIterator(TCharHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public char next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeChar(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeChar(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readChar(); + // noinspection RedundantCast + if (no_entry_value != (char) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + char val = in.readChar(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TCustomHashSet.java b/src/gnu/trove/set/hash/TCustomHashSet.java new file mode 100644 index 0000000..7a285c1 --- /dev/null +++ b/src/gnu/trove/set/hash/TCustomHashSet.java @@ -0,0 +1,411 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.strategy.HashingStrategy; +import gnu.trove.impl.HashFunctions; +import gnu.trove.impl.hash.TCustomObjectHash; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.array.ToObjectArrayProceedure; + +import java.io.Externalizable; +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.lang.reflect.Array; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * @author Rob Eden + */ +public class TCustomHashSet extends TCustomObjectHash implements Set, Iterable, Externalizable { + + static final long serialVersionUID = 1L; + + /** FOR EXTERNALIZATION ONLY!!! */ + public TCustomHashSet() { + } + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public TCustomHashSet(HashingStrategy strategy) { + super(strategy); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TCustomHashSet(HashingStrategy strategy, int initialCapacity) { + super(strategy, initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TCustomHashSet(HashingStrategy strategy, int initialCapacity, float loadFactor) { + + super(strategy, initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param collection + * a Collection value + */ + public TCustomHashSet(HashingStrategy strategy, Collection collection) { + + this(strategy, collection.size()); + addAll(collection); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + @SuppressWarnings({ "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Set)) { + return false; + } + Set that = (Set) other; + if (that.size() != this.size()) { + return false; + } + return containsAll(that); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(E key) { + h += HashFunctions.hash(key); + return true; + } + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + int oldSize = size(); + Object oldSet[] = _set; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + for (int i = oldCapacity; i-- > 0;) { + E o = (E) oldSet[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + } + } + } + + /** + * Returns a new array containing the objects in the set. + * + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] toArray() { + Object[] result = new Object[size()]; + forEach(new ToObjectArrayProceedure(result)); + return result; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + forEach(new ToObjectArrayProceedure(a)); + + // If this collection fits in the specified array with room to + // spare (i.e., the array has more elements than this + // collection), the element in the array immediately following + // the end of the collection is set to null. This is useful in + // determining the length of this collection only if the + // caller knows that this collection does not contain any null + // elements.) + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + /** Empties the set. */ + @Override + public void clear() { + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + } + + /** + * Removes obj from the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the remove operation. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object obj) { + int index = index(obj); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this); + } + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + @SuppressWarnings("ForLoopReplaceableByForEach") + public boolean containsAll(Collection collection) { + for (Iterator i = collection.iterator(); i.hasNext();) { + if (!contains(i.next())) { + return false; + } + } + return true; + } + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + + ensureCapacity(size); + Iterator it = collection.iterator(); + while (size-- > 0) { + if (add(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + Iterator it; + + it = collection.iterator(); + while (size-- > 0) { + if (remove(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + int size = size(); + Iterator it = iterator(); + while (size-- > 0) { + if (!collection.contains(it.next())) { + it.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEach(new TObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(Object value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + E val = (E) in.readObject(); + add(val); + } + } +} diff --git a/src/gnu/trove/set/hash/TDoubleHashSet.java b/src/gnu/trove/set/hash/TDoubleHashSet.java new file mode 100644 index 0000000..ee275fe --- /dev/null +++ b/src/gnu/trove/set/hash/TDoubleHashSet.java @@ -0,0 +1,552 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TDoubleSet; +import gnu.trove.iterator.TDoubleIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TDoubleCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for double primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TDoubleHashSet extends TDoubleHash implements TDoubleSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TDoubleHashSet instance with the default capacity + * and load factor. + */ + public TDoubleHashSet() { + super(); + } + + /** + * Creates a new TDoubleHashSet instance with a prime capacity + * equal to or greater than initialCapacity and with the default load + * factor. + * + * @param initialCapacity + * an int value + */ + public TDoubleHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TDoubleHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TDoubleHashSet instance with a prime capacity + * equal to or greater than initial_capacity and with the specified + * load factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a double value that represents null. + */ + public TDoubleHashSet(int initial_capacity, float load_factor, double no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TDoubleHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TDoubleHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TDoubleHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TDoubleSet that will be duplicated. + */ + public TDoubleHashSet(TDoubleCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TDoubleHashSet) { + TDoubleHashSet hashset = (TDoubleHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TDoubleHashSet instance containing the elements of + * array. + * + * @param array + * an array of double primitives + */ + public TDoubleHashSet(double[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TDoubleIterator iterator() { + return new TDoubleHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public double[] toArray() { + double[] result = new double[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + double[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public double[] toArray(double[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + double[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(double val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(double val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TDoubleCollection collection) { + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(double[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Double element : collection) { + double e = element.doubleValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Double.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TDoubleCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TDoubleIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(double[] array) { + boolean changed = false; + Arrays.sort(array); + double[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Double) { + double c = ((Double) element).doubleValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TDoubleCollection collection) { + boolean changed = false; + TDoubleIterator iter = collection.iterator(); + while (iter.hasNext()) { + double element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(double[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + double[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + double oldSet[] = _set; + byte oldStates[] = _states; + + _set = new double[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + double o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TDoubleSet)) { + return false; + } + TDoubleSet that = (TDoubleSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TDoubleHashIterator extends THashPrimitiveIterator implements TDoubleIterator { + + /** the collection on which the iterator operates */ + private final TDoubleHash _hash; + + /** {@inheritDoc} */ + public TDoubleHashIterator(TDoubleHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public double next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeDouble(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeDouble(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readDouble(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + double val = in.readDouble(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TFloatHashSet.java b/src/gnu/trove/set/hash/TFloatHashSet.java new file mode 100644 index 0000000..fe75fa0 --- /dev/null +++ b/src/gnu/trove/set/hash/TFloatHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TFloatSet; +import gnu.trove.iterator.TFloatIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TFloatCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for float primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TFloatHashSet extends TFloatHash implements TFloatSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TFloatHashSet instance with the default capacity + * and load factor. + */ + public TFloatHashSet() { + super(); + } + + /** + * Creates a new TFloatHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TFloatHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TFloatHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TFloatHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a float value that represents null. + */ + public TFloatHashSet(int initial_capacity, float load_factor, float no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TFloatHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TFloatHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TFloatHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TFloatSet that will be duplicated. + */ + public TFloatHashSet(TFloatCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TFloatHashSet) { + TFloatHashSet hashset = (TFloatHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TFloatHashSet instance containing the elements of + * array. + * + * @param array + * an array of float primitives + */ + public TFloatHashSet(float[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TFloatIterator iterator() { + return new TFloatHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public float[] toArray() { + float[] result = new float[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + float[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public float[] toArray(float[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + float[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(float val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(float val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TFloatCollection collection) { + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(float[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Float element : collection) { + float e = element.floatValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Float.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TFloatCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TFloatIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(float[] array) { + boolean changed = false; + Arrays.sort(array); + float[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Float) { + float c = ((Float) element).floatValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TFloatCollection collection) { + boolean changed = false; + TFloatIterator iter = collection.iterator(); + while (iter.hasNext()) { + float element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(float[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + float[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + float oldSet[] = _set; + byte oldStates[] = _states; + + _set = new float[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + float o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TFloatSet)) { + return false; + } + TFloatSet that = (TFloatSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TFloatHashIterator extends THashPrimitiveIterator implements TFloatIterator { + + /** the collection on which the iterator operates */ + private final TFloatHash _hash; + + /** {@inheritDoc} */ + public TFloatHashIterator(TFloatHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public float next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeFloat(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeFloat(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readFloat(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + float val = in.readFloat(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/THashSet.java b/src/gnu/trove/set/hash/THashSet.java new file mode 100644 index 0000000..47ee23a --- /dev/null +++ b/src/gnu/trove/set/hash/THashSet.java @@ -0,0 +1,418 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.impl.hash.TObjectHash; +import gnu.trove.impl.HashFunctions; +import gnu.trove.procedure.TObjectProcedure; +import gnu.trove.procedure.array.ToObjectArrayProceedure; +import gnu.trove.iterator.hash.TObjectHashIterator; + +import java.io.*; +import java.util.Collection; +import java.util.Iterator; +import java.util.Set; +import java.util.Arrays; +import java.lang.reflect.Array; + +/** + * An implementation of the Set interface that uses an open-addressed + * hash table to store its contents. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + * @version $Id: THashSet.java,v 1.1.2.8 2010/03/02 04:09:50 robeden Exp $ + */ + +public class THashSet extends TObjectHash implements Set, Iterable, Externalizable { + + static final long serialVersionUID = 1L; + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public THashSet() { + super(); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public THashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public THashSet(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param collection + * a Collection value + */ + public THashSet(Collection collection) { + this(collection.size()); + addAll(collection); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + @SuppressWarnings({ "SimplifiableIfStatement" }) + public boolean equals(Object other) { + if (!(other instanceof Set)) { + return false; + } + Set that = (Set) other; + if (that.size() != this.size()) { + return false; + } + return containsAll(that); + } + + @Override + public int hashCode() { + HashProcedure p = new HashProcedure(); + forEach(p); + return p.getHashCode(); + } + + private final class HashProcedure implements TObjectProcedure { + private int h = 0; + + public int getHashCode() { + return h; + } + + @Override + public final boolean execute(E key) { + h += HashFunctions.hash(key); + return true; + } + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + @SuppressWarnings({ "unchecked" }) + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldSize = size(); + Object oldSet[] = _set; + + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + int count = 0; + for (int i = oldCapacity; i-- > 0;) { + E o = (E) oldSet[i]; + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + // + count++; + } + } + // Last check: size before and after should be the same + reportPotentialConcurrentMod(size(), oldSize); + } + + /** + * Returns a new array containing the objects in the set. + * + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public Object[] toArray() { + Object[] result = new Object[size()]; + forEach(new ToObjectArrayProceedure(result)); + return result; + } + + /** + * Returns a typed array of the objects in the set. + * + * @param a + * an Object[] value + * @return an Object[] value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public T[] toArray(T[] a) { + int size = size(); + if (a.length < size) { + a = (T[]) Array.newInstance(a.getClass().getComponentType(), size); + } + + forEach(new ToObjectArrayProceedure(a)); + + // If this collection fits in the specified array with room to + // spare (i.e., the array has more elements than this + // collection), the element in the array immediately following + // the end of the collection is set to null. This is useful in + // determining the length of this collection only if the + // caller knows that this collection does not contain any null + // elements.) + + if (a.length > size) { + a[size] = null; + } + + return a; + } + + /** + * Empties the set. + */ + @Override + public void clear() { + super.clear(); + + Arrays.fill(_set, 0, _set.length, FREE); + } + + /** + * Removes obj from the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the remove operation. + */ + @Override + @SuppressWarnings({ "unchecked" }) + public boolean remove(Object obj) { + int index = index(obj); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + @SuppressWarnings({ "unchecked" }) + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this); + } + + /** + * Tests the set to determine if all of the elements in collection are + * present. + * + * @param collection + * a Collection value + * @return true if all elements were present in the set. + */ + @Override + @SuppressWarnings("ForLoopReplaceableByForEach") + public boolean containsAll(Collection collection) { + for (Iterator i = collection.iterator(); i.hasNext();) { + if (!contains(i.next())) { + return false; + } + } + return true; + } + + /** + * Adds all of the elements in collection to the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the add all operation. + */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + + ensureCapacity(size); + Iterator it = collection.iterator(); + while (size-- > 0) { + if (add(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes all of the elements in collection from the set. + * + * @param collection + * a Collection value + * @return true if the set was modified by the remove all operation. + */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + int size = collection.size(); + Iterator it; + + it = collection.iterator(); + while (size-- > 0) { + if (remove(it.next())) { + changed = true; + } + } + return changed; + } + + /** + * Removes any values in the set which are not contained in collection. + * + * @param collection + * a Collection value + * @return true if the set was modified by the retain all operation + */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean changed = false; + int size = size(); + Iterator it = iterator(); + while (size-- > 0) { + if (!collection.contains(it.next())) { + it.remove(); + changed = true; + } + } + return changed; + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + forEach(new TObjectProcedure() { + private boolean first = true; + + @Override + public boolean execute(Object value) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(value); + return true; + } + }); + buf.append("}"); + return buf.toString(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(1); + + // NOTE: Super was not written in version 0 + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // ENTRIES + writeEntries(out); + } + + protected void writeEntries(ObjectOutput out) throws IOException { + for (int i = _set.length; i-- > 0;) { + if (_set[i] != REMOVED && _set[i] != FREE) { + out.writeObject(_set[i]); + } + } + } + + @Override + @SuppressWarnings({ "unchecked" }) + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + byte version = in.readByte(); + + // NOTE: super was not written in version 0 + if (version != 0) { + super.readExternal(in); + } + + // NUMBER OF ENTRIES + int size = in.readInt(); + setUp(size); + + // ENTRIES + while (size-- > 0) { + E val = (E) in.readObject(); + add(val); + } + + } +} // THashSet diff --git a/src/gnu/trove/set/hash/TIntHashSet.java b/src/gnu/trove/set/hash/TIntHashSet.java new file mode 100644 index 0000000..2069feb --- /dev/null +++ b/src/gnu/trove/set/hash/TIntHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TIntSet; +import gnu.trove.iterator.TIntIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TIntCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for int primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TIntHashSet extends TIntHash implements TIntSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TIntHashSet instance with the default capacity and + * load factor. + */ + public TIntHashSet() { + super(); + } + + /** + * Creates a new TIntHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TIntHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TIntHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TIntHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a int value that represents null. + */ + public TIntHashSet(int initial_capacity, float load_factor, int no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TIntHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TIntHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TIntHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TIntSet that will be duplicated. + */ + public TIntHashSet(TIntCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TIntHashSet) { + TIntHashSet hashset = (TIntHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TIntHashSet instance containing the elements of + * array. + * + * @param array + * an array of int primitives + */ + public TIntHashSet(int[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TIntIterator iterator() { + return new TIntHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public int[] toArray() { + int[] result = new int[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + int[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public int[] toArray(int[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + int[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(int val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(int val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TIntCollection collection) { + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(int[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Integer element : collection) { + int e = element.intValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Integer.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TIntCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TIntIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(int[] array) { + boolean changed = false; + Arrays.sort(array); + int[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Integer) { + int c = ((Integer) element).intValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TIntCollection collection) { + boolean changed = false; + TIntIterator iter = collection.iterator(); + while (iter.hasNext()) { + int element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(int[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + int[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + int oldSet[] = _set; + byte oldStates[] = _states; + + _set = new int[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + int o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TIntSet)) { + return false; + } + TIntSet that = (TIntSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TIntHashIterator extends THashPrimitiveIterator implements TIntIterator { + + /** the collection on which the iterator operates */ + private final TIntHash _hash; + + /** {@inheritDoc} */ + public TIntHashIterator(TIntHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public int next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeInt(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeInt(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readInt(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + int val = in.readInt(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TLinkedHashSet.java b/src/gnu/trove/set/hash/TLinkedHashSet.java new file mode 100644 index 0000000..0dd9bd2 --- /dev/null +++ b/src/gnu/trove/set/hash/TLinkedHashSet.java @@ -0,0 +1,320 @@ +package gnu.trove.set.hash; + +import gnu.trove.iterator.TIntIterator; +import gnu.trove.iterator.hash.TObjectHashIterator; +import gnu.trove.list.TIntList; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.list.linked.TIntLinkedList; +import gnu.trove.procedure.TIntProcedure; +import gnu.trove.procedure.TObjectProcedure; + +import java.io.IOException; +import java.io.ObjectOutput; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +/** + * Created by IntelliJ IDEA. User: Johan Date: 15/03/11 Time: 18:15 To change + * this template use File | Settings | File Templates. + */ +public class TLinkedHashSet extends THashSet { + TIntList order; + + /** + * Creates a new THashSet instance with the default capacity and + * load factor. + */ + public TLinkedHashSet() { + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TLinkedHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new THashSet instance with a prime capacity equal to + * or greater than initialCapacity and with the specified load factor. + * + * @param initialCapacity + * an int value + * @param loadFactor + * a float value + */ + public TLinkedHashSet(int initialCapacity, float loadFactor) { + super(initialCapacity, loadFactor); + } + + /** + * Creates a new THashSet instance containing the elements of + * collection. + * + * @param es + * a Collection value + */ + public TLinkedHashSet(Collection es) { + super(es); + } + + /** + * initializes the Object set of this hash table. + * + * @param initialCapacity + * an int value + * @return an int value + */ + @Override + public int setUp(int initialCapacity) { + order = new TIntArrayList(initialCapacity) { + /** + * Grow the internal array as needed to accommodate the specified number of + * elements. The size of the array bytes on each resize unless capacity requires + * more than twice the current capacity. + */ + @Override + public void ensureCapacity(int capacity) { + if (capacity > _data.length) { + int newCap = Math.max(_set.length, capacity); + int[] tmp = new int[newCap]; + System.arraycopy(_data, 0, tmp, 0, _data.length); + _data = tmp; + } + } + }; + return super.setUp(initialCapacity); // To change body of overridden methods use File | Settings | File + // Templates. + } + + /** + * Empties the set. + */ + @Override + public void clear() { + super.clear(); + order.clear(); + } + + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + boolean first = true; + + for (Iterator it = iterator(); it.hasNext();) { + if (first) { + first = false; + } else { + buf.append(", "); + } + + buf.append(it.next()); + } + + buf.append("}"); + return buf.toString(); + } + + /** + * Inserts a value into the set. + * + * @param obj + * an Object value + * @return true if the set was modified by the add operation + */ + @Override + public boolean add(E obj) { + int index = insertKey(obj); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + if (!order.add(index)) + throw new IllegalStateException("Order not changed after insert"); + + postInsertHook(consumeFreeSlot); + return true; // yes, we added something + } + + @Override + protected void removeAt(int index) { + // Remove from order first since super.removeAt can trigger compaction + // making the index invalid afterwards + order.remove(index); + super.removeAt(index); + } + + /** + * Expands the set to accommodate new values. + * + * @param newCapacity + * an int value + */ + @Override + protected void rehash(int newCapacity) { + TIntLinkedList oldOrder = new TIntLinkedList(order); + int oldSize = size(); + + Object oldSet[] = _set; + + order.clear(); + _set = new Object[newCapacity]; + Arrays.fill(_set, FREE); + + for (TIntIterator iterator = oldOrder.iterator(); iterator.hasNext();) { + int i = iterator.next(); + E o = (E) oldSet[i]; + if (o == FREE || o == REMOVED) { + throw new IllegalStateException("Iterating over empty location while rehashing"); + } + + if (o != FREE && o != REMOVED) { + int index = insertKey(o); + if (index < 0) { // everyone pays for this because some people can't RTFM + throwObjectContractViolation(_set[(-index - 1)], o, size(), oldSize, oldSet); + } + + if (!order.add(index)) + throw new IllegalStateException("Order not changed after insert"); + } + } + + } + + class WriteProcedure implements TIntProcedure { + final ObjectOutput output; + IOException ioException; + + WriteProcedure(ObjectOutput output) { + this.output = output; + } + + public IOException getIoException() { + return ioException; + } + + @Override + public boolean execute(int value) { + try { + output.writeObject(_set[value]); + } catch (IOException e) { + ioException = e; + return false; + } + return true; + } + + } + + @Override + protected void writeEntries(ObjectOutput out) throws IOException { + // ENTRIES + WriteProcedure writeProcedure = new WriteProcedure(out); + if (!order.forEach(writeProcedure)) + throw writeProcedure.getIoException(); + } + + /** + * Creates an iterator over the values of the set. The iterator supports element + * deletion. + * + * @return an Iterator value + */ + @Override + public TObjectHashIterator iterator() { + return new TObjectHashIterator(this) { + TIntIterator localIterator = order.iterator(); + int lastIndex; + + /** + * Moves the iterator to the next Object and returns it. + * + * @return an Object value + * @throws java.util.ConcurrentModificationException + * if the structure was changed using a method that isn't on this + * iterator. + * @throws java.util.NoSuchElementException + * if this is called on an exhausted iterator. + */ + @Override + public E next() { + lastIndex = localIterator.next(); + return objectAtIndex(lastIndex); + } + + /** + * Returns true if the iterator can be advanced past its current location. + * + * @return a boolean value + */ + @Override + public boolean hasNext() { + return localIterator.hasNext(); // To change body of overridden methods use File | Settings | File + // Templates. + } + + /** + * Removes the last entry returned by the iterator. Invoking this method more + * than once for a single entry will leave the underlying data structure in a + * confused state. + */ + @Override + public void remove() { + // Remove for iterator first + localIterator.remove(); + // the removal within removeAt() will not change the collection + // but the localIterator will remain valid + try { + _hash.tempDisableAutoCompaction(); + TLinkedHashSet.this.removeAt(lastIndex); + } finally { + _hash.reenableAutoCompaction(false); + } + } + }; // To change body of overridden methods use File | Settings | File Templates. + } + + class ForEachProcedure implements TIntProcedure { + boolean changed = false; + final Object[] set; + final TObjectProcedure procedure; + + public ForEachProcedure(Object[] set, TObjectProcedure procedure) { + this.set = set; + this.procedure = procedure; + } + + /** + * Executes this procedure. A false return value indicates that the application + * executing this procedure should not invoke this procedure again. + * + * @param value + * a value of type int + * @return true if additional invocations of the procedure are allowed. + */ + @Override + public boolean execute(int value) { + return procedure.execute((E) set[value]); + } + } + + /** + * Executes procedure for each element in the set. + * + * @param procedure + * a TObjectProcedure value + * @return false if the loop over the set terminated because the procedure + * returned false for some value. + */ + @Override + public boolean forEach(TObjectProcedure procedure) { + ForEachProcedure forEachProcedure = new ForEachProcedure(_set, procedure); + return order.forEach(forEachProcedure); + } +} diff --git a/src/gnu/trove/set/hash/TLongHashSet.java b/src/gnu/trove/set/hash/TLongHashSet.java new file mode 100644 index 0000000..64dfbd5 --- /dev/null +++ b/src/gnu/trove/set/hash/TLongHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TLongSet; +import gnu.trove.iterator.TLongIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TLongCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for long primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TLongHashSet extends TLongHash implements TLongSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TLongHashSet instance with the default capacity + * and load factor. + */ + public TLongHashSet() { + super(); + } + + /** + * Creates a new TLongHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TLongHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TLongHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TLongHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a long value that represents null. + */ + public TLongHashSet(int initial_capacity, float load_factor, long no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TLongHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TLongHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TLongHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TLongSet that will be duplicated. + */ + public TLongHashSet(TLongCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TLongHashSet) { + TLongHashSet hashset = (TLongHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TLongHashSet instance containing the elements of + * array. + * + * @param array + * an array of long primitives + */ + public TLongHashSet(long[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TLongIterator iterator() { + return new TLongHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public long[] toArray() { + long[] result = new long[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + long[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public long[] toArray(long[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + long[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(long val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(long val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TLongCollection collection) { + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(long[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Long element : collection) { + long e = element.longValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Long.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TLongCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TLongIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(long[] array) { + boolean changed = false; + Arrays.sort(array); + long[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Long) { + long c = ((Long) element).longValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TLongCollection collection) { + boolean changed = false; + TLongIterator iter = collection.iterator(); + while (iter.hasNext()) { + long element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(long[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + long[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + long oldSet[] = _set; + byte oldStates[] = _states; + + _set = new long[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + long o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TLongSet)) { + return false; + } + TLongSet that = (TLongSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TLongHashIterator extends THashPrimitiveIterator implements TLongIterator { + + /** the collection on which the iterator operates */ + private final TLongHash _hash; + + /** {@inheritDoc} */ + public TLongHashIterator(TLongHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public long next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeLong(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeLong(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readLong(); + // noinspection RedundantCast + if (no_entry_value != 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + long val = in.readLong(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/set/hash/TShortHashSet.java b/src/gnu/trove/set/hash/TShortHashSet.java new file mode 100644 index 0000000..b8e8b0c --- /dev/null +++ b/src/gnu/trove/set/hash/TShortHashSet.java @@ -0,0 +1,551 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.set.hash; + +import gnu.trove.set.TShortSet; +import gnu.trove.iterator.TShortIterator; +import gnu.trove.impl.*; +import gnu.trove.impl.hash.*; +import gnu.trove.TShortCollection; + +import java.io.IOException; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.Externalizable; +import java.util.Arrays; +import java.util.Collection; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * An open addressed set implementation for short primitives. + * + * @author Eric D. Friedman + * @author Rob Eden + * @author Jeff Randall + */ + +public class TShortHashSet extends TShortHash implements TShortSet, Externalizable { + static final long serialVersionUID = 1L; + + /** + * Creates a new TShortHashSet instance with the default capacity + * and load factor. + */ + public TShortHashSet() { + super(); + } + + /** + * Creates a new TShortHashSet instance with a prime capacity equal + * to or greater than initialCapacity and with the default load factor. + * + * @param initialCapacity + * an int value + */ + public TShortHashSet(int initialCapacity) { + super(initialCapacity); + } + + /** + * Creates a new TIntHash instance with a prime value at or near + * the specified capacity and load factor. + * + * @param initialCapacity + * used to find a prime capacity for the table. + * @param load_factor + * used to calculate the threshold over which rehashing takes place. + */ + public TShortHashSet(int initialCapacity, float load_factor) { + super(initialCapacity, load_factor); + } + + /** + * Creates a new TShortHashSet instance with a prime capacity equal + * to or greater than initial_capacity and with the specified load + * factor. + * + * @param initial_capacity + * an int value + * @param load_factor + * a float value + * @param no_entry_value + * a short value that represents null. + */ + public TShortHashSet(int initial_capacity, float load_factor, short no_entry_value) { + super(initial_capacity, load_factor, no_entry_value); + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + /** + * Creates a new TShortHashSet instance that is a copy of the + * existing Collection. + * + * @param collection + * a Collection that will be duplicated. + */ + public TShortHashSet(Collection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + addAll(collection); + } + + /** + * Creates a new TShortHashSet instance that is a copy of the + * existing set. + * + * @param collection + * a TShortSet that will be duplicated. + */ + public TShortHashSet(TShortCollection collection) { + this(Math.max(collection.size(), DEFAULT_CAPACITY)); + if (collection instanceof TShortHashSet) { + TShortHashSet hashset = (TShortHashSet) collection; + this._loadFactor = hashset._loadFactor; + this.no_entry_value = hashset.no_entry_value; + // noinspection RedundantCast + if (this.no_entry_value != (short) 0) { + Arrays.fill(_set, this.no_entry_value); + } + setUp((int) Math.ceil(DEFAULT_CAPACITY / _loadFactor)); + } + addAll(collection); + } + + /** + * Creates a new TShortHashSet instance containing the elements of + * array. + * + * @param array + * an array of short primitives + */ + public TShortHashSet(short[] array) { + this(Math.max(array.length, DEFAULT_CAPACITY)); + addAll(array); + } + + /** {@inheritDoc} */ + @Override + public TShortIterator iterator() { + return new TShortHashIterator(this); + } + + /** {@inheritDoc} */ + @Override + public short[] toArray() { + short[] result = new short[size()]; + if (result.length == 0) { + return result; // nothing to copy + } + short[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + result[j++] = set[i]; + } + } + return result; + } + + /** {@inheritDoc} */ + @Override + public short[] toArray(short[] dest) { + if (dest.length == 0) { + return dest; // nothing to copy + } + short[] set = _set; + byte[] states = _states; + + for (int i = states.length, j = 0; i-- > 0;) { + if (states[i] == FULL) { + dest[j++] = set[i]; + } + } + + if (dest.length > _size) { + dest[_size] = no_entry_value; + } + return dest; + } + + /** {@inheritDoc} */ + @Override + public boolean add(short val) { + int index = insertKey(val); + + if (index < 0) { + return false; // already present in set, nothing to add + } + + postInsertHook(consumeFreeSlot); + + return true; // yes, we added something + } + + /** {@inheritDoc} */ + @Override + public boolean remove(short val) { + int index = index(val); + if (index >= 0) { + removeAt(index); + return true; + } + return false; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(Collection collection) { + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (!contains(c)) { + return false; + } + } else { + return false; + } + + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(TShortCollection collection) { + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (!contains(element)) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean containsAll(short[] array) { + for (int i = array.length; i-- > 0;) { + if (!contains(array[i])) { + return false; + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(Collection collection) { + boolean changed = false; + for (Short element : collection) { + short e = element.shortValue(); + if (add(e)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (add(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean addAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (add(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + @SuppressWarnings({ "SuspiciousMethodCalls" }) + public boolean retainAll(Collection collection) { + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(Short.valueOf(iter.next()))) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(TShortCollection collection) { + if (this == collection) { + return false; + } + boolean modified = false; + TShortIterator iter = iterator(); + while (iter.hasNext()) { + if (!collection.contains(iter.next())) { + iter.remove(); + modified = true; + } + } + return modified; + } + + /** {@inheritDoc} */ + @Override + public boolean retainAll(short[] array) { + boolean changed = false; + Arrays.sort(array); + short[] set = _set; + byte[] states = _states; + + _autoCompactTemporaryDisable = true; + for (int i = set.length; i-- > 0;) { + if (states[i] == FULL && (Arrays.binarySearch(array, set[i]) < 0)) { + removeAt(i); + changed = true; + } + } + _autoCompactTemporaryDisable = false; + + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(Collection collection) { + boolean changed = false; + for (Object element : collection) { + if (element instanceof Short) { + short c = ((Short) element).shortValue(); + if (remove(c)) { + changed = true; + } + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(TShortCollection collection) { + boolean changed = false; + TShortIterator iter = collection.iterator(); + while (iter.hasNext()) { + short element = iter.next(); + if (remove(element)) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public boolean removeAll(short[] array) { + boolean changed = false; + for (int i = array.length; i-- > 0;) { + if (remove(array[i])) { + changed = true; + } + } + return changed; + } + + /** {@inheritDoc} */ + @Override + public void clear() { + super.clear(); + short[] set = _set; + byte[] states = _states; + + for (int i = set.length; i-- > 0;) { + set[i] = no_entry_value; + states[i] = FREE; + } + } + + /** {@inheritDoc} */ + @Override + protected void rehash(int newCapacity) { + int oldCapacity = _set.length; + + short oldSet[] = _set; + byte oldStates[] = _states; + + _set = new short[newCapacity]; + _states = new byte[newCapacity]; + + for (int i = oldCapacity; i-- > 0;) { + if (oldStates[i] == FULL) { + short o = oldSet[i]; + int index = insertKey(o); + } + } + } + + /** {@inheritDoc} */ + @Override + public boolean equals(Object other) { + if (!(other instanceof TShortSet)) { + return false; + } + TShortSet that = (TShortSet) other; + if (that.size() != this.size()) { + return false; + } + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + if (!that.contains(_set[i])) { + return false; + } + } + } + return true; + } + + /** {@inheritDoc} */ + @Override + public int hashCode() { + int hashcode = 0; + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + hashcode += HashFunctions.hash(_set[i]); + } + } + return hashcode; + } + + /** {@inheritDoc} */ + @Override + public String toString() { + StringBuilder buffy = new StringBuilder(_size * 2 + 2); + buffy.append("{"); + for (int i = _states.length, j = 1; i-- > 0;) { + if (_states[i] == FULL) { + buffy.append(_set[i]); + if (j++ < _size) { + buffy.append(","); + } + } + } + buffy.append("}"); + return buffy.toString(); + } + + class TShortHashIterator extends THashPrimitiveIterator implements TShortIterator { + + /** the collection on which the iterator operates */ + private final TShortHash _hash; + + /** {@inheritDoc} */ + public TShortHashIterator(TShortHash hash) { + super(hash); + this._hash = hash; + } + + /** {@inheritDoc} */ + @Override + public short next() { + moveToNextIndex(); + return _hash._set[_index]; + } + } + + /** {@inheritDoc} */ + @Override + public void writeExternal(ObjectOutput out) throws IOException { + + // VERSION + out.writeByte(1); + + // SUPER + super.writeExternal(out); + + // NUMBER OF ENTRIES + out.writeInt(_size); + + // LOAD FACTOR -- Added version 1 + out.writeFloat(_loadFactor); + + // NO ENTRY VALUE -- Added version 1 + out.writeShort(no_entry_value); + + // ENTRIES + for (int i = _states.length; i-- > 0;) { + if (_states[i] == FULL) { + out.writeShort(_set[i]); + } + } + } + + /** {@inheritDoc} */ + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + int version = in.readByte(); + + // SUPER + super.readExternal(in); + + // NUMBER OF ENTRIES + int size = in.readInt(); + + if (version >= 1) { + // LOAD FACTOR + _loadFactor = in.readFloat(); + + // NO ENTRY VALUE + no_entry_value = in.readShort(); + // noinspection RedundantCast + if (no_entry_value != (short) 0) { + Arrays.fill(_set, no_entry_value); + } + } + + // ENTRIES + setUp(size); + while (size-- > 0) { + short val = in.readShort(); + add(val); + } + } +} // TIntHashSet diff --git a/src/gnu/trove/stack/TByteStack.java b/src/gnu/trove/stack/TByteStack.java new file mode 100644 index 0000000..a8530c0 --- /dev/null +++ b/src/gnu/trove/stack/TByteStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of byte primitives. + */ +public interface TByteStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public byte getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an byte value + */ + public void push(byte val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an byte value + */ + public byte pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an byte value + */ + public byte peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an byte[] value + */ + public byte[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(byte[] dest); +} diff --git a/src/gnu/trove/stack/TCharStack.java b/src/gnu/trove/stack/TCharStack.java new file mode 100644 index 0000000..0a345a6 --- /dev/null +++ b/src/gnu/trove/stack/TCharStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of char primitives. + */ +public interface TCharStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public char getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an char value + */ + public void push(char val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an char value + */ + public char pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an char value + */ + public char peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an char[] value + */ + public char[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(char[] dest); +} diff --git a/src/gnu/trove/stack/TDoubleStack.java b/src/gnu/trove/stack/TDoubleStack.java new file mode 100644 index 0000000..e685497 --- /dev/null +++ b/src/gnu/trove/stack/TDoubleStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of double primitives. + */ +public interface TDoubleStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public double getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an double value + */ + public void push(double val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an double value + */ + public double pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an double value + */ + public double peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an double[] value + */ + public double[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(double[] dest); +} diff --git a/src/gnu/trove/stack/TFloatStack.java b/src/gnu/trove/stack/TFloatStack.java new file mode 100644 index 0000000..3955759 --- /dev/null +++ b/src/gnu/trove/stack/TFloatStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of float primitives. + */ +public interface TFloatStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public float getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an float value + */ + public void push(float val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an float value + */ + public float pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an float value + */ + public float peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an float[] value + */ + public float[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(float[] dest); +} diff --git a/src/gnu/trove/stack/TIntStack.java b/src/gnu/trove/stack/TIntStack.java new file mode 100644 index 0000000..61a3674 --- /dev/null +++ b/src/gnu/trove/stack/TIntStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of int primitives. + */ +public interface TIntStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public int getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an int value + */ + public void push(int val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an int value + */ + public int pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an int value + */ + public int peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an int[] value + */ + public int[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(int[] dest); +} diff --git a/src/gnu/trove/stack/TLongStack.java b/src/gnu/trove/stack/TLongStack.java new file mode 100644 index 0000000..e2053a3 --- /dev/null +++ b/src/gnu/trove/stack/TLongStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of long primitives. + */ +public interface TLongStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public long getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an long value + */ + public void push(long val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an long value + */ + public long pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an long value + */ + public long peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an long[] value + */ + public long[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(long[] dest); +} diff --git a/src/gnu/trove/stack/TShortStack.java b/src/gnu/trove/stack/TShortStack.java new file mode 100644 index 0000000..3e62249 --- /dev/null +++ b/src/gnu/trove/stack/TShortStack.java @@ -0,0 +1,89 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack; + +////////////////////////////////////////////////// + +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of short primitives. + */ +public interface TShortStack { + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + public short getNoEntryValue(); + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an short value + */ + public void push(short val); + + /** + * Removes and returns the value at the top of the stack. + * + * @return an short value + */ + public short pop(); + + /** + * Returns the value at the top of the stack. + * + * @return an short value + */ + public short peek(); + + /** + * Returns the current depth of the stack. + */ + public int size(); + + /** + * Clears the stack. + */ + public void clear(); + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. + * + * @return an short[] value + */ + public short[] toArray(); + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. + * + * @param dest + * the array to copy into. + */ + public void toArray(short[] dest); +} diff --git a/src/gnu/trove/stack/array/TByteArrayStack.java b/src/gnu/trove/stack/array/TByteArrayStack.java new file mode 100644 index 0000000..28249f8 --- /dev/null +++ b/src/gnu/trove/stack/array/TByteArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TByteStack; +import gnu.trove.list.array.TByteArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of byte primitives, backed by a TByteArrayList + */ +public class TByteArrayStack implements TByteStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TByteArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TByteArrayStack instance with the default + * capacity. + */ + public TByteArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TByteArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TByteArrayStack(int capacity) { + _list = new TByteArrayList(capacity); + } + + /** + * Creates a new TByteArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TByteArrayStack(int capacity, byte no_entry_value) { + _list = new TByteArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TByteArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TByteArrayStack(TByteStack stack) { + if (stack instanceof TByteArrayStack) { + TByteArrayStack array_stack = (TByteArrayStack) stack; + this._list = new TByteArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TByteArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public byte getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an byte value + */ + @Override + public void push(byte val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an byte value + */ + @Override + public byte pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an byte value + */ + @Override + public byte peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an byte[] value + */ + @Override + public byte[] toArray() { + byte[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(byte[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(byte[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(byte[] dest, int i, int j) { + byte tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TByteArrayStack that = (TByteArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TByteArrayList) in.readObject(); + } +} // TByteArrayStack diff --git a/src/gnu/trove/stack/array/TCharArrayStack.java b/src/gnu/trove/stack/array/TCharArrayStack.java new file mode 100644 index 0000000..57e9a20 --- /dev/null +++ b/src/gnu/trove/stack/array/TCharArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TCharStack; +import gnu.trove.list.array.TCharArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of char primitives, backed by a TCharArrayList + */ +public class TCharArrayStack implements TCharStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TCharArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TCharArrayStack instance with the default + * capacity. + */ + public TCharArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TCharArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TCharArrayStack(int capacity) { + _list = new TCharArrayList(capacity); + } + + /** + * Creates a new TCharArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TCharArrayStack(int capacity, char no_entry_value) { + _list = new TCharArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TCharArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TCharArrayStack(TCharStack stack) { + if (stack instanceof TCharArrayStack) { + TCharArrayStack array_stack = (TCharArrayStack) stack; + this._list = new TCharArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TCharArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public char getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an char value + */ + @Override + public void push(char val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an char value + */ + @Override + public char pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an char value + */ + @Override + public char peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an char[] value + */ + @Override + public char[] toArray() { + char[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(char[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(char[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(char[] dest, int i, int j) { + char tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TCharArrayStack that = (TCharArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TCharArrayList) in.readObject(); + } +} // TCharArrayStack diff --git a/src/gnu/trove/stack/array/TDoubleArrayStack.java b/src/gnu/trove/stack/array/TDoubleArrayStack.java new file mode 100644 index 0000000..0a89b03 --- /dev/null +++ b/src/gnu/trove/stack/array/TDoubleArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TDoubleStack; +import gnu.trove.list.array.TDoubleArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of double primitives, backed by a TDoubleArrayList + */ +public class TDoubleArrayStack implements TDoubleStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TDoubleArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TDoubleArrayStack instance with the default + * capacity. + */ + public TDoubleArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TDoubleArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TDoubleArrayStack(int capacity) { + _list = new TDoubleArrayList(capacity); + } + + /** + * Creates a new TDoubleArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TDoubleArrayStack(int capacity, double no_entry_value) { + _list = new TDoubleArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TDoubleArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TDoubleArrayStack(TDoubleStack stack) { + if (stack instanceof TDoubleArrayStack) { + TDoubleArrayStack array_stack = (TDoubleArrayStack) stack; + this._list = new TDoubleArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TDoubleArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public double getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an double value + */ + @Override + public void push(double val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an double value + */ + @Override + public double pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an double value + */ + @Override + public double peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an double[] value + */ + @Override + public double[] toArray() { + double[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(double[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(double[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(double[] dest, int i, int j) { + double tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TDoubleArrayStack that = (TDoubleArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TDoubleArrayList) in.readObject(); + } +} // TDoubleArrayStack diff --git a/src/gnu/trove/stack/array/TFloatArrayStack.java b/src/gnu/trove/stack/array/TFloatArrayStack.java new file mode 100644 index 0000000..67fefef --- /dev/null +++ b/src/gnu/trove/stack/array/TFloatArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TFloatStack; +import gnu.trove.list.array.TFloatArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of float primitives, backed by a TFloatArrayList + */ +public class TFloatArrayStack implements TFloatStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TFloatArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TFloatArrayStack instance with the default + * capacity. + */ + public TFloatArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TFloatArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TFloatArrayStack(int capacity) { + _list = new TFloatArrayList(capacity); + } + + /** + * Creates a new TFloatArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TFloatArrayStack(int capacity, float no_entry_value) { + _list = new TFloatArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TFloatArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TFloatArrayStack(TFloatStack stack) { + if (stack instanceof TFloatArrayStack) { + TFloatArrayStack array_stack = (TFloatArrayStack) stack; + this._list = new TFloatArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TFloatArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public float getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an float value + */ + @Override + public void push(float val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an float value + */ + @Override + public float pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an float value + */ + @Override + public float peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an float[] value + */ + @Override + public float[] toArray() { + float[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(float[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(float[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(float[] dest, int i, int j) { + float tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TFloatArrayStack that = (TFloatArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TFloatArrayList) in.readObject(); + } +} // TFloatArrayStack diff --git a/src/gnu/trove/stack/array/TIntArrayStack.java b/src/gnu/trove/stack/array/TIntArrayStack.java new file mode 100644 index 0000000..0ad6232 --- /dev/null +++ b/src/gnu/trove/stack/array/TIntArrayStack.java @@ -0,0 +1,287 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TIntStack; +import gnu.trove.list.array.TIntArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of int primitives, backed by a TIntArrayList + */ +public class TIntArrayStack implements TIntStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TIntArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TIntArrayStack instance with the default capacity. + */ + public TIntArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TIntArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TIntArrayStack(int capacity) { + _list = new TIntArrayList(capacity); + } + + /** + * Creates a new TIntArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TIntArrayStack(int capacity, int no_entry_value) { + _list = new TIntArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TIntArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TIntArrayStack(TIntStack stack) { + if (stack instanceof TIntArrayStack) { + TIntArrayStack array_stack = (TIntArrayStack) stack; + this._list = new TIntArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TIntArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public int getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an int value + */ + @Override + public void push(int val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an int value + */ + @Override + public int pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an int value + */ + @Override + public int peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an int[] value + */ + @Override + public int[] toArray() { + int[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(int[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(int[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(int[] dest, int i, int j) { + int tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TIntArrayStack that = (TIntArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TIntArrayList) in.readObject(); + } +} // TIntArrayStack diff --git a/src/gnu/trove/stack/array/TLongArrayStack.java b/src/gnu/trove/stack/array/TLongArrayStack.java new file mode 100644 index 0000000..7c0743c --- /dev/null +++ b/src/gnu/trove/stack/array/TLongArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TLongStack; +import gnu.trove.list.array.TLongArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of long primitives, backed by a TLongArrayList + */ +public class TLongArrayStack implements TLongStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TLongArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TLongArrayStack instance with the default + * capacity. + */ + public TLongArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TLongArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TLongArrayStack(int capacity) { + _list = new TLongArrayList(capacity); + } + + /** + * Creates a new TLongArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TLongArrayStack(int capacity, long no_entry_value) { + _list = new TLongArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TLongArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TLongArrayStack(TLongStack stack) { + if (stack instanceof TLongArrayStack) { + TLongArrayStack array_stack = (TLongArrayStack) stack; + this._list = new TLongArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TLongArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public long getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an long value + */ + @Override + public void push(long val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an long value + */ + @Override + public long pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an long value + */ + @Override + public long peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an long[] value + */ + @Override + public long[] toArray() { + long[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(long[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(long[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(long[] dest, int i, int j) { + long tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TLongArrayStack that = (TLongArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TLongArrayList) in.readObject(); + } +} // TLongArrayStack diff --git a/src/gnu/trove/stack/array/TShortArrayStack.java b/src/gnu/trove/stack/array/TShortArrayStack.java new file mode 100644 index 0000000..4259e7d --- /dev/null +++ b/src/gnu/trove/stack/array/TShortArrayStack.java @@ -0,0 +1,288 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2001, Eric D. Friedman All Rights Reserved. +// Copyright (c) 2009, Rob Eden All Rights Reserved. +// Copyright (c) 2009, Jeff Randall All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.stack.array; + +import gnu.trove.stack.TShortStack; +import gnu.trove.list.array.TShortArrayList; +import gnu.trove.impl.*; + +import java.io.Externalizable; +import java.io.ObjectInput; +import java.io.ObjectOutput; +import java.io.IOException; + +////////////////////////////////////////////////// +// THIS IS A GENERATED CLASS. DO NOT HAND EDIT! // +////////////////////////////////////////////////// + +/** + * A stack of short primitives, backed by a TShortArrayList + */ +public class TShortArrayStack implements TShortStack, Externalizable { + static final long serialVersionUID = 1L; + + /** the list used to hold the stack values. */ + protected TShortArrayList _list; + + public static final int DEFAULT_CAPACITY = Constants.DEFAULT_CAPACITY; + + /** + * Creates a new TShortArrayStack instance with the default + * capacity. + */ + public TShortArrayStack() { + this(DEFAULT_CAPACITY); + } + + /** + * Creates a new TShortArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + */ + public TShortArrayStack(int capacity) { + _list = new TShortArrayList(capacity); + } + + /** + * Creates a new TShortArrayStack instance with the specified + * capacity. + * + * @param capacity + * the initial depth of the stack + * @param no_entry_value + * value that represents null + */ + public TShortArrayStack(int capacity, short no_entry_value) { + _list = new TShortArrayList(capacity, no_entry_value); + } + + /** + * Creates a new TShortArrayStack instance that is a copy of the + * instanced passed to us. + * + * @param stack + * the instance to copy + */ + public TShortArrayStack(TShortStack stack) { + if (stack instanceof TShortArrayStack) { + TShortArrayStack array_stack = (TShortArrayStack) stack; + this._list = new TShortArrayList(array_stack._list); + } else { + throw new UnsupportedOperationException("Only support TShortArrayStack"); + } + } + + /** + * Returns the value that is used to represent null. The default value is + * generally zero, but can be changed during construction of the collection. + * + * @return the value that represents null + */ + @Override + public short getNoEntryValue() { + return _list.getNoEntryValue(); + } + + /** + * Pushes the value onto the top of the stack. + * + * @param val + * an short value + */ + @Override + public void push(short val) { + _list.add(val); + } + + /** + * Removes and returns the value at the top of the stack. + * + * @return an short value + */ + @Override + public short pop() { + return _list.removeAt(_list.size() - 1); + } + + /** + * Returns the value at the top of the stack. + * + * @return an short value + */ + @Override + public short peek() { + return _list.get(_list.size() - 1); + } + + /** + * Returns the current depth of the stack. + */ + @Override + public int size() { + return _list.size(); + } + + /** + * Clears the stack. + */ + @Override + public void clear() { + _list.clear(); + } + + /** + * Copies the contents of the stack into a native array. Note that this will NOT + * pop them out of the stack. The front of the list will be the top of the + * stack. + * + * @return an short[] value + */ + @Override + public short[] toArray() { + short[] retval = _list.toArray(); + reverse(retval, 0, size()); + return retval; + } + + /** + * Copies a slice of the list into a native array. Note that this will NOT pop + * them out of the stack. The front of the list will be the top of the stack. + *

+ * If the native array is smaller than the stack depth, the native array will be + * filled with the elements from the top of the array until it is full and + * exclude the remainder. + * + * @param dest + * the array to copy into. + */ + @Override + public void toArray(short[] dest) { + int size = size(); + int start = size - dest.length; + if (start < 0) { + start = 0; + } + + int length = Math.min(size, dest.length); + _list.toArray(dest, start, length); + reverse(dest, 0, length); + if (dest.length > size) { + dest[size] = _list.getNoEntryValue(); + } + } + + /** + * Reverse the order of the elements in the range of the list. + * + * @param dest + * the array of data + * @param from + * the inclusive index at which to start reversing + * @param to + * the exclusive index at which to stop reversing + */ + private void reverse(short[] dest, int from, int to) { + if (from == to) { + return; // nothing to do + } + if (from > to) { + throw new IllegalArgumentException("from cannot be greater than to"); + } + for (int i = from, j = to - 1; i < j; i++, j--) { + swap(dest, i, j); + } + } + + /** + * Swap the values at offsets i and j. + * + * @param dest + * the array of data + * @param i + * an offset into the data array + * @param j + * an offset into the data array + */ + private void swap(short[] dest, int i, int j) { + short tmp = dest[i]; + dest[i] = dest[j]; + dest[j] = tmp; + } + + /** + * Returns a String representation of the list, top to bottom. + * + * @return a String value + */ + @Override + public String toString() { + final StringBuilder buf = new StringBuilder("{"); + for (int i = _list.size() - 1; i > 0; i--) { + buf.append(_list.get(i)); + buf.append(", "); + } + if (size() > 0) { + buf.append(_list.get(0)); + } + buf.append("}"); + return buf.toString(); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + TShortArrayStack that = (TShortArrayStack) o; + + return _list.equals(that._list); + } + + @Override + public int hashCode() { + return _list.hashCode(); + } + + @Override + public void writeExternal(ObjectOutput out) throws IOException { + // VERSION + out.writeByte(0); + + // LIST + out.writeObject(_list); + } + + @Override + public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { + + // VERSION + in.readByte(); + + // LIST + _list = (TShortArrayList) in.readObject(); + } +} // TShortArrayStack diff --git a/src/gnu/trove/strategy/HashingStrategy.java b/src/gnu/trove/strategy/HashingStrategy.java new file mode 100644 index 0000000..3ba3458 --- /dev/null +++ b/src/gnu/trove/strategy/HashingStrategy.java @@ -0,0 +1,59 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright (c) 2002, Eric D. Friedman All Rights Reserved. +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/////////////////////////////////////////////////////////////////////////////// + +package gnu.trove.strategy; + +import java.io.Serializable; + +/** + * Interface to support pluggable hashing strategies in maps and sets. + * Implementers can use this interface to make the trove hashing algorithms use + * object values, values provided by the java runtime, or a custom strategy when + * computing hashcodes. + * + * @author Eric Friedman + * @author Rob Eden + */ + +public interface HashingStrategy extends Serializable { + static final long serialVersionUID = 5674097166776615540L; + + /** + * Computes a hash code for the specified object. Implementers can use the + * object's own hashCode method, the Java runtime's + * identityHashCode, or a custom scheme. + * + * @param object + * for which the hashcode is to be computed + * @return the hashCode + */ + int computeHashCode(T object); + + /** + * Compares o1 and o2 for equality. Strategy implementers may use the objects' + * own equals() methods, compare object references, or implement some custom + * scheme. + * + * @param o1 + * an Object value + * @param o2 + * an Object value + * @return true if the objects are equal according to this strategy. + */ + boolean equals(T o1, T o2); +} diff --git a/src/gnu/trove/strategy/IdentityHashingStrategy.java b/src/gnu/trove/strategy/IdentityHashingStrategy.java new file mode 100644 index 0000000..9b6baf4 --- /dev/null +++ b/src/gnu/trove/strategy/IdentityHashingStrategy.java @@ -0,0 +1,26 @@ +package gnu.trove.strategy; + +/** + * A {@link gnu.trove.strategy.HashingStrategy} that does identity comparisons + * (==) and uses {@link System#identityHashCode(Object)} for hashCode + * generation. + */ +public class IdentityHashingStrategy implements HashingStrategy { + static final long serialVersionUID = -5188534454583764904L; + + /** + * A single instance that can be shared with multiple collections. This instance + * is thread safe. + */ + public static final IdentityHashingStrategy INSTANCE = new IdentityHashingStrategy(); + + @Override + public int computeHashCode(K object) { + return System.identityHashCode(object); + } + + @Override + public boolean equals(K o1, K o2) { + return o1 == o2; + } +} diff --git a/src/me/Utils.java b/src/me/Utils.java new file mode 100644 index 0000000..9c250a7 --- /dev/null +++ b/src/me/Utils.java @@ -0,0 +1,70 @@ +package me; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; + +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class Utils { + public static String c(String text) { + return ChatColor.translateAlternateColorCodes('&', text); + } + + public static void broadcast(String message) { + for (Player p : Bukkit.getOnlinePlayers()) { + p.sendMessage(Utils.c(message)); + } + } + + + + public String getTabRank(Player p) { + final String prefix = PermissionsEx.getUser(p).getGroups()[0].getPrefix().replace("[", "").replace("]", ""); + final String rank = PermissionsEx.getUser(p).getGroups()[0].getName(); + if (prefix.equals("&4")) { + return Utils.c("&4" + rank); + } else if (prefix.equals("&c")) { + return Utils.c("&c" + rank); + } else if (prefix.equals("&6")) { + return Utils.c("&6" + rank); + } else if (prefix.equals("&e")) { + return Utils.c("&e" + rank); + } else if (prefix.equals("&2")) { + return Utils.c("&2" + rank); + } else if (prefix.equals("&a")) { + return Utils.c("&a" + rank); + } else if (prefix.equals("&b")) { + return Utils.c("&b" + rank); + } else if (prefix.equals("&3")) { + return Utils.c("&3" + rank); + } else if (prefix.equals("&1")) { + return Utils.c("&1" + rank); + } else if (prefix.equals("&9")) { + return Utils.c("&9" + rank); + } else if (prefix.equals("&d")) { + return Utils.c("&d" + rank); + } else if (prefix.equals("&5")) { + return Utils.c("&5" + rank); + } else if (prefix.equals("&f")) { + return Utils.c("&f" + rank); + } else if (prefix.equals("&7")) { + return Utils.c("&7" + rank); + } else if (prefix.equals("&8")) { + return Utils.c("&8" + rank); + } else if (prefix.equals("&0")) { + return Utils.c("&0" + rank); + } else if (prefix.equals(null)) { + return rank; + } else if (prefix.equals("")) { + return rank; + } else if (prefix.equals(" ")) { + return rank; + } else { + return prefix; + } + + } + + +} diff --git a/src/me/bruce/factions/KIts/GiveBook.java b/src/me/bruce/factions/KIts/GiveBook.java new file mode 100644 index 0000000..dea7566 --- /dev/null +++ b/src/me/bruce/factions/KIts/GiveBook.java @@ -0,0 +1,33 @@ +package me.bruce.factions.KIts; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import net.md_5.bungee.api.ChatColor; + +public class GiveBook { + + + public static void GiveBooktoplayer(Player p) { + ItemStack book = new ItemStack(Material.BOOK); + ItemMeta bmeta = book.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + "Select a kit"); + book.setItemMeta(bmeta); + + p.getInventory().addItem(book); + } + public static void takeBooktoplayer(Player p) { + ItemStack book = new ItemStack(Material.BOOK); + ItemMeta bmeta = book.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + "Select a kit"); + book.setItemMeta(bmeta); + + p.getInventory().remove(book);; + } + + + + +} diff --git a/src/me/bruce/factions/KIts/KitsBook.java b/src/me/bruce/factions/KIts/KitsBook.java new file mode 100644 index 0000000..170cb5a --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsBook.java @@ -0,0 +1,73 @@ +package me.bruce.factions.KIts; + +import java.util.ArrayList; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import net.md_5.bungee.api.ChatColor; + +public class KitsBook { + + public static void BookGui(Player p) { + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + ArrayList lore3 = new ArrayList(); + + Inventory book = Bukkit.createInventory(null, 9, ChatColor.GOLD + ChatColor.BOLD.toString() + "Kits Selector"); + + //Diamond Kit + ItemStack diamond = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemMeta dmeta = diamond.getItemMeta(); + dmeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Diamond Kit §7(Right Click)"); + lore.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Diamond Kit&7.")); + lore.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + dmeta.setLore(lore); + diamond.setItemMeta(dmeta); + + //Bard + ItemStack Bard = new ItemStack(Material.GOLD_CHESTPLATE); + ItemMeta bmeta = Bard.getItemMeta(); + bmeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Bard Kit §7(Right Click)"); + lore1.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore1.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Bard Kit&7.")); + lore1.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + bmeta.setLore(lore1); + Bard.setItemMeta(bmeta); + + //Archer Kit + ItemStack Archer = new ItemStack(Material.LEATHER_CHESTPLATE); + ItemMeta ameta = Archer.getItemMeta(); + ameta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Archer Kit §7(Right Click)"); + lore2.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore2.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Archer Kit&7.")); + lore2.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + ameta.setLore(lore2); + Archer.setItemMeta(ameta); + + //Builder Kit + ItemStack Builder = new ItemStack(Material.IRON_CHESTPLATE); + ItemMeta bumeta = Builder.getItemMeta(); + bumeta.setDisplayName(ChatColor.GOLD + ChatColor.BOLD.toString() + "Builder Kit §7(Right Click)"); + lore3.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + lore3.add(ChatColor.translateAlternateColorCodes('&', "&6&LRIGHT CLICK &7to use the &6Builder Kit&7.")); + lore3.add(ChatColor.GRAY + ChatColor.STRIKETHROUGH.toString() + "-------------------------------------------"); + bumeta.setLore(lore3); + Builder.setItemMeta(bumeta); + + book.setItem(0, diamond); + book.setItem(1, Bard); + book.setItem(2, Archer); + book.setItem(3, Builder); + + p.openInventory(book); + + } + +} diff --git a/src/me/bruce/factions/KIts/KitsInteract.java b/src/me/bruce/factions/KIts/KitsInteract.java new file mode 100644 index 0000000..a4c16bd --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsInteract.java @@ -0,0 +1,37 @@ +package me.bruce.factions.KIts; + +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; + +import net.md_5.bungee.api.ChatColor; + +public class KitsInteract implements Listener { + + @EventHandler + public void onInteract(PlayerInteractEvent e) { + Player p = e.getPlayer(); + ItemStack item = e.getItem(); + Action action = e.getAction(); + if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK) { + if (item == null) return; + if (item.getType() == Material.AIR) return; + + + if (item.getType() == Material.BOOK) { + if (!item.hasItemMeta()) return; + + if (item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GOLD + "Select a kit")) { + KitsBook.BookGui(p); + e.setCancelled(true); + } + } + } + } + + +} diff --git a/src/me/bruce/factions/KIts/KitsInvClick.java b/src/me/bruce/factions/KIts/KitsInvClick.java new file mode 100644 index 0000000..6313dbe --- /dev/null +++ b/src/me/bruce/factions/KIts/KitsInvClick.java @@ -0,0 +1,55 @@ +package me.bruce.factions.KIts; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.KIts.Kitsgive.GiveKits; +import me.bruce.factions.prefix.inventory.PrefixInventoryClick; +import ru.tehkode.permissions.PermissionUser; +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class KitsInvClick implements Listener { + + + @EventHandler + public void onInvClick(final InventoryClickEvent event) { + final Player player = (Player)event.getWhoClicked(); + if (event.getInventory().getName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Kits Selector")) { + event.setCancelled(true); + if (event.getCurrentItem() == null) { + return; + } + if (event.getCurrentItem().getType().equals((Object)Material.DIAMOND_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Diamond Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setDiamond(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.GOLD_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Bard Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setBard(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.LEATHER_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Archer Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setArcher(player); + player.closeInventory(); + + } + if (event.getCurrentItem().getType().equals((Object)Material.IRON_CHESTPLATE) && event.getCurrentItem().getItemMeta().getDisplayName().equals(ChatColor.GOLD + ChatColor.BOLD.toString() + "Builder Kit §7(Right Click)")) { + player.getInventory().clear(); + GiveKits.setBuilder(player); + player.closeInventory(); + + } + } + } +} + + diff --git a/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java b/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java new file mode 100644 index 0000000..48cb343 --- /dev/null +++ b/src/me/bruce/factions/KIts/Kitsgive/GiveKits.java @@ -0,0 +1,187 @@ +package me.bruce.factions.KIts.Kitsgive; + +import org.bukkit.Material; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +public class GiveKits { + + private static final ItemStack SPLASH_HEATH = new ItemStack(Material.POTION, 1, (short)16421); + + + //Kit stuff + private static int maxProtection = 1; + private static int maxSharpness = 1; + private static int maxUnbreaking = 3; + private static int maxFF = 4; + private static int maxPower = 3; + private static int maxFire = 0; + private static int maxInfinite = 1; + + public static void setDiamond(Player player) { + ItemStack helm = new ItemStack(Material.DIAMOND_HELMET); + ItemStack chest = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + player.getInventory().addItem(sword, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32)); + player.getInventory().setItem(8, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(17, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(26, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setItem(35, new ItemStack(Material.POTION, 1, (short) 8226)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setBard(Player player) { + ItemStack helm = new ItemStack(Material.GOLD_HELMET); + ItemStack chest = new ItemStack(Material.GOLD_CHESTPLATE); + ItemStack pants = new ItemStack(Material.GOLD_LEGGINGS); + ItemStack boots = new ItemStack(Material.GOLD_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + player.getInventory().addItem(sword, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32), new ItemStack(Material.BLAZE_POWDER, 32), new ItemStack(Material.SUGAR, 32), new ItemStack(Material.GHAST_TEAR, 2), new ItemStack(Material.FEATHER, 16), new ItemStack(Material.SPIDER_EYE, 16)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setArcher(Player player) { + ItemStack helm = new ItemStack(Material.LEATHER_HELMET); + ItemStack chest = new ItemStack(Material.LEATHER_CHESTPLATE); + ItemStack pants = new ItemStack(Material.LEATHER_LEGGINGS); + ItemStack boots = new ItemStack(Material.LEATHER_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + ItemStack bow = new ItemStack(Material.BOW); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + bow.addUnsafeEnchantment(Enchantment.ARROW_DAMAGE, maxPower); + bow.addUnsafeEnchantment(Enchantment.ARROW_FIRE, maxFire); + bow.addUnsafeEnchantment(Enchantment.ARROW_INFINITE, maxInfinite); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + + player.getInventory().addItem(sword, bow, new ItemStack(Material.ENDER_PEARL, 16), new ItemStack(Material.COOKED_BEEF, 32), new ItemStack(Material.ARROW, 1), new ItemStack(Material.SUGAR, 32)); + + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + public static void setBuilder(Player player) { + ItemStack helm = new ItemStack(Material.DIAMOND_HELMET); + ItemStack chest = new ItemStack(Material.DIAMOND_CHESTPLATE); + ItemStack pants = new ItemStack(Material.DIAMOND_LEGGINGS); + ItemStack boots = new ItemStack(Material.DIAMOND_BOOTS); + ItemStack sword = new ItemStack(Material.DIAMOND_SWORD); + + sword.addUnsafeEnchantment(Enchantment.DAMAGE_ALL, maxSharpness); + + helm.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + chest.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + pants.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + boots.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, maxProtection); + + helm.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + chest.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + pants.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + boots.addUnsafeEnchantment(Enchantment.DURABILITY, maxUnbreaking); + + boots.addUnsafeEnchantment(Enchantment.PROTECTION_FALL, maxFF); + + ItemStack pick = new ItemStack(Material.DIAMOND_PICKAXE); + pick.addEnchantment(Enchantment.DIG_SPEED, 5); + + ItemStack spade = new ItemStack(Material.DIAMOND_SPADE); + spade.addEnchantment(Enchantment.DIG_SPEED, 4); + player.getInventory().addItem(sword, + new ItemStack(Material.ENDER_PEARL, 16), + new ItemStack(Material.COOKED_BEEF, 32), + pick, + spade, + new ItemStack(Material.REDSTONE_BLOCK, 10), + new ItemStack(Material.GLASS, 64), + new ItemStack(Material.REDSTONE_COMPARATOR, 64), + new ItemStack(Material.WOOD_PLATE, 64), + new ItemStack(Material.FENCE, 64), + new ItemStack(Material.COOKED_BEEF, 16), + new ItemStack(Material.STRING, 64), + new ItemStack(Material.DIRT, 64), + new ItemStack(Material.COBBLESTONE, 64), + new ItemStack(Material.STONE, 64), + new ItemStack(Material.LOG, 64), + new ItemStack(Material.WATER_BUCKET, 64), + new ItemStack(Material.WOOL, 64), + new ItemStack(Material.STAINED_GLASS, 64, (short) 5), + new ItemStack(Material.COBBLESTONE_STAIRS, 64), + new ItemStack(Material.QUARTZ, 64), + new ItemStack(Material.GLOWSTONE), + new ItemStack(98, 64), + new ItemStack(Material.PISTON_BASE, 64), + new ItemStack(Material.SLIME_BALL, 64), + new ItemStack(Material.REDSTONE, 128), + new ItemStack(Material.HOPPER, 64), + new ItemStack(356, 64)); + player.getInventory().setHelmet(helm); + player.getInventory().setChestplate(chest); + player.getInventory().setLeggings(pants); + player.getInventory().setBoots(boots); + while (player.getInventory().firstEmpty() != -1) { + player.getInventory().addItem(new ItemStack[]{SPLASH_HEATH.clone()}); + } + } + + +} \ No newline at end of file diff --git a/src/me/bruce/factions/LorexHCF.java b/src/me/bruce/factions/LorexHCF.java new file mode 100644 index 0000000..419b825 --- /dev/null +++ b/src/me/bruce/factions/LorexHCF.java @@ -0,0 +1,722 @@ +package me.bruce.factions; + +import java.io.File; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.PluginCommand; +import org.bukkit.configuration.serialization.ConfigurationSerialization; +import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.PluginManager; +import org.bukkit.plugin.RegisteredServiceProvider; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.scheduler.BukkitRunnable; + +import com.sk89q.worldedit.bukkit.WorldEditPlugin; + +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; +import lombok.Getter; +import me.bruce.factions.armors.PvpClassManager; +import me.bruce.factions.armors.bard.EffectRestorer; +import me.bruce.factions.commands.BallerRevive; +import me.bruce.factions.commands.BroadCastCommand; +import me.bruce.factions.commands.Buy; +import me.bruce.factions.commands.CobbleCommand; +import me.bruce.factions.commands.CoordsCommand; +import me.bruce.factions.commands.FRCOMMAND; +import me.bruce.factions.commands.FixCommand; +import me.bruce.factions.commands.FreezeCommand; +import me.bruce.factions.commands.GiveCrowbarCommand; +import me.bruce.factions.commands.GlowstoneMountain; +import me.bruce.factions.commands.GoppleCommand; +import me.bruce.factions.commands.HelpCommand; +import me.bruce.factions.commands.HubCommand; +import me.bruce.factions.commands.InveeSeeCommand; +import me.bruce.factions.commands.LFFCommand; +import me.bruce.factions.commands.LogoutCommand; +import me.bruce.factions.commands.MapKitCommand; +import me.bruce.factions.commands.MedicCommand; +import me.bruce.factions.commands.OresCommand; +import me.bruce.factions.commands.Panic; +import me.bruce.factions.commands.PingCommand; +import me.bruce.factions.commands.PlayTimeCommand; +import me.bruce.factions.commands.PotsCommand; +import me.bruce.factions.commands.Pro; +import me.bruce.factions.commands.PvPCommand; +import me.bruce.factions.commands.RefundCommand; +import me.bruce.factions.commands.RegenCommand; +import me.bruce.factions.commands.RenameCommand; +import me.bruce.factions.commands.RulesCommand; +import me.bruce.factions.commands.SPCOMMAND; +import me.bruce.factions.commands.SetPrefixCommand; +import me.bruce.factions.commands.SettingsCommand; +import me.bruce.factions.commands.SpawnCommand; +import me.bruce.factions.commands.StaffInformation; +import me.bruce.factions.commands.StaffSettings; +import me.bruce.factions.commands.StatsCommand; +import me.bruce.factions.commands.TLCommand; +import me.bruce.factions.commands.Tablist; +import me.bruce.factions.commands.TablistCommand; +import me.bruce.factions.commands.ToggleCapzoneEntryCommand; +import me.bruce.factions.commands.ToggleLightningCommand; +import me.bruce.factions.commands.Vip; +import me.bruce.factions.commands.WB; +import me.bruce.factions.commands.ZorexDeveloper; +import me.bruce.factions.commands.ZorexRevive; +import me.bruce.factions.commands.nv; +import me.bruce.factions.commands.randomtp; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.deathban.DeathbanListener; +import me.bruce.factions.deathban.DeathbanManager; +import me.bruce.factions.deathban.FlatFileDeathbanManager; +import me.bruce.factions.deathban.StaffReviveCommand; +import me.bruce.factions.deathban.lives.LivesExecutor; +import me.bruce.factions.economy.EconomyCommand; +import me.bruce.factions.economy.EconomyManager; +import me.bruce.factions.economy.FlatFileEconomyManager; +import me.bruce.factions.economy.PayCommand; +import me.bruce.factions.economy.ShopSignListener; +import me.bruce.factions.endoftheworld.EotwCommand; +import me.bruce.factions.endoftheworld.EotwHandler; +import me.bruce.factions.endoftheworld.EotwListener; +import me.bruce.factions.eventutils.CaptureZone; +import me.bruce.factions.eventutils.EventExecutor; +import me.bruce.factions.eventutils.EventScheduler; +import me.bruce.factions.faction.FactionExecutor; +import me.bruce.factions.faction.FactionManager; +import me.bruce.factions.faction.FactionMember; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.FlatFileFactionManager; +import me.bruce.factions.faction.args.FactionClaimChunkArgument; +import me.bruce.factions.faction.claim.Claim; +import me.bruce.factions.faction.claim.ClaimHandler; +import me.bruce.factions.faction.claim.ClaimWandListener; +import me.bruce.factions.faction.claim.Subclaim; +import me.bruce.factions.faction.claim.SubclaimWandListener; +import me.bruce.factions.faction.type.CapturableFaction; +import me.bruce.factions.faction.type.ClaimableFaction; +import me.bruce.factions.faction.type.ConquestFaction; +import me.bruce.factions.faction.type.EndPortalFaction; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.GlowstoneMountainFaction; +import me.bruce.factions.faction.type.KothFaction; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.faction.type.RoadFaction; +import me.bruce.factions.faction.type.SpawnFaction; +import me.bruce.factions.keysale.keysaleCommand; +import me.bruce.factions.koth.KothExecutor; +import me.bruce.factions.listener.AutoSmeltOreListener; +import me.bruce.factions.listener.BookDeenchantListener; +import me.bruce.factions.listener.BorderListener; +import me.bruce.factions.listener.BottledExpListener; +import me.bruce.factions.listener.ChatListener; +import me.bruce.factions.listener.Cooldowns; +import me.bruce.factions.listener.CoreListener; +import me.bruce.factions.listener.CreativeClickListener; +import me.bruce.factions.listener.CrowbarListener; +import me.bruce.factions.listener.DeathMessageListener; +import me.bruce.factions.listener.DeathSignListener; +import me.bruce.factions.listener.ElevatorListener; +import me.bruce.factions.listener.EndListener; +import me.bruce.factions.listener.EntityLimitListener; +import me.bruce.factions.listener.EventSignListener; +import me.bruce.factions.listener.ExpMultiplierListener; +import me.bruce.factions.listener.FactionListener; +import me.bruce.factions.listener.FastEverythingListener; +import me.bruce.factions.listener.FoundDiamondsListener; +import me.bruce.factions.listener.ItemRemoverListener; +import me.bruce.factions.listener.MineListener; +import me.bruce.factions.listener.PlayTimeManager; +import me.bruce.factions.listener.PortalListener; +import me.bruce.factions.listener.PotListener; +import me.bruce.factions.listener.ProtectionListener; +import me.bruce.factions.listener.SignSubclaimListener; +import me.bruce.factions.listener.StaffModeListener; +import me.bruce.factions.listener.StrengthListener; +import me.bruce.factions.listener.UnRepairableListener; +import me.bruce.factions.listener.UserManager; +import me.bruce.factions.listener.VanishListener; +import me.bruce.factions.listener.WorldListener; +import me.bruce.factions.listener.combatloggers.CombatLogListener; +import me.bruce.factions.listener.combatloggers.CustomEntityRegistration; +import me.bruce.factions.listener.fixes.ArmorFixListener; +import me.bruce.factions.listener.fixes.BlockHitFixListener; +import me.bruce.factions.listener.fixes.BlockJumpGlitchFixListener; +import me.bruce.factions.listener.fixes.BoatGlitchFixListener; +import me.bruce.factions.listener.fixes.ColonCommandFixListener; +import me.bruce.factions.listener.fixes.CreatureSpawn; +import me.bruce.factions.listener.fixes.EnchantLimitListener; +import me.bruce.factions.listener.fixes.EnderChestRemovalListener; +import me.bruce.factions.listener.fixes.HungerFixListener; +import me.bruce.factions.listener.fixes.InfinityArrowFixListener; +import me.bruce.factions.listener.fixes.PearlGlitchListener; +import me.bruce.factions.listener.fixes.PortalTrapFixListener; +import me.bruce.factions.listener.fixes.PotionLimitListener; +import me.bruce.factions.listener.fixes.VoidGlitchFixListener; +import me.bruce.factions.listener.render.ProtocolLibHook; +import me.bruce.factions.listener.render.VisualiseHandler; +import me.bruce.factions.listener.render.WallBorderListener; +import me.bruce.factions.prefix.PrefixInv; +import me.bruce.factions.prefix.PrefixMenu; +import me.bruce.factions.prefix.prefix; + +import me.bruce.factions.rank.RankCommand; +import me.bruce.factions.rank.RankExecutor; +import me.bruce.factions.reboot.rebootCommand; +import me.bruce.factions.scoreboard.ScoreboardHandler; +import me.bruce.factions.staff.StaffModeCommand; +import me.bruce.factions.staff.VanishCommand; +import me.bruce.factions.startoftheworld.SotwCommand; +import me.bruce.factions.startoftheworld.SotwListener; +import me.bruce.factions.startoftheworld.SotwTimer; +import me.bruce.factions.timer.TimerExecutor; +import me.bruce.factions.timer.TimerManager; +import me.bruce.factions.ymls.AThing; +import me.bruce.factions.ymls.SettingsYML; +import me.bruceboy.framework.commands.Fly; +import me.bruceboy.framework.commands.Gamemode; +import me.bruceboy.framework.commands.ListCommand; +import me.bruceboy.framework.commands.Teleport; +import me.bruceboy.framework.commands.tphere; +import me.tablist.api.tabapi.Tab; +import me.tablist.api.tablist.adapter.TablistAdapter; +//import src.me.bruceboy.tablist.lorexmc.utils.main.TabCreator; +import net.milkbowl.vault.chat.Chat; +import net.milkbowl.vault.economy.Economy; +import net.milkbowl.vault.permission.Permission; + +public class LorexHCF extends JavaPlugin { + public static Permission permission = null; + public static Economy economy = null; + public static Economy econ = null; + public static Chat chat = null; + public static final String PREFIX; + public static final String NOPLAYER; + public static final String PREFIXNOPERMS; + public static final String NOPERMS; + AThing utils = new AThing(this); + + + @Getter + private static LorexHCF instance; + @Getter + private PlayTimeManager playTimeManager; + @Getter + private Random random = new Random(); + @Getter + private ClaimHandler claimHandler; + @Getter + private DeathbanManager deathbanManager; + @Getter + private EconomyManager economyManager; + @Getter + private EffectRestorer effectRestorer; + @Getter + private EotwHandler eotwHandler; + @Getter + private EventScheduler eventScheduler; + @Getter + private FactionManager factionManager; + @Getter + private FoundDiamondsListener foundDiamondsListener; + @Getter + private PvpClassManager pvpClassManager; + @Getter + private ScoreboardHandler scoreboardHandler; + @Getter + private SotwTimer sotwTimer; + @Getter + private static me.bruce.factions.keysale.keysaletimer keysaletimer; + @Getter + private static me.bruce.factions.reboot.reboottimer reboottimer; + @Getter + private TimerManager timerManager; + @Getter + private FactionUser factionUser; + @Getter + private UserManager userManager; + @Getter + private VisualiseHandler visualiseHandler; + @Getter + private WorldEditPlugin worldEdit; + + private CombatLogListener combatLogListener; + + public CombatLogListener getCombatLogListener() { + return this.combatLogListener; + } + public static String PREFIX1 = ChatColor.GOLD + "" + ChatColor.BOLD + "Zorex" + ChatColor.GRAY + " » "; + + public void resetGlowstoneMountain() { + for (int x = 502; x <= 582; x++) { + for (int y = 76; y <= 112; y++) { + for (int z = 594; z > 514; z--) { + Block block = Bukkit.getWorld("world_nether") + .getBlockAt(new Location(Bukkit.getWorld("world_nether"), -1 * x, y, z)); + if (block.getType().equals(Material.AIR)) { + block.setType(Material.GLOWSTONE); + } + } + } + } + } + + @Override + public void onEnable() { + //new TabList(this, new me.bruceboy.tablist.lorexmc.utils.main.TabCreator()); + + Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "HCF Enabled"); + setupEconomy(); + File file = new File(getDataFolder(), "config.yml"); + if (!file.exists()) { + this.getConfig().options().copyDefaults(true); + this.saveConfig(); + } + Cooldowns.createCooldown("medic_cooldown"); + Cooldowns.createCooldown("lff_cooldown"); + Cooldowns.createCooldown("revive_cooldown"); + + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7The core has been &aenabled!&7.")); + instance = this; + BasePlugin.getPlugin().init(this); + + ProtocolLibHook.hook(this); + + Plugin wep = getServer().getPluginManager().getPlugin("WorldEdit"); + Plugin kits = getServer().getPluginManager().getPlugin("VengefulKits"); + this.worldEdit = wep instanceof WorldEditPlugin && wep.isEnabled() ? (WorldEditPlugin) wep : null; + CustomEntityRegistration.registerCustomEntities(); + + SettingsYML.init(this); + this.effectRestorer = new EffectRestorer(this); + this.registerConfiguration(); + this.registerCommands(); + // getCommand("list").setExecutor(new ListCommand()); + //getCommand("fly").setExecutor(new Fly()); + getCommand("spawn").setExecutor(new SpawnCommand()); + getCommand("author").setExecutor(new ZorexDeveloper()); + getCommand("stats").setExecutor(new StatsCommand()); + this.registerManagers(); + this.registerListeners(); + this.setupPermissions(); + this.resetGlowstoneMountain(); + this.prefixcommands(); + this.registerEvents1(); + tab(); + + + new BukkitRunnable() { + @Override + public void run() { + getServer().broadcastMessage(ChatColor.RED.toString() + ChatColor.BOLD + "Saving" + "\n" + ChatColor.RED + + "All the faction data to the database."); + saveData(); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&7&m----------------------------------------------")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&cJoin our discord at: https://discord.gg/eZS8Brc")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', + "&7&m----------------------------------------------")); + } + }.runTaskTimerAsynchronously(this, TimeUnit.MINUTES.toMillis(10L), TimeUnit.SECONDS.toMillis(10L)); + } + public void tab() { + TablistAdapter ta = new TablistAdapter(this, utils); + Bukkit.getServer().getPluginManager().registerEvents(new Tab(this, utils, ta), this); + } + + + + + private void saveData() { + this.combatLogListener.removeCombatLoggers(); + this.deathbanManager.saveDeathbanData(); + this.economyManager.saveEconomyData(); + this.factionManager.saveFactionData(); + this.timerManager.saveTimerData(); + this.userManager.saveUserData(); + } + + @Override + public void onDisable() { + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Economy has been &asaved! &7(1/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Faction has been &asaved! &7(2/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Key Data has been &asaved! &7(3/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Cooldowns has been &asaved! &7(4/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Player Data has been &asaved! &7(5/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Player Vaults has been &asaved! &7(6/6)")); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7Saving is now &acomplete!&7.")); + this.pvpClassManager.onDisable(); + this.scoreboardHandler.clearBoards(); + this.factionManager.saveFactionData(); + this.deathbanManager.saveDeathbanData(); + this.economyManager.saveEconomyData(); + this.factionManager.saveFactionData(); + this.timerManager.saveTimerData(); + this.userManager.saveUserData(); + this.playTimeManager.savePlaytimeData(); + this.saveData(); + + instance = null; // always initialise last + } + + public static Chat getChat() { + return LorexHCF.chat; + } + + private boolean setupPermissions() { + final RegisteredServiceProvider permissionProvider = this.getServer().getServicesManager() + .getRegistration((Class) Permission.class); + if (permissionProvider != null) { + permission = (Permission) permissionProvider.getProvider(); + } + return permission != null; + } + + private boolean setupChat() { + final RegisteredServiceProvider chatProvider = this.getServer().getServicesManager() + .getRegistration((Class) Chat.class); + if (chatProvider != null) { + LorexHCF.chat = (Chat) chatProvider.getProvider(); + } + return LorexHCF.chat != null; + } + + private boolean setupEconomy() { + if (getServer().getPluginManager().getPlugin("Vault") == null) { + return false; + } + RegisteredServiceProvider rsp = getServer().getServicesManager().getRegistration(Economy.class); + if (rsp == null) { + return false; + } + econ = rsp.getProvider(); + return econ != null; + } + + private void registerConfiguration() { + ConfigurationSerialization.registerClass(CaptureZone.class); + ConfigurationSerialization.registerClass(Deathban.class); + ConfigurationSerialization.registerClass(Claim.class); + ConfigurationSerialization.registerClass(Subclaim.class); + ConfigurationSerialization.registerClass(Deathban.class); + ConfigurationSerialization.registerClass(FactionUser.class); + ConfigurationSerialization.registerClass(ClaimableFaction.class); + ConfigurationSerialization.registerClass(ConquestFaction.class); + ConfigurationSerialization.registerClass(CapturableFaction.class); + ConfigurationSerialization.registerClass(KothFaction.class); + ConfigurationSerialization.registerClass(EndPortalFaction.class); + ConfigurationSerialization.registerClass(Faction.class); + ConfigurationSerialization.registerClass(FactionMember.class); + ConfigurationSerialization.registerClass(PlayerFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.class); + ConfigurationSerialization.registerClass(SpawnFaction.class); + ConfigurationSerialization.registerClass(GlowstoneMountainFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.NorthRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.EastRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.SouthRoadFaction.class); + ConfigurationSerialization.registerClass(RoadFaction.WestRoadFaction.class); + } + + public void registerListeners() { + PluginManager manager = this.getServer().getPluginManager(); + this.playTimeManager = new PlayTimeManager(this); + manager.registerEvents(this.playTimeManager, this); + // If Kit_MAP = true then this will enable and the false shit wont enable. + manager.registerEvents(this.combatLogListener = new CombatLogListener(this), this); + manager.registerEvents(new BlockHitFixListener(), this); + manager.registerEvents(new BlockJumpGlitchFixListener(), this); + manager.registerEvents(new BoatGlitchFixListener(), this); + manager.registerEvents(new BookDeenchantListener(), this); + manager.registerEvents(new FactionClaimChunkArgument(this), this); + manager.registerEvents(new BorderListener(), this); // I never fix the pearl pass border in this version might + // wanna fix it + manager.registerEvents(new CreatureSpawn(), this); + manager.registerEvents(new CobbleCommand(), this); + manager.registerEvents(new BottledExpListener(), this); + manager.registerEvents(new PortalTrapFixListener(this), this); + manager.registerEvents(new ChatListener(this), this); + manager.registerEvents(new ClaimWandListener(this), this); + manager.registerEvents(new CoreListener(this), this); + manager.registerEvents(new ElevatorListener(this), this); + manager.registerEvents(new CrowbarListener(this), this); + manager.registerEvents(new DeathMessageListener(this), this); + manager.registerEvents(new DeathSignListener(this), this); + manager.registerEvents(new PotsCommand(this), this); + manager.registerEvents(new SettingsCommand(), this); + manager.registerEvents(new Tablist(), this); + manager.registerEvents(new ShopSignListener(this), this); + + // If KIT_MAP = false then this will enable if its true this enables. + if (SettingsYML.KIT_MAP == false) { + manager.registerEvents(new DeathbanListener(this), this); + } + manager.registerEvents(new EnchantLimitListener(), this); + manager.registerEvents(new EnderChestRemovalListener(), this); + manager.registerEvents(new EntityLimitListener(), this); + manager.registerEvents(new EndListener(), this); + manager.registerEvents(new EotwListener(this), this); + manager.registerEvents(new EventSignListener(), this); + manager.registerEvents(new ExpMultiplierListener(), this); + manager.registerEvents(new FactionListener(this), this); + manager.registerEvents(this.foundDiamondsListener = new FoundDiamondsListener(this), this); + manager.registerEvents(new FastEverythingListener(this), this); + manager.registerEvents(new InfinityArrowFixListener(), this); + manager.registerEvents(new PearlGlitchListener(this), this); + manager.registerEvents(new PortalListener(this), this); + manager.registerEvents(new PotionLimitListener(), this); + manager.registerEvents(new ProtectionListener(this), this); + manager.registerEvents(new SubclaimWandListener(this), this); + manager.registerEvents(new SignSubclaimListener(this), this); + manager.registerEvents(new SotwListener(this), this); + manager.registerEvents(new VoidGlitchFixListener(), this); + manager.registerEvents(new UnRepairableListener(), this); + manager.registerEvents(new WallBorderListener(this), this); + manager.registerEvents(new AutoSmeltOreListener(), this); + manager.registerEvents(new WorldListener(this), this); + manager.registerEvents(new MineListener(this), this); + manager.registerEvents(new ItemRemoverListener(this), this); + manager.registerEvents(new PotListener(this), this); // this pot listener is aids btw + // manager.registerEvents(new GlowstoneListener (this), this); + manager.registerEvents(new StrengthListener(), this); + manager.registerEvents(new CreativeClickListener(), this); + manager.registerEvents(new ArmorFixListener(), this); + manager.registerEvents(new HungerFixListener(this), this); + manager.registerEvents(new ColonCommandFixListener(), this); + manager.registerEvents(new RefundCommand(this), this); + manager.registerEvents(new InveeSeeCommand(), this); + //manager.registerEvents((Listener)new StaffModeListener(), (Plugin)this); + //manager.registerEvents((Listener)new VanishListener(), this); + manager.registerEvents(new me.bruce.factions.KIts.KitsInteract(), this); + manager.registerEvents(new me.bruce.factions.KIts.KitsInvClick(), this); + manager.registerEvents(new StaffSettings(), this); + manager.registerEvents(new TablistCommand(), this); + } + + private void registerCommands() { + getCommand("vanish").setExecutor(new VanishCommand()); + getCommand("zorex").setExecutor(new ZorexRevive(this)); + getCommand("vip").setExecutor(new Vip(this)); + getCommand("pro").setExecutor(new Pro(this)); + getCommand("rules").setExecutor(new RulesCommand()); + getCommand("baller").setExecutor(new BallerRevive(this)); + getCommand("tl").setExecutor(new TLCommand()); + getCommand("invsee").setExecutor(new InveeSeeCommand()); + getCommand("fix").setExecutor(new FixCommand()); + getCommand("broadcast").setExecutor(new BroadCastCommand()); + getCommand("cobble").setExecutor(new CobbleCommand()); + getCommand("hub").setExecutor(new HubCommand(this)); + getCommand("amethyst").setExecutor(new MedicCommand(this)); + getCommand("crowgive").setExecutor(new GiveCrowbarCommand()); + getCommand("hcfhelp").setExecutor(new HelpCommand()); + getCommand("coords").setExecutor(new CoordsCommand()); + getCommand("conquest").setExecutor(new me.bruce.factions.conquest.ConquestExecutor(this)); + getCommand("economy").setExecutor(new EconomyCommand(this)); + getCommand("refund").setExecutor(new RefundCommand(this)); + getCommand("eotw").setExecutor(new EotwCommand(this)); + getCommand("panic").setExecutor(new Panic()); + getCommand("tablistgui").setExecutor(new TablistCommand()); + getCommand("event").setExecutor(new EventExecutor(this)); + getCommand("hcfhelp").setExecutor(new HelpCommand()); + getCommand("faction").setExecutor(new FactionExecutor(this)); + getCommand("tp").setExecutor(new Teleport()); + getCommand("wb").setExecutor(new WB()); + getCommand("nv").setExecutor(new nv()); + getCommand("here").setExecutor(new tphere()); +// getCommand("vanish").setExecutor((CommandExecutor)new VanishCommand()); + getCommand("gopple").setExecutor(new GoppleCommand(this)); + getCommand("gamemode").setExecutor( new Gamemode()); + getCommand("koth").setExecutor(new KothExecutor(this)); + getCommand("lives").setExecutor(new LivesExecutor(this)); + getCommand("ping").setExecutor(new PingCommand()); + //getCommand("slowchat").setExecutor(new SlowChat(this)); + //getCommand("disablechat").setExecutor(new DisableChat(this)); + getCommand("freeze").setExecutor(new FreezeCommand(this)); + getCommand("logout").setExecutor(new LogoutCommand(this)); + //tCommand("staffmode").setExecutor((CommandExecutor)new StaffModeCommand()); + getCommand("mapkit").setExecutor(new MapKitCommand(this)); + getCommand("pay").setExecutor(new PayCommand(this)); + getCommand("tablist").setExecutor(new Tablist()); + getCommand("sp").setExecutor(new SPCOMMAND()); + getCommand("fr").setExecutor(new FRCOMMAND()); + getCommand("pvptimer").setExecutor(new PvPCommand(this)); + getCommand("reboot").setExecutor(new rebootCommand(this)); + getCommand("staffgui").setExecutor(new StaffSettings()); + getCommand("pots").setExecutor(new PotsCommand(this)); + getCommand("regen").setExecutor(new RegenCommand(this)); + getCommand("keysale").setExecutor(new keysaleCommand(this)); + getCommand("sotw").setExecutor(new SotwCommand(this)); + getCommand("staffrevive").setExecutor(new StaffReviveCommand(this)); + getCommand("staffguide").setExecutor(new StaffInformation()); + getCommand("timer").setExecutor(new TimerExecutor(this)); + getCommand("lff").setExecutor(new LFFCommand(this)); + getCommand("togglecapzoneentry").setExecutor(new ToggleCapzoneEntryCommand(this)); + getCommand("togglelightning").setExecutor(new ToggleLightningCommand(this)); + getCommand("rename").setExecutor(new RenameCommand(this)); + getCommand("ores").setExecutor(new OresCommand(this)); + getCommand("playtime").setExecutor(new PlayTimeCommand()); + getCommand("settings").setExecutor(new SettingsCommand()); + getCommand("rank").setExecutor(new RankExecutor(this)); + getCommand("glowstonemountain").setExecutor(new GlowstoneMountain(this)); + getCommand("buy").setExecutor(new Buy()); + getCommand("setprefix").setExecutor(new SetPrefixCommand()); + getCommand("randomtp").setExecutor(new randomtp()); + getCommand("staffgui").setExecutor(new StaffSettings()); + + Map> map = getDescription().getCommands(); + for (Map.Entry> entry : map.entrySet()) { + PluginCommand command = getCommand(entry.getKey()); + command.setPermission("zorex." + entry.getKey()); + command.setPermissionMessage(ChatColor.RED + "You do not have permissions to execute this command."); + } + } + private void registerManagers() { + this.claimHandler = new ClaimHandler(this); + this.deathbanManager = new FlatFileDeathbanManager(this); + this.economyManager = new FlatFileEconomyManager(this); + this.eotwHandler = new EotwHandler(this); + this.eventScheduler = new EventScheduler(this); + this.factionManager = new FlatFileFactionManager(this); + this.pvpClassManager = new PvpClassManager(this); + this.sotwTimer = new SotwTimer(); + this.keysaletimer = new me.bruce.factions.keysale.keysaletimer(); + this.reboottimer = new me.bruce.factions.reboot.reboottimer(); + this.timerManager = new TimerManager(this); // needs to be registered before ScoreboardHandler + this.scoreboardHandler = new ScoreboardHandler(this); + this.userManager = new UserManager(this); + this.visualiseHandler = new VisualiseHandler(); + } + + public void prefixcommands() { + this.getCommand("prefix").setExecutor((CommandExecutor)new prefix()); + } + private void registerEvents1() { + final PluginManager pm = Bukkit.getPluginManager(); + pm.registerEvents((Listener)new PrefixMenu(), (Plugin)this); + pm.registerEvents((Listener)new PrefixInv(), (Plugin)this); + + } + + + private void registerCooldowns() { + Cooldowns.createCooldown("medic_cooldown"); + } + + + + public PlayTimeManager getPlayTimeManager() { + return this.playTimeManager; + } + + public static LorexHCF getInstance() { + return LorexHCF.instance; + } + + public Random getRandom() { + return this.random; + } + + + + public ClaimHandler getClaimHandler() { + return this.claimHandler; + } + + public DeathbanManager getDeathbanManager() { + return this.deathbanManager; + } + + public EconomyManager getEconomyManager() { + return this.economyManager; + } + + public EffectRestorer getEffectRestorer() { + return this.effectRestorer; + } + + public EotwHandler getEotwHandler() { + return this.eotwHandler; + } + + public static SotwTimer getSotwRunnable() { + return LorexHCF.getSotwRunnable(); + } + + public FactionUser getFactionUser() { + return this.factionUser; + } + + public EventScheduler getEventScheduler() { + return this.eventScheduler; + } + + public FactionManager getFactionManager() { + return this.factionManager; + } + + public FoundDiamondsListener getFoundDiamondsListener() { + return this.foundDiamondsListener; + } + + public PvpClassManager getPvpClassManager() { + return this.pvpClassManager; + } + + public ScoreboardHandler getScoreboardHandler() { + return this.scoreboardHandler; + } + public static me.bruce.factions.keysale.keysaletimer getkeysalerunnable() { + return LorexHCF.getkeysalerunnable(); + } + public static me.bruce.factions.keysale.keysaletimer getkeysaletimer() { + return keysaletimer; + } + public static me.bruce.factions.reboot.reboottimer getreboottimer() { + return reboottimer; + } + + + + public SotwTimer getSotwTimer() { + return this.sotwTimer; + } + public me.bruce.factions.reboot.reboottimer getrebootrunnable() { + return this.reboottimer; + } + + public TimerManager getTimerManager() { + return this.timerManager; + } + + public UserManager getUserManager() { + return this.userManager; + } + + public VisualiseHandler getVisualiseHandler() { + return this.visualiseHandler; + } + + public WorldEditPlugin getWorldEdit() { + return this.worldEdit; + } + + public static ChatColor getRemaining(long remaining, boolean b, boolean c) { + // TODO Auto-generated method stub + return null; + } + static { + PREFIX = ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY; + NOPLAYER = ChatColor.RED + "You must be a player to use this command. "; + PREFIXNOPERMS = ChatColor.RED + "You lack the sufficient permissions to use this prefix. "; + NOPERMS = ChatColor.RED + "You lack the sufficient permissions to execute this command. "; + } + +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/PvpClass.java b/src/me/bruce/factions/armors/PvpClass.java new file mode 100644 index 0000000..1dff36a --- /dev/null +++ b/src/me/bruce/factions/armors/PvpClass.java @@ -0,0 +1,83 @@ +package me.bruce.factions.armors; + +import org.bukkit.ChatColor; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; + +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; + +/** + * Represents a class that can apply PVP buffs for players. + */ +public abstract class PvpClass { + + public static final long DEFAULT_MAX_DURATION = TimeUnit.MINUTES.toMillis(8L); + + protected final Set passiveEffects = new HashSet<>(); + protected final String name; + protected final long warmupDelay; + + public PvpClass(String name, long warmupDelay) { + this.name = name; + this.warmupDelay = warmupDelay; + } + + /** + * Gets the name of this {@link PvpClass}. + * + * @return the name + */ + public String getName() { + return name; + } + + /** + * Gets the warmup delay of this {@link PvpClass}. + * + * @return the warmup delay in milliseconds + */ + public long getWarmupDelay() { + return warmupDelay; + } + + /** + * Method called when a {@link Player} equips a {@link PvpClass}. + * + * @param player + * the equipping {@link Player} + * @return true if successfully equipped + */ + public boolean onEquip(Player player) { + for (PotionEffect effect : passiveEffects) { + player.addPotionEffect(effect, true); + } + + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.YELLOW + name + " has been activated."); + return true; + } + + /** + * Method called when a {@link Player} unequips a {@link PvpClass}. + * + * @param player + * the unequipping {@link Player} + */ + public void onUnequip(Player player) { + for (PotionEffect effect : passiveEffects) { + for (PotionEffect active : player.getActivePotionEffects()) { + if (active.getDuration() > DEFAULT_MAX_DURATION && active.getType().equals(effect.getType()) + && active.getAmplifier() == effect.getAmplifier()) { + player.removePotionEffect(effect.getType()); + break; + } + } + } + + player.sendMessage(ChatColor.RED + name + " has been deactivated."); + } + + // TODO: More automated method + public abstract boolean isApplicableFor(Player player); +} diff --git a/src/me/bruce/factions/armors/PvpClassManager.java b/src/me/bruce/factions/armors/PvpClassManager.java new file mode 100644 index 0000000..3239a60 --- /dev/null +++ b/src/me/bruce/factions/armors/PvpClassManager.java @@ -0,0 +1,103 @@ +package me.bruce.factions.armors; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.archer.ArcherClass; +import me.bruce.factions.armors.bard.BardClass; +import me.bruce.factions.armors.event.PvpClassEquipEvent; +import me.bruce.factions.armors.event.PvpClassUnequipEvent; +import me.bruce.factions.armors.miner.MinerClass; +import me.bruce.factions.armors.rogue.RogueClass; + +import javax.annotation.Nullable; +import java.util.*; + +public class PvpClassManager implements Listener { + + // Mapping to get the PVP Class a player has equipped. + private final Map equippedClassMap = new HashMap<>(); + + private final List pvpClasses = new ArrayList<>(); + + public PvpClassManager(LorexHCF plugin) { + pvpClasses.add(new ArcherClass(plugin)); + pvpClasses.add(new BardClass(plugin)); + pvpClasses.add(new MinerClass(plugin)); + pvpClasses.add(new RogueClass(plugin)); + + Bukkit.getPluginManager().registerEvents(this, plugin); + for (PvpClass pvpClass : pvpClasses) { + if (pvpClass instanceof Listener) { + plugin.getServer().getPluginManager().registerEvents((Listener) pvpClass, plugin); + } + } + } + + public void onDisable() { + for (Map.Entry entry : new HashMap<>(equippedClassMap).entrySet()) { + this.setEquippedClass(Bukkit.getPlayer(entry.getKey()), null); + } + + this.pvpClasses.clear(); + this.equippedClassMap.clear(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerDeath(PlayerDeathEvent event) { + setEquippedClass(event.getEntity(), null); + } + + /** + * Gets the {@link PvpClass}es held by this manager + * + * @return set of {@link PvpClass}es + */ + public Collection getPvpClasses() { + return pvpClasses; + } + + /** + * Gets the equipped {@link PvpClass} of a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the equipped {@link PvpClass} + */ + public PvpClass getEquippedClass(Player player) { + synchronized (equippedClassMap) { + return equippedClassMap.get(player.getUniqueId()); + } + } + + public boolean hasClassEquipped(Player player, PvpClass pvpClass) { + return getEquippedClass(player) == pvpClass; + } + + /** + * Sets the equipped {@link PvpClass} of a {@link Player}. + * + * @param player + * the {@link Player} to set for + * @param pvpClass + * the class to equip or null to un-equip active + */ + public void setEquippedClass(Player player, @Nullable PvpClass pvpClass) { + if (pvpClass == null) { + PvpClass equipped = this.equippedClassMap.remove(player.getUniqueId()); + if (equipped != null) { + equipped.onUnequip(player); + Bukkit.getPluginManager().callEvent(new PvpClassUnequipEvent(player, equipped)); + } + } else if (pvpClass.onEquip(player) && pvpClass != this.getEquippedClass(player)) { + equippedClassMap.put(player.getUniqueId(), pvpClass); + Bukkit.getPluginManager().callEvent(new PvpClassEquipEvent(player, pvpClass)); + } + } +} diff --git a/src/me/bruce/factions/armors/archer/ArcherClass.java b/src/me/bruce/factions/armors/archer/ArcherClass.java new file mode 100644 index 0000000..9de3461 --- /dev/null +++ b/src/me/bruce/factions/armors/archer/ArcherClass.java @@ -0,0 +1,217 @@ +package me.bruce.factions.armors.archer; + +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; + +import java.util.HashMap; +import java.util.Random; +import java.util.UUID; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.Color; +import org.bukkit.Material; +import org.bukkit.entity.Arrow; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.inventory.meta.LeatherArmorMeta; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.projectiles.ProjectileSource; + +public class ArcherClass extends PvpClass implements Listener { + private static final PotionEffect ARCHER_CRITICAL_EFFECT = new PotionEffect(PotionEffectType.SLOW, 60, 255); + private static final int MARK_TIMEOUT_SECONDS = 15; + private static final int MARK_EXECUTION_LEVEL = 3; + private static final float MINIMUM_FORCE = 0.5F; + public static final HashMap TAGGED = new HashMap(); + private static final PotionEffect ARCHER_SPEED_EFFECT = new PotionEffect(PotionEffectType.SPEED, 160, 3); + private static final PotionEffect ARCHER_JUMP_EFFECT = new PotionEffect(PotionEffectType.JUMP, 160, 3); + private static final long ARCHER_SPEED_COOLDOWN_DELAY = TimeUnit.SECONDS.toMillis(45L); + private static final long ARCHER_JUMP_COOLDOWN_DELAY = TimeUnit.MINUTES.toMillis(1L); + public static final TObjectLongMap archerSpeedCooldowns = new TObjectLongHashMap(); + private final TObjectLongMap archerJumpCooldowns = new TObjectLongHashMap(); + private final LorexHCF plugin; + private static Random random = new Random(); + + public ArcherClass(LorexHCF plugin) { + super("Archer", TimeUnit.SECONDS.toMillis(5L)); + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamage(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + Entity damager = event.getDamager(); + if (((entity instanceof Player)) && ((damager instanceof Arrow))) { + Arrow arrow = (Arrow) damager; + ProjectileSource source = arrow.getShooter(); + if ((source instanceof Player)) { + Player damaged = (Player) event.getEntity(); + Player shooter = (Player) source; + PvpClass equipped = this.plugin.getPvpClassManager().getEquippedClass(shooter); + if ((equipped == null) || (!equipped.equals(this))) { + return; + } + if ((this.plugin.getTimerManager().archerTimer.getRemaining((Player) entity) == 0L) + || (this.plugin.getTimerManager().archerTimer.getRemaining((Player) entity) < TimeUnit.SECONDS + .toMillis(5L))) { + if ((this.plugin.getPvpClassManager().getEquippedClass(damaged) != null) + && (this.plugin.getPvpClassManager().getEquippedClass(damaged).equals(this))) { + return; + } + double distance = shooter.getLocation().distance(damaged.getLocation()); + shooter.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&e[&9Arrow Range &e(&c" + String.format("%.1f", new Object[] { Double.valueOf(distance) }) + + "&e)] " + "&6Marked " + damaged.getName() + " &6for 6 seconds. &9&l(1 heart)")); + + damaged.sendMessage(ChatColor.GOLD + "You were archer tagged by " + ChatColor.RED + + shooter.getName() + ChatColor.GOLD + " from " + ChatColor.RED + + String.format("%.1f", new Object[] { Double.valueOf(distance) }) + ChatColor.GOLD + + " blocks away."); + + LeatherArmorMeta helmMeta = (LeatherArmorMeta) shooter.getInventory().getHelmet().getItemMeta(); + LeatherArmorMeta chestMeta = (LeatherArmorMeta) shooter.getInventory().getChestplate() + .getItemMeta(); + LeatherArmorMeta leggingsMeta = (LeatherArmorMeta) shooter.getInventory().getLeggings() + .getItemMeta(); + LeatherArmorMeta bootsMeta = (LeatherArmorMeta) shooter.getInventory().getBoots().getItemMeta(); + Color green = Color.fromRGB(6717235); + + double r = random.nextDouble(); + r = random.nextDouble(); + if ((r <= 0.5D) && (helmMeta.getColor().equals(green)) && (chestMeta.getColor().equals(green)) + && (leggingsMeta.getColor().equals(green)) && (bootsMeta.getColor().equals(green))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.POISON, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is green, you gave " + damaged.getName() + + " the poison effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is green, you were given the poison effect for 6 seconds..."); + } + Color blue = Color.fromRGB(3361970); + if ((r <= 0.5D) && (helmMeta.getColor().equals(blue)) && (chestMeta.getColor().equals(blue)) + && (leggingsMeta.getColor().equals(blue)) && (bootsMeta.getColor().equals(blue))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is blue, you gave " + damaged.getName() + + " the slowness effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is blue, you were given the slowness effect for 6 seconds..."); + } + Color gray = Color.fromRGB(5000268); + if ((r <= 0.5D) && (helmMeta.getColor().equals(gray)) && (chestMeta.getColor().equals(gray)) + && (leggingsMeta.getColor().equals(gray)) && (bootsMeta.getColor().equals(gray))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is gray, you gave " + damaged.getName() + + " the blindness effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is gray, you were given the blindness effect for 6 seconds..."); + } + Color black = Color.fromRGB(1644825); + if ((r <= 0.2D) && (helmMeta.getColor().equals(black)) && (chestMeta.getColor().equals(black)) + && (leggingsMeta.getColor().equals(black)) && (bootsMeta.getColor().equals(black))) { + damaged.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, 120, 0)); + shooter.sendMessage(ChatColor.GRAY + "Since your armor is black, you gave " + damaged.getName() + + " the wither effect for 6 seconds..."); + damaged.sendMessage(ChatColor.GRAY + "Since " + shooter.getName() + + "'s armor is black, you were given the wither effect for 6 seconds..."); + } + } + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) + public void onArcherSpeedClick(PlayerInteractEvent event) { + Action action = event.getAction(); + if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) && (event.hasItem()) + && (event.getItem().getType() == Material.SUGAR)) { + if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) { + return; + } + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + long timestamp = ArcherClass.archerSpeedCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + long remaining = timestamp == ArcherClass.archerSpeedCooldowns.getNoEntryValue() ? -1L : timestamp - millis; + if (remaining > 0L) { + player.sendMessage(ChatColor.RED + "Cannot use Speed Boost for another " + + DurationFormatUtils.formatDurationWords(remaining, true, true) + "."); + } else { + ItemStack stack = player.getItemInHand(); + if (stack.getAmount() == 1) { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } else { + stack.setAmount(stack.getAmount() - 1); + } + player.sendMessage(ChatColor.GREEN + "Speed 4 activated for 7 seconds."); + + this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_SPEED_EFFECT); + ArcherClass.archerSpeedCooldowns.put(event.getPlayer().getUniqueId(), + System.currentTimeMillis() + ARCHER_SPEED_COOLDOWN_DELAY); + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.HIGH) + public void onArcherJumpClick(PlayerInteractEvent event) { + Action action = event.getAction(); + if (((action == Action.RIGHT_CLICK_AIR) || (action == Action.RIGHT_CLICK_BLOCK)) && (event.hasItem()) + && (event.getItem().getType() == Material.FEATHER)) { + if (this.plugin.getPvpClassManager().getEquippedClass(event.getPlayer()) != this) { + return; + } + Player player = event.getPlayer(); + UUID uuid = player.getUniqueId(); + long timestamp = this.archerJumpCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + long remaining = timestamp == this.archerJumpCooldowns.getNoEntryValue() ? -1L : timestamp - millis; + if (remaining > 0L) { + player.sendMessage(ChatColor.RED + "Cannot use Jump Boost for another " + + DurationFormatUtils.formatDurationWords(remaining, true, true) + "."); + } else { + ItemStack stack = player.getItemInHand(); + if (stack.getAmount() == 1) { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } else { + stack.setAmount(stack.getAmount() - 1); + } + player.sendMessage(ChatColor.GREEN + "Jump Boost 4 activated for 7 seconds."); + + this.plugin.getEffectRestorer().setRestoreEffect(player, ARCHER_JUMP_EFFECT); + this.archerJumpCooldowns.put(event.getPlayer().getUniqueId(), + System.currentTimeMillis() + ARCHER_JUMP_COOLDOWN_DELAY); + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + ItemStack helmet = playerInventory.getHelmet(); + if ((helmet == null) || (helmet.getType() != Material.LEATHER_HELMET)) { + return false; + } + ItemStack chestplate = playerInventory.getChestplate(); + if ((chestplate == null) || (chestplate.getType() != Material.LEATHER_CHESTPLATE)) { + return false; + } + ItemStack leggings = playerInventory.getLeggings(); + if ((leggings == null) || (leggings.getType() != Material.LEATHER_LEGGINGS)) { + return false; + } + ItemStack boots = playerInventory.getBoots(); + return (boots != null) && (boots.getType() == Material.LEATHER_BOOTS); + } +} diff --git a/src/me/bruce/factions/armors/archer/ArcherMark.java b/src/me/bruce/factions/armors/archer/ArcherMark.java new file mode 100644 index 0000000..deb8809 --- /dev/null +++ b/src/me/bruce/factions/armors/archer/ArcherMark.java @@ -0,0 +1,52 @@ +package me.bruce.factions.armors.archer; + +import javax.annotation.Nonnull; +import org.bukkit.scheduler.BukkitTask; + +public class ArcherMark implements Comparable { + public BukkitTask decrementTask; + public int currentLevel; + + public void reset() { + if (this.decrementTask != null) { + this.decrementTask.cancel(); + this.decrementTask = null; + } + this.currentLevel = 0; + } + + public int incrementMark() { + return ++this.currentLevel; + } + + public int decrementMark() { + return --this.currentLevel; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof ArcherMark)) { + return false; + } + ArcherMark that = (ArcherMark) o; + if (this.currentLevel != that.currentLevel) { + return false; + } + return this.decrementTask != null ? this.decrementTask.equals(that.decrementTask) : that.decrementTask == null; + } + + @Override + public int hashCode() { + int result = this.decrementTask != null ? this.decrementTask.hashCode() : 0; + result = 31 * result + this.currentLevel; + return result; + } + + @Override + public int compareTo(@Nonnull ArcherMark archerMark) { + return Integer.compare(this.currentLevel, archerMark.currentLevel); + } +} diff --git a/src/me/bruce/factions/armors/bard/BardClass.java b/src/me/bruce/factions/armors/bard/BardClass.java new file mode 100644 index 0000000..4dcf958 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardClass.java @@ -0,0 +1,364 @@ +package me.bruce.factions.armors.bard; + +import java.util.Collection; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.Event; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.block.Action; +import org.bukkit.event.player.PlayerInteractEvent; +import org.bukkit.event.player.PlayerItemHeldEvent; +import org.bukkit.event.player.PlayerKickEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import LorexMC.us.utils.*; +import LorexMC.us.utils.other.chat.Lang; +import gnu.trove.map.TObjectLongMap; +import gnu.trove.map.hash.TObjectLongHashMap; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.PlayerFaction; + +public class BardClass extends PvpClass implements Listener { + public static final int HELD_EFFECT_DURATION_TICKS = 100; // the amount of time in ticks to apply a Held potion + // effect for faction members + + private static final long BUFF_COOLDOWN_MILLIS = TimeUnit.SECONDS.toMillis(10L); // time in milliseconds for Bard + // buff cooldowns + private static final int TEAMMATE_NEARBY_RADIUS = 25; + private static final long HELD_REAPPLY_TICKS = 20L; + private static final String MARK = BukkitUtils.STRAIGHT_LINE_DEFAULT.substring(0, 8); + private final Map bardDataMap = new HashMap<>(); + private final Map bardEffects = new EnumMap<>(Material.class); + private final LorexHCF plugin; + private final TObjectLongMap msgCooldowns = new TObjectLongHashMap<>(); + + public BardClass(LorexHCF plugin) { + super("Bard", TimeUnit.SECONDS.toMillis(1L)); + this.plugin = plugin; + + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + this.bardEffects.put(Material.WHEAT, new BardEffect(35, new PotionEffect(PotionEffectType.SATURATION, 120, 1), + new PotionEffect(PotionEffectType.SATURATION, 100, 0))); + this.bardEffects.put(Material.SUGAR, new BardEffect(35, new PotionEffect(PotionEffectType.SPEED, 120, 2), + new PotionEffect(PotionEffectType.SPEED, 100, 1))); + this.bardEffects.put(Material.BLAZE_POWDER, + new BardEffect(45, new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 120, 1), + new PotionEffect(PotionEffectType.INCREASE_DAMAGE, 100, 0))); + this.bardEffects.put(Material.IRON_INGOT, + new BardEffect(35, new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 80, 2), + new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 100, 0))); + this.bardEffects.put(Material.GHAST_TEAR, + new BardEffect(30, new PotionEffect(PotionEffectType.REGENERATION, 60, 2), + new PotionEffect(PotionEffectType.REGENERATION, 100, 0))); + this.bardEffects.put(Material.FEATHER, new BardEffect(40, new PotionEffect(PotionEffectType.JUMP, 120, 2), + new PotionEffect(PotionEffectType.JUMP, 100, 0))); + this.bardEffects.put(Material.SPIDER_EYE, + new BardEffect(55, new PotionEffect(PotionEffectType.WITHER, 100, 1), null)); + this.bardEffects.put(Material.MAGMA_CREAM, + new BardEffect(10, new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 900, 0), + new PotionEffect(PotionEffectType.FIRE_RESISTANCE, 120, 0))); + } + + @Override + public boolean onEquip(Player player) { + if (plugin.getTimerManager().getCombatTimer().getRemaining(player) > 0L) { + player.sendMessage(ChatColor.RED + "You cannot equip the " + getName() + " Class whilst PVP Protected."); + return false; + } + + if (!super.onEquip(player)) { + return false; + } + + BardData bardData = new BardData(); + bardDataMap.put(player.getUniqueId(), bardData); + bardData.startEnergyTracking(); + bardData.heldTask = new BukkitRunnable() { + int lastEnergy; + + @Override + public void run() { + // Apply the bard effects here. + ItemStack held = player.getItemInHand(); + if (held != null) { + BardEffect bardEffect = bardEffects.get(held.getType()); + if (bardEffect == null) + return; + + if (bardEffect.heldable.getType() == PotionEffectType.JUMP) { + plugin.getEffectRestorer().setRestoreEffect(player, bardEffect.heldable); + } + + if (!plugin.getFactionManager().getFactionAt(player.getLocation()).isSafezone()) { + // Apply the held effect to faction members. + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction != null) { + Collection nearbyEntities = player.getNearbyEntities(TEAMMATE_NEARBY_RADIUS, + TEAMMATE_NEARBY_RADIUS, TEAMMATE_NEARBY_RADIUS); + nearbyEntities.stream().filter(nearby -> nearby instanceof Player && !player.equals(nearby)) + .forEach(nearby -> { + Player target = (Player) nearby; + if (playerFaction.getMembers().containsKey(target.getUniqueId())) { + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.heldable); + } + }); + } + } + } + + int energy = (int) getEnergy(player); + // the -1 check is for offsets with the energy per millisecond + if (energy != 0 && energy != lastEnergy + && (energy % 10 == 0 || lastEnergy - energy - 1 > 0 || energy == BardData.MAX_ENERGY)) { + lastEnergy = energy; + player.sendMessage(ChatColor.GOLD + name + " Energy is now at " + ChatColor.RED + energy + + ChatColor.GOLD + '.'); + } + } + }.runTaskTimer(plugin, 0L, HELD_REAPPLY_TICKS); + return true; + } + + @Override + public void onUnequip(Player player) { + super.onUnequip(player); + clearBardData(player.getUniqueId()); + } + + private void clearBardData(UUID uuid) { + BardData bardData = bardDataMap.remove(uuid); + if (bardData != null && bardData.getHeldTask() != null) { + ((BukkitTask) bardData.getHeldTask()).cancel(); + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerQuit(PlayerQuitEvent event) { + clearBardData(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerKick(PlayerKickEvent event) { + clearBardData(event.getPlayer().getUniqueId()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onItemHeld(PlayerItemHeldEvent event) { + Player player = event.getPlayer(); + PvpClass equipped = plugin.getPvpClassManager().getEquippedClass(player); + if (equipped == null || !equipped.equals(this)) { + return; + } + + UUID uuid = player.getUniqueId(); + long lastMessage = msgCooldowns.get(uuid); + long millis = System.currentTimeMillis(); + if (lastMessage != msgCooldowns.getNoEntryValue() && lastMessage - millis > 0L) { + return; + } + + ItemStack newStack = player.getInventory().getItem(event.getNewSlot()); + if (newStack != null) { + BardEffect bardEffect = bardEffects.get(newStack.getType()); + if (bardEffect != null) { + msgCooldowns.put(uuid, millis + 1500L); + player.sendMessage(ChatColor.GOLD + BukkitUtils.STRAIGHT_LINE_DEFAULT); + player.sendMessage(ChatColor.GOLD + "Bard Effect: " + ChatColor.GOLD); + player.sendMessage(ChatColor.GOLD + "\u00bb " + ChatColor.YELLOW + "Clickable Effect: " + ChatColor.AQUA + + Lang.fromPotionEffectType(bardEffect.clickable.getType()) + ' ' + + (bardEffect.clickable.getAmplifier() + 1) + ChatColor.GRAY + " (" + + (bardEffect.clickable.getDuration() / 20) + "s)"); + player.sendMessage(ChatColor.GOLD + "\u00bb " + ChatColor.YELLOW + "Energy Cost: " + ChatColor.AQUA + + bardEffect.energyCost); + player.sendMessage(ChatColor.GOLD + BukkitUtils.STRAIGHT_LINE_DEFAULT); + } + } + } + + @EventHandler(ignoreCancelled = false, priority = EventPriority.MONITOR) + public void onPlayerInteract(final PlayerInteractEvent event) { + if (!event.hasItem()) { + return; + } + final Action action = event.getAction(); + if (action == Action.RIGHT_CLICK_AIR || (!event.isCancelled() && action == Action.RIGHT_CLICK_BLOCK)) { + final ItemStack stack = event.getItem(); + final BardEffect bardEffect = this.bardEffects.get(stack.getType()); + if (bardEffect == null || bardEffect.clickable == null) { + return; + } + event.setUseItemInHand(Event.Result.DENY); + final Player player = event.getPlayer(); + final BardData bardData = this.bardDataMap.get(player.getUniqueId()); + if (bardData != null) { + if (!this.canUseBardEffect(player, bardData, bardEffect, true)) { + return; + } + if (stack.getAmount() > 1) { + stack.setAmount(stack.getAmount() - 1); + } else { + player.setItemInHand(new ItemStack(Material.AIR, 1)); + } + if (bardEffect != null + && !this.plugin.getFactionManager().getFactionAt(player.getLocation()).isSafezone()) { + final PlayerFaction playerFaction = this.plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction != null && !bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + for (final Entity nearby : nearbyEntities) { + if (nearby instanceof Player && !player.equals(nearby)) { + final Player target = (Player) nearby; + if (!playerFaction.getMembers().containsKey(target.getUniqueId())) { + continue; + } + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + } + } + } else if (playerFaction != null + && bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + for (final Entity nearby : nearbyEntities) { + if (nearby instanceof Player && !player.equals(nearby)) { + final Player target = (Player) nearby; + if (playerFaction.getMembers().containsKey(target.getUniqueId())) { + continue; + } + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + } + } + } else if (bardEffect.clickable.getType().equals(PotionEffectType.WITHER)) { + final Collection nearbyEntities = player.getNearbyEntities(25.0, 25.0, 25.0); + nearbyEntities.stream().filter(nearby -> nearby instanceof Player && !player.equals(nearby)) + .forEach(nearby -> { + final Player target = (Player) nearby; + plugin.getEffectRestorer().setRestoreEffect(target, bardEffect.clickable); + }); + } + } + plugin.getEffectRestorer().setRestoreEffect(player, bardEffect.clickable); + bardData.setBuffCooldown(BUFF_COOLDOWN_MILLIS); + + double newEnergy = this.setEnergy(player, bardData.getEnergy() - bardEffect.energyCost); + player.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&eYou have just used a &aBard Buff ðat cost you &lsome &eof your Energy.")); + // player.sendMessage(ChatColor.GOLD + "You have just used " + name + " buff " + + // ChatColor.RED + Lang.fromPotionEffectType(bardEffect.clickable.getType()) + ' + // ' + // + (bardEffect.clickable.getAmplifier() + 1) + ChatColor.GOLD + " costing you + // " + ChatColor.BOLD + bardEffect.energyCost + ChatColor.YELLOW + " energy. " + // + "Your energy is now " + ChatColor.GREEN + ((newEnergy * 10.0) / 10.0)/* + // TODO:neeeded? */+ ChatColor.YELLOW + '.'); + } + } + } + + private boolean canUseBardEffect(Player player, BardData bardData, BardEffect bardEffect, boolean sendFeedback) { + String errorFeedback = null; + double currentEnergy = bardData.getEnergy(); + if (bardEffect.energyCost > currentEnergy) { + errorFeedback = ChatColor.RED + "You need at least " + ChatColor.BOLD + bardEffect.energyCost + + ChatColor.RED + " energy to use this Bard buff, whilst you only have " + ChatColor.BOLD + + currentEnergy + ChatColor.RED + '.'; + } + + long remaining = bardData.getRemainingBuffDelay(); + if (remaining > 0L) { + errorFeedback = ChatColor.RED + "You cannot use this bard buff for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.'; + } + + Faction factionAt = plugin.getFactionManager().getFactionAt(player.getLocation()); + if (factionAt.isSafezone()) { + errorFeedback = ChatColor.RED + "You may not use bard buffs in safe-zones."; + } + + if (sendFeedback && errorFeedback != null) { + player.sendMessage(errorFeedback); + } + + return errorFeedback == null; + } + + @Override + public boolean isApplicableFor(Player player) { + ItemStack helmet = player.getInventory().getHelmet(); + if (helmet == null || helmet.getType() != Material.GOLD_HELMET) + return false; + + ItemStack chestplate = player.getInventory().getChestplate(); + if (chestplate == null || chestplate.getType() != Material.GOLD_CHESTPLATE) + return false; + + ItemStack leggings = player.getInventory().getLeggings(); + if (leggings == null || leggings.getType() != Material.GOLD_LEGGINGS) + return false; + + ItemStack boots = player.getInventory().getBoots(); + return !(boots == null || boots.getType() != Material.GOLD_BOOTS); + } + + public long getRemainingBuffDelay(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0L : bardData.getRemainingBuffDelay(); + } + } + + /** + * Gets the energy of a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the energy, or 0 if not tracking this player + */ + public double getEnergy(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0 : bardData.getEnergy(); + } + } + + public long getEnergyMillis(Player player) { + synchronized (bardDataMap) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + return bardData == null ? 0 : bardData.getEnergyMillis(); + } + } + + /** + * Sets the energy of a {@link Player}. + * + * @param player + * the {@link Player} to set for + * @param energy + * the energy amount to set + * @return the new energy amount + */ + public double setEnergy(Player player, double energy) { + BardData bardData = bardDataMap.get(player.getUniqueId()); + if (bardData == null) + return 0.0; + + bardData.setEnergy(energy); + return bardData.getEnergy(); + } + +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/bard/BardData.java b/src/me/bruce/factions/armors/bard/BardData.java new file mode 100644 index 0000000..696e7b5 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardData.java @@ -0,0 +1,68 @@ +package me.bruce.factions.armors.bard; + +import com.google.common.base.Preconditions; +import lombok.Getter; +import org.bukkit.scheduler.BukkitTask; + +/** + * Holds data about a {@link BardClass}. + */ +public class BardData { + + public static final double ENERGY_PER_MILLISECOND = 1.25D; + public static final double MIN_ENERGY = 0.0D; + public static final double MAX_ENERGY = 120.0D; + public static final long MAX_ENERGY_MILLIS = (long) (MAX_ENERGY * 1000L); + + @Getter + private long buffCooldown; + + @Getter + protected BukkitTask heldTask; // TODO: find a way to make private + + private long energyStart; + + public void setBuffCooldown(long millis) { + this.buffCooldown = System.currentTimeMillis() + millis; + } + + public long getRemainingBuffDelay() { + return this.buffCooldown - System.currentTimeMillis(); + } + + /** + * Begins tracking energy. + */ + public void startEnergyTracking() { + this.setEnergy(0); + } + + /** + * Gets the energy in milliseconds. + * + * @return energy in milliseconds + */ + public long getEnergyMillis() { + if (this.energyStart == 0L) { + return 0L; + } + + return Math.min(MAX_ENERGY_MILLIS, + (long) (ENERGY_PER_MILLISECOND * (System.currentTimeMillis() - this.energyStart))); + } + + public double getEnergy() { + // TODO: double check + return Math.round(this.getEnergyMillis() / 100.0) / 10.0; + } + + public void setEnergy(double energy) { + Preconditions.checkArgument(energy >= MIN_ENERGY, "Energy cannot be less than " + MIN_ENERGY); + Preconditions.checkArgument(energy <= MAX_ENERGY, "Energy cannot be more than " + MAX_ENERGY); + this.energyStart = (long) (System.currentTimeMillis() - (1000L * energy)); + } + + public Object getHeldTask() { + return this.heldTask; + } +} diff --git a/src/me/bruce/factions/armors/bard/BardEffect.java b/src/me/bruce/factions/armors/bard/BardEffect.java new file mode 100644 index 0000000..b78a0e8 --- /dev/null +++ b/src/me/bruce/factions/armors/bard/BardEffect.java @@ -0,0 +1,16 @@ +package me.bruce.factions.armors.bard; + +import org.bukkit.potion.PotionEffect; + +public class BardEffect { + + public final int energyCost; + public final PotionEffect clickable; + public final PotionEffect heldable; + + public BardEffect(int energyCost, PotionEffect clickable, PotionEffect heldable) { + this.energyCost = energyCost; + this.clickable = clickable; + this.heldable = heldable; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/bard/EffectRestorer.java b/src/me/bruce/factions/armors/bard/EffectRestorer.java new file mode 100644 index 0000000..8a8b76d --- /dev/null +++ b/src/me/bruce/factions/armors/bard/EffectRestorer.java @@ -0,0 +1,68 @@ +package me.bruce.factions.armors.bard; + +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.event.PvpClassUnequipEvent; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PotionEffectExpireEvent; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import java.util.Collection; +import java.util.UUID; + +public class EffectRestorer implements Listener { + + private final Table restores = HashBasedTable.create(); + + public EffectRestorer(LorexHCF plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPvpClassUnequip(PvpClassUnequipEvent event) { + restores.rowKeySet().remove(event.getPlayer().getUniqueId()); + } + + public void setRestoreEffect(Player player, PotionEffect effect) { + boolean shouldCancel = true; + Collection activeList = player.getActivePotionEffects(); + for (PotionEffect active : activeList) + if (active.getType().equals(effect.getType())) { + + if (effect.getAmplifier() < active.getAmplifier()) { + return; + } + if ((effect.getAmplifier() == active.getAmplifier()) && (effect.getDuration() < active.getDuration())) { + return; + } + restores.put(player.getUniqueId(), active.getType(), active); + shouldCancel = false; + break; + } + player.addPotionEffect(effect, true); + if ((shouldCancel) && (effect.getDuration() > 100) && (effect.getDuration() < PvpClass.DEFAULT_MAX_DURATION)) { + restores.remove(player.getUniqueId(), effect.getType()); + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPotionEffectExpire(PotionEffectExpireEvent event) { + LivingEntity livingEntity = event.getEntity(); + Player player; + PotionEffect previous; + if (((livingEntity instanceof Player)) && ((previous = restores + .remove((player = (Player) livingEntity).getUniqueId(), event.getEffect().getType())) != null)) { + event.setCancelled(true); + player.addPotionEffect(previous, true); + } + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java b/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java new file mode 100644 index 0000000..f2fc329 --- /dev/null +++ b/src/me/bruce/factions/armors/event/PvpClassEquipEvent.java @@ -0,0 +1,40 @@ +package me.bruce.factions.armors.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import me.bruce.factions.armors.PvpClass; + +/** + * Event called when a player equips a {@link PvpClass}. + */ +public class PvpClassEquipEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + + private final PvpClass pvpClass; + + public PvpClassEquipEvent(Player player, PvpClass pvpClass) { + super(player); + this.pvpClass = pvpClass; + } + + /** + * Gets the {@link PvpClass} being unequipped. + * + * @return the unequipped {@link PvpClass} + */ + public PvpClass getPvpClass() { + return pvpClass; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} diff --git a/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java b/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java new file mode 100644 index 0000000..bd12e2b --- /dev/null +++ b/src/me/bruce/factions/armors/event/PvpClassUnequipEvent.java @@ -0,0 +1,40 @@ +package me.bruce.factions.armors.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.HandlerList; +import org.bukkit.event.player.PlayerEvent; + +import me.bruce.factions.armors.PvpClass; + +/** + * Event called when a player unequips a {@link PvpClass}. + */ +public class PvpClassUnequipEvent extends PlayerEvent { + + private static final HandlerList handlers = new HandlerList(); + + private final PvpClass pvpClass; + + public PvpClassUnequipEvent(Player player, PvpClass pvpClass) { + super(player); + this.pvpClass = pvpClass; + } + + /** + * Gets the {@link PvpClass} being unequipped. + * + * @return the unequipped {@link PvpClass} + */ + public PvpClass getPvpClass() { + return pvpClass; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} diff --git a/src/me/bruce/factions/armors/miner/MinerClass.java b/src/me/bruce/factions/armors/miner/MinerClass.java new file mode 100644 index 0000000..7abe0b9 --- /dev/null +++ b/src/me/bruce/factions/armors/miner/MinerClass.java @@ -0,0 +1,141 @@ +package me.bruce.factions.armors.miner; + +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerTeleportEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.armors.event.PvpClassEquipEvent; + +import java.util.concurrent.TimeUnit; + +/** + * Represents a {@link PvpClass} used to enhance mining quality. + */ +public class MinerClass extends PvpClass implements Listener { + + // The minimum height level to obtain the Invisibility effect. + private static final int INVISIBILITY_HEIGHT_LEVEL = 30; + private static final PotionEffect HEIGHT_INVISIBILITY = new PotionEffect(PotionEffectType.INVISIBILITY, + Integer.MAX_VALUE, 0); + + private final LorexHCF plugin; + + public MinerClass(LorexHCF plugin) { + super("Miner", TimeUnit.SECONDS.toMillis(10L)); + + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.FAST_DIGGING, Integer.MAX_VALUE, 1)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 0)); + } + + private void removeInvisibilitySafely(Player player) { + for (PotionEffect active : player.getActivePotionEffects()) { + if (active.getType().equals(PotionEffectType.INVISIBILITY) && active.getDuration() > DEFAULT_MAX_DURATION) { + player.sendMessage(ChatColor.RED + getName() + ChatColor.GRAY + " invisibility removed."); + player.removePotionEffect(active.getType()); + break; + } + } + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerDamage(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + if (entity instanceof Player && BukkitUtils.getFinalAttacker(event, false) != null) { + Player player = (Player) entity; + if (plugin.getPvpClassManager().hasClassEquipped(player, this)) { + removeInvisibilitySafely(player); + } + } + } + + @Override + public void onUnequip(Player player) { + super.onUnequip(player); + removeInvisibilitySafely(player); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerMove(PlayerMoveEvent event) { + conformMinerInvisibility(event.getPlayer(), event.getFrom(), event.getTo()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onPlayerTeleport(PlayerTeleportEvent event) { + conformMinerInvisibility(event.getPlayer(), event.getFrom(), event.getTo()); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + public void onClassEquip(PvpClassEquipEvent event) { + Player player = event.getPlayer(); + if (event.getPvpClass() == this && player.getLocation().getBlockY() <= INVISIBILITY_HEIGHT_LEVEL) { + player.addPotionEffect(HEIGHT_INVISIBILITY, true); + player.sendMessage(ChatColor.AQUA + getName() + ChatColor.GRAY + " invisibility added."); + } + } + + /** + * Applies the {@link MinerClass} invisibility {@link PotionEffect} depending on + * the {@link Player}s {@link Location}. + * + * @param player + * the {@link Player} to apply for + * @param from + * the from {@link Location} + * @param to + * the to {@link Location} + */ + private void conformMinerInvisibility(Player player, Location from, Location to) { + int fromY = from.getBlockY(); + int toY = to.getBlockY(); + if (fromY != toY && plugin.getPvpClassManager().hasClassEquipped(player, this)) { + boolean isInvisible = player.hasPotionEffect(PotionEffectType.INVISIBILITY); + if (toY > INVISIBILITY_HEIGHT_LEVEL) { + if (fromY <= INVISIBILITY_HEIGHT_LEVEL && isInvisible) { + removeInvisibilitySafely(player); + } + } else { + if (!isInvisible) { + player.addPotionEffect(HEIGHT_INVISIBILITY, true); + player.sendMessage(ChatColor.AQUA + getName() + ChatColor.GRAY + " invisibility added."); + } + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + + ItemStack helmet = playerInventory.getHelmet(); + if (helmet == null || helmet.getType() != Material.IRON_HELMET) + return false; + + ItemStack chestplate = playerInventory.getChestplate(); + if (chestplate == null || chestplate.getType() != Material.IRON_CHESTPLATE) + return false; + + ItemStack leggings = playerInventory.getLeggings(); + if (leggings == null || leggings.getType() != Material.IRON_LEGGINGS) + return false; + + ItemStack boots = playerInventory.getBoots(); + return !(boots == null || boots.getType() != Material.IRON_BOOTS); + } +} diff --git a/src/me/bruce/factions/armors/rogue/RogueClass.java b/src/me/bruce/factions/armors/rogue/RogueClass.java new file mode 100644 index 0000000..21600e0 --- /dev/null +++ b/src/me/bruce/factions/armors/rogue/RogueClass.java @@ -0,0 +1,84 @@ +package me.bruce.factions.armors.rogue; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.Sound; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.armors.PvpClass; +import me.bruce.factions.ymls.SettingsYML; + +import java.util.concurrent.TimeUnit; + +public class RogueClass extends PvpClass implements Listener { + + private final LorexHCF plugin; + + public RogueClass(LorexHCF plugin) { + super("Rogue", TimeUnit.SECONDS.toMillis(15L)); + + this.plugin = plugin; + this.passiveEffects.add(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.REGENERATION, Integer.MAX_VALUE, 0)); + this.passiveEffects.add(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 2)); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamageByEntity(EntityDamageByEntityEvent event) { + Entity entity = event.getEntity(); + Entity damager = event.getDamager(); + if (entity instanceof Player && damager instanceof Player) { + Player attacker = (Player) damager; + if (plugin.getPvpClassManager().getEquippedClass(attacker) == this) { + ItemStack stack = attacker.getItemInHand(); + if (stack != null && stack.getType() == Material.GOLD_SWORD && stack.getEnchantments().isEmpty()) { + Player player = (Player) entity; + player.sendMessage( + SettingsYML.ENEMY_COLOUR + attacker.getName() + ChatColor.YELLOW + " has backstabbed you."); + player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); + + attacker.sendMessage(ChatColor.YELLOW + "You have backstabbed " + SettingsYML.ENEMY_COLOUR + + player.getName() + ChatColor.YELLOW + '.'); + attacker.setItemInHand(new ItemStack(Material.AIR, 1)); + player.setHealth(12); + attacker.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); + + event.setDamage(3.0); + } + } + } + } + + @Override + public boolean isApplicableFor(Player player) { + PlayerInventory playerInventory = player.getInventory(); + + ItemStack helmet = playerInventory.getHelmet(); + if (helmet == null || helmet.getType() != Material.CHAINMAIL_HELMET) { + return false; + } + + ItemStack chestplate = playerInventory.getChestplate(); + if (chestplate == null || chestplate.getType() != Material.CHAINMAIL_CHESTPLATE) { + return false; + } + + ItemStack leggings = playerInventory.getLeggings(); + if (leggings == null || leggings.getType() != Material.CHAINMAIL_LEGGINGS) { + return false; + } + + ItemStack boots = playerInventory.getBoots(); + return !(boots == null || boots.getType() != Material.CHAINMAIL_BOOTS); + } +} diff --git a/src/me/bruce/factions/commands/.DS_Store b/src/me/bruce/factions/commands/.DS_Store new file mode 100644 index 0000000..9b925a9 Binary files /dev/null and b/src/me/bruce/factions/commands/.DS_Store differ diff --git a/src/me/bruce/factions/commands/BallerRevive.java b/src/me/bruce/factions/commands/BallerRevive.java new file mode 100644 index 0000000..64fdccd --- /dev/null +++ b/src/me/bruce/factions/commands/BallerRevive.java @@ -0,0 +1,63 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class BallerRevive implements CommandExecutor { + + private final LorexHCF plugin; + + public BallerRevive(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lBaller Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} diff --git a/src/me/bruce/factions/commands/BanCommand.java b/src/me/bruce/factions/commands/BanCommand.java new file mode 100644 index 0000000..444a9c9 --- /dev/null +++ b/src/me/bruce/factions/commands/BanCommand.java @@ -0,0 +1,34 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class BanCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + return true; + } + if(args.length == 0) { + sender.sendMessage("usage /ban "); + return true; + } + Player target = Bukkit.getPlayer(args[0]); + Player p = (Player) sender; + if(target == null) { + sender.sendMessage("ERROR"); + return true; + } + target.kickPlayer(ChatColor.RED + "you have beened banned"); + target.setBanned(true); + return true; + } + + + +} diff --git a/src/me/bruce/factions/commands/BroadCastCommand.java b/src/me/bruce/factions/commands/BroadCastCommand.java new file mode 100644 index 0000000..2d13260 --- /dev/null +++ b/src/me/bruce/factions/commands/BroadCastCommand.java @@ -0,0 +1,35 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class BroadCastCommand implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { + if (cmd.getName().equalsIgnoreCase("broadcast")) { + String r = ""; + if (sender.hasPermission("command.broadcast")) { + if (args.length > 0) { + for (int i = 0; i < args.length; ++i) { + r = String.valueOf(r) + args[i] + " "; + } + r = r.replace("&", "§"); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&8[&4Alert&8]&f " + r)); + } + else { + sender.sendMessage(ChatColor.RED + "Usage: /broadcast "); + } + } + else { + sender.sendMessage("§cYou lack the sufficient permissions to execute this command."); + } + } + return true; + } +} + + + diff --git a/src/me/bruce/factions/commands/Buy.java b/src/me/bruce/factions/commands/Buy.java new file mode 100644 index 0000000..d47af4f --- /dev/null +++ b/src/me/bruce/factions/commands/Buy.java @@ -0,0 +1,22 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class Buy implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use this command in console"); + return true; + } + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + " www.zorex.us"); + return true; + } +} + + diff --git a/src/me/bruce/factions/commands/CobbleCommand.java b/src/me/bruce/factions/commands/CobbleCommand.java new file mode 100644 index 0000000..52d475b --- /dev/null +++ b/src/me/bruce/factions/commands/CobbleCommand.java @@ -0,0 +1,56 @@ +package me.bruce.factions.commands; + +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerPickupItemEvent; +import org.bukkit.event.player.PlayerQuitEvent; + +import com.google.common.collect.Sets; + +public class CobbleCommand implements Listener, CommandExecutor { + + public static Set disabled = Sets.newHashSet(); + + @Override + public boolean onCommand(CommandSender sender, Command arg1, String arg2, String[] args) { + + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can focus."); + return true; + } + Player player = (Player) sender; + if (disabled.contains(player)) { + disabled.remove(player); + player.sendMessage(ChatColor.GRAY + " § " + ChatColor.YELLOW + "You have " + ChatColor.RED + "disabled " + + ChatColor.YELLOW + "Cobblestone and Stone pickup!"); + } else { + disabled.add(player); + player.sendMessage(ChatColor.GRAY + " § " + ChatColor.YELLOW + "You have " + ChatColor.GREEN + "enabled " + + ChatColor.YELLOW + "Cobblestone and Stone pickup!"); + } + return true; + } + + @EventHandler + public void onPlayerPickup(PlayerQuitEvent event) { + disabled.remove(event.getPlayer()); + } + + @EventHandler + public void onPlayerPickup(PlayerPickupItemEvent event) { + Material type = event.getItem().getItemStack().getType(); + if (type == Material.STONE || type == Material.COBBLESTONE) { + if (disabled.contains(event.getPlayer())) { + event.setCancelled(true); + } + } + } +} diff --git a/src/me/bruce/factions/commands/CoordsCommand.java b/src/me/bruce/factions/commands/CoordsCommand.java new file mode 100644 index 0000000..163209b --- /dev/null +++ b/src/me/bruce/factions/commands/CoordsCommand.java @@ -0,0 +1,33 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +public class CoordsCommand implements CommandExecutor, TabCompleter { + + @Override + public boolean onCommand(CommandSender p, Command command, String label, String[] args) { + if (!(p instanceof Player)) { + p.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + p.sendMessage(""); + p.sendMessage("§7§m---------------------------------------------------"); + p.sendMessage("§7§m---------------------------------------------------"); + p.sendMessage(""); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/Discord.java b/src/me/bruce/factions/commands/Discord.java new file mode 100644 index 0000000..72a1add --- /dev/null +++ b/src/me/bruce/factions/commands/Discord.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Discord { + +} diff --git a/src/me/bruce/factions/commands/FRCOMMAND.java b/src/me/bruce/factions/commands/FRCOMMAND.java new file mode 100644 index 0000000..b5302ac --- /dev/null +++ b/src/me/bruce/factions/commands/FRCOMMAND.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class FRCOMMAND implements Listener, CommandExecutor{ + public static ArrayList fr = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!fr.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7fire resistance.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, Integer.MAX_VALUE, 0)); + fr.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisbaled &7fire resistance.")); + p.removePotionEffect(PotionEffectType.FIRE_RESISTANCE); + fr.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/FixCommand.java b/src/me/bruce/factions/commands/FixCommand.java new file mode 100644 index 0000000..52703f9 --- /dev/null +++ b/src/me/bruce/factions/commands/FixCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.PlayerInventory; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; + +public class FixCommand implements CommandExecutor{ + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + Player target; + if (args.length > 0) { + target = BukkitUtils.playerWithNameOrUUID(args[0]); + } + else { + if (!(sender instanceof Player)) { + sender.sendMessage("Cannot use in console"); + return true; + } + target = (Player)sender; + } + if (target == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + final Set toRepair = new HashSet(); + if (args.length >= 1 && args[1].equalsIgnoreCase("all")) { + final PlayerInventory targetInventory = target.getInventory(); + toRepair.addAll(Arrays.asList(targetInventory.getContents())); + toRepair.addAll(Arrays.asList(targetInventory.getArmorContents())); + } + else { + toRepair.add(target.getItemInHand()); + } + for (final ItemStack stack : toRepair) { + if (stack != null && stack.getType() != Material.AIR) { + stack.setDurability((short)0); + } + } + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + "Repaired " + ((toRepair.size() > 1) ? "all" : "item in hand") + " of " + target.getName() + '.'); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/Forums.java b/src/me/bruce/factions/commands/Forums.java new file mode 100644 index 0000000..47e8cef --- /dev/null +++ b/src/me/bruce/factions/commands/Forums.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Forums { + +} diff --git a/src/me/bruce/factions/commands/FreezeCommand.java b/src/me/bruce/factions/commands/FreezeCommand.java new file mode 100644 index 0000000..efde9ba --- /dev/null +++ b/src/me/bruce/factions/commands/FreezeCommand.java @@ -0,0 +1,229 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.bukkit.event.player.PlayerCommandPreprocessEvent; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.scheduler.BukkitTask; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.other.chat.ClickAction; +import LorexMC.us.utils.other.chat.Text; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.event.PlayerFreezeEvent; +import net.minecraft.util.gnu.trove.map.TObjectLongMap; +import net.minecraft.util.gnu.trove.map.hash.TObjectLongHashMap; +import net.minecraft.util.org.apache.commons.lang3.StringUtils; +import net.minecraft.util.org.apache.commons.lang3.time.DurationFormatUtils; + +public class FreezeCommand implements CommandExecutor, Listener { + private static final String FREEZE_BYPASS = "command.freeze.bypass"; + public static TObjectLongMap frozenPlayers; + public static HashMap frozenReasons; + private long defaultFreezeDuration; + private long serverFrozenMillis; + public static HashSet frozen; + + static { + FreezeCommand.frozenPlayers = new TObjectLongHashMap(); + FreezeCommand.frozenReasons = new HashMap(); + } + + public FreezeCommand(final LorexHCF plugin) { + FreezeCommand.frozen = new HashSet(); + this.defaultFreezeDuration = TimeUnit.MINUTES.toMillis(60L); + Bukkit.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + "Usage: " + "/freeze "); + return true; + } + final String reason = null; + Long freezeTicks = this.defaultFreezeDuration; + final long millis = System.currentTimeMillis(); + if (args[0].equalsIgnoreCase("all") && sender.hasPermission(String.valueOf(command.getPermission()) + ".all")) { + final long oldTicks = this.getRemainingServerFrozenMillis(); + if (oldTicks > 0L) { + freezeTicks = 0L; + } + this.serverFrozenMillis = millis + this.defaultFreezeDuration; + Bukkit.getServer() + .broadcastMessage(ChatColor.YELLOW + "The server is " + ((freezeTicks > 0L) + ? ("now frozen for " + DurationFormatUtils.formatDurationWords(freezeTicks, true, true)) + : "no longer frozen") + ((reason == null) ? "" : (" with reason " + reason)) + '.'); + return true; + } + final Player target = Bukkit.getServer().getPlayer(args[0]); + if (target == null) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final boolean shouldFreeze = this.getRemainingPlayerFrozenMillis(targetUUID) > 0L; + final PlayerFreezeEvent playerFreezeEvent = new PlayerFreezeEvent(target, shouldFreeze); + Bukkit.getServer().getPluginManager().callEvent(playerFreezeEvent); + if (playerFreezeEvent.isCancelled()) { + sender.sendMessage(ChatColor.RED + "Unable to freeze " + target.getName() + '.'); + return false; + } + if (shouldFreeze) { + FreezeCommand.frozen.remove(target.getName()); + FreezeCommand.frozenPlayers.remove(targetUUID); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been un-frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + target.sendMessage(ChatColor.RED + "You have been un-frozen."); + target.removePotionEffect(PotionEffectType.BLINDNESS); + FreezeCommand.frozenReasons.remove(target); + } else if (args.length == 1) { + FreezeCommand.frozen.add(target.getName()); + FreezeCommand.frozenPlayers.put(targetUUID, millis + freezeTicks); + final String timeString = DurationFormatUtils.formatDurationWords(freezeTicks, true, true); + this.Message(target.getName()); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + } else { + FreezeCommand.frozen.add(target.getName()); + FreezeCommand.frozenPlayers.put(targetUUID, millis + freezeTicks); + final String timeString = DurationFormatUtils.formatDurationWords(freezeTicks, true, true); + this.Message(target.getName()); + sender.sendMessage(ChatColor.GOLD + "âš  " + ChatColor.LIGHT_PURPLE + target.getName() + ChatColor.YELLOW + " has been frozen by " + ChatColor.LIGHT_PURPLE + sender.getName()); + final String reason2 = StringUtils.join(args, ' ', 1, args.length); + FreezeCommand.frozenReasons.put(target, reason2); + } + return true; + } + + private void Message(final String name) { + final HashMap timer = new HashMap(); + final Player p = Bukkit.getPlayer(name); + final BukkitTask task = new BukkitRunnable() { + @Override + public void run() { + if (FreezeCommand.frozen.contains(name)) { + p.sendMessage(" "); + p.sendMessage("§f\u2588\u2588\u2588\u2588§c\u2588§f\u2588\u2588\u2588\u2588"); + p.sendMessage("§f\u2588\u2588\u2588§c\u2588§6\u2588§c\u2588§f\u2588\u2588\u2588"); + p.sendMessage( + "§f\u2588\u2588§c\u2588§6\u2588§0\u2588§6\u2588§c\u2588§f\u2588\u2588 §4§lDo NOT log out!"); + p.sendMessage( + "§f\u2588\u2588§c\u2588§6\u2588§0\u2588§6\u2588§c\u2588§f\u2588\u2588 §cIf you do, you will be banned!"); + p.sendMessage( + "§f\u2588§c\u2588§6\u2588\u2588§0\u2588§6\u2588\u2588§c\u2588§f\u2588 §ePlease download §eTeamspeak §eand connect to:"); + p.sendMessage( + "§f\u2588§c\u2588§6\u2588\u2588\u2588\u2588\u2588§c\u2588§f\u2588 " + "§ets.Zorex.us"); + p.sendMessage("§c\u2588§6\u2588\u2588\u2588§0\u2588§6\u2588\u2588\u2588§c\u2588"); + p.sendMessage("§c\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588"); + p.sendMessage(" "); + } else { + this.cancel(); + } + } + }.runTaskTimerAsynchronously(LorexHCF.getInstance(), 0L, 200L); + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + return (args.length == 1) ? null : Collections.emptyList(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onEntityDamageByEntity(final EntityDamageByEntityEvent event) { + final Entity entity = event.getEntity(); + if (entity instanceof Player) { + final Player attacker = BukkitUtils.getFinalAttacker(event, false); + if (attacker == null) { + return; + } + final Player player = (Player) entity; + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(player.getUniqueId()) > 0L) + && !player.hasPermission("command.freeze.bypass")) { + attacker.sendMessage(ChatColor.RED + player.getName() + " is currently frozen, you may not attack."); + event.setCancelled(true); + return; + } + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(attacker.getUniqueId()) > 0L) + && !attacker.hasPermission("command.freeze.bypass")) { + event.setCancelled(true); + attacker.sendMessage(ChatColor.RED + "You may not attack players whilst frozen."); + } + } + } + + + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onPlayerMove(final PlayerMoveEvent event) { + final Location from = event.getFrom(); + final Location to = event.getTo(); + if (from.getBlockX() == to.getBlockX() && from.getBlockZ() == to.getBlockZ()) { + return; + } + final Player player = event.getPlayer(); + if ((this.getRemainingServerFrozenMillis() > 0L + || this.getRemainingPlayerFrozenMillis(player.getUniqueId()) > 0L) + && !player.hasPermission("command.freeze.bypass")) { + event.setTo(event.getFrom()); + } + } + + @EventHandler + public void onPlayerQuit(final PlayerQuitEvent e) { + if (FreezeCommand.frozen.contains(e.getPlayer().getUniqueId())) { + for (final Player online : Bukkit.getOnlinePlayers()) { + if (online.hasPermission("command.freeze")) { + online.sendMessage(""); + online.sendMessage(""); + online.sendMessage(""); + new Text(ChatColor.WHITE + e.getPlayer().getName() + " has " + ChatColor.DARK_RED + "QUIT" + + ChatColor.WHITE + " while frozen. " + ChatColor.GRAY + ChatColor.ITALIC + + "(Click here to ban)") + .setHoverText(ChatColor.WHITE + "Click here to permanently ban" + ChatColor.GRAY + + e.getPlayer().getName()) + .setClick(ClickAction.RUN_COMMAND, + "/ban" + e.getPlayer().getName() + "Refusal to SS | Logout") + .setColor(ChatColor.GRAY).send(online); + online.sendMessage(""); + online.sendMessage(""); + online.sendMessage(""); + } + } + } + } + + public long getRemainingServerFrozenMillis() { + return this.serverFrozenMillis - System.currentTimeMillis(); + } + + public long getRemainingPlayerFrozenMillis(final UUID uuid) { + final long remaining = FreezeCommand.frozenPlayers.get(uuid); + if (remaining == FreezeCommand.frozenPlayers.getNoEntryValue()) { + return 0L; + } + return remaining - System.currentTimeMillis(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/GiveCrowbarCommand.java b/src/me/bruce/factions/commands/GiveCrowbarCommand.java new file mode 100644 index 0000000..a6ef023 --- /dev/null +++ b/src/me/bruce/factions/commands/GiveCrowbarCommand.java @@ -0,0 +1,37 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; + +import me.bruce.factions.listener.Crowbar; + +public class GiveCrowbarCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player p = (Player) sender; + if (cmd.getName().equalsIgnoreCase("crowgive")) { + if (args.length == 0) { + p.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + Player target = Bukkit.getServer().getPlayer(args[0]); + if (target == null) { + p.sendMessage(ChatColor.RED + "That player is not online!"); + return true; + } + + ItemStack stack = new Crowbar().getItemIfPresent(); + target.getInventory().addItem(new ItemStack[] { stack }); + target.sendMessage(ChatColor.GREEN + "You were given a crowbar from " + sender.getName()); + p.sendMessage(ChatColor.GREEN + "You have given " + target.getName() + " a crowbar"); + return true; + } + return false; + } +} diff --git a/src/me/bruce/factions/commands/GlowstoneMountain.java b/src/me/bruce/factions/commands/GlowstoneMountain.java new file mode 100644 index 0000000..1687830 --- /dev/null +++ b/src/me/bruce/factions/commands/GlowstoneMountain.java @@ -0,0 +1,28 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.*; + +import me.bruce.factions.*; + +import org.bukkit.*; + +public class GlowstoneMountain implements CommandExecutor { + private LorexHCF hcf; + + public GlowstoneMountain(final LorexHCF hcf) { + this.hcf = hcf; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (!sender.hasPermission("command.glowstonemountain")) { + sender.sendMessage(ChatColor.RED + "You don not have permission for this command."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.YELLOW + "You have reset Glowstone Mountain!"); + // this.hcf.resetGlowstoneMountain(); + } + return true; + } +} diff --git a/src/me/bruce/factions/commands/GoppleCommand.java b/src/me/bruce/factions/commands/GoppleCommand.java new file mode 100644 index 0000000..30be702 --- /dev/null +++ b/src/me/bruce/factions/commands/GoppleCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.PlayerTimer; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to check remaining Notch Apple cooldown time for {@link Player}. + */ +public class GoppleCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public GoppleCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + + PlayerTimer timer = plugin.getTimerManager().getGappleTimer(); + long remaining = timer.getRemaining(player); + + if (remaining <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + timer.getDisplayName() + ChatColor.RED + + " timer is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.YELLOW + "Your " + timer.getDisplayName() + ChatColor.YELLOW + + " timer is active for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.YELLOW + '.'); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/HelpCommand.java b/src/me/bruce/factions/commands/HelpCommand.java new file mode 100644 index 0000000..1d4472c --- /dev/null +++ b/src/me/bruce/factions/commands/HelpCommand.java @@ -0,0 +1,76 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.ymls.SettingsYML; + +import java.util.Collections; +import java.util.List; + +/** + * + */ +public class HelpCommand implements CommandExecutor, TabCompleter { + + @Override + public boolean onCommand(CommandSender p, Command command, String label, String[] args) { + if (!(p instanceof Player)) { + p.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if(SettingsYML.KIT_MAP == true) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &C(KitMap)")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LInformation")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWorld Border &71500 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWarzone Radius &7150 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eKits &7Diamond, Bard, Archer, Builder")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eEnd Exit &c( 150 ) South Road")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LUseful Commands")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/helpop &7Request staff assistance")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/coords &7View KOTH, Conquest and Mountain locations")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/mapkit &7Get the kit of the map")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LLinks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWebsite &7www.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eTeamspeak &7ts.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eStore &7store.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lTribes &C(Map 1)")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LInformation")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWorld Border &73000 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWarzone Radius &7800 Blocks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eKits &7Diamond, Bard, Archer, Builder")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eEnd Exit &c( 150 ) South Road")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LUseful Commands")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/helpop &7Request staff assistance")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/coords &7View KOTH, Conquest and Mountain locations")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &e/mapkit &7Get the kit of the map")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&LLinks")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eWebsite &7www.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eTeamspeak &7ts.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6* &eStore &7store.zorex.us")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8&m-----------------------------------------------------")); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/HubCommand.java b/src/me/bruce/factions/commands/HubCommand.java new file mode 100644 index 0000000..5592964 --- /dev/null +++ b/src/me/bruce/factions/commands/HubCommand.java @@ -0,0 +1,57 @@ +package me.bruce.factions.commands; + +import java.io.DataOutputStream; +import java.io.IOException; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import net.minecraft.util.org.apache.commons.io.output.ByteArrayOutputStream; + +public class HubCommand implements CommandExecutor { + + private final LorexHCF plugin; + + public HubCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public static void teleport(Player pl, String input) { + ByteArrayOutputStream b = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(b); + try { + out.writeUTF("Connect"); + out.writeUTF(input); + } catch (IOException localIOException) { + } + pl.sendPluginMessage(LorexHCF.getInstance(), "BungeeCord", b.toByteArray()); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "We are sending you to The Hub."); + teleport(p, "hub"); + Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(LorexHCF.getInstance(), new Runnable() { + @Override + public void run() { + if (p.isOnline()) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&cWe couldn't connect you to any of the Hubs, please try again later.")); + } + } + }, 20 * 5); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/InveeSeeCommand.java b/src/me/bruce/factions/commands/InveeSeeCommand.java new file mode 100644 index 0000000..043fedc --- /dev/null +++ b/src/me/bruce/factions/commands/InveeSeeCommand.java @@ -0,0 +1,122 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.InventoryHolder; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import me.bruce.factions.LorexHCF; + +public class InveeSeeCommand implements Listener,CommandExecutor { + private InventoryType[] types; + private Map inventories; + + public void InvSeeCommand(final LorexHCF plugin) { + this.types = new InventoryType[] { InventoryType.BREWING, InventoryType.CHEST, InventoryType.DISPENSER, InventoryType.ENCHANTING, InventoryType.FURNACE, InventoryType.HOPPER, InventoryType.PLAYER, InventoryType.WORKBENCH }; + this.inventories = new EnumMap(InventoryType.class); + Bukkit.getPluginManager().registerEvents((Listener)this, (Plugin)plugin); + } + + public boolean isPlayerOnlyCommand() { + return true; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /invsee "); + return true; + } + final Player target = BukkitUtils.playerWithNameOrUUID(args[0]); + if (target == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + sender.sendMessage(ChatColor.GRAY + "This players inventory contains: "); + ItemStack[] arrayOfItemStack; + for (int j = (arrayOfItemStack = target.getInventory().getContents()).length, i = 0; i < j; ++i) { + final ItemStack items = arrayOfItemStack[i]; + if (items != null) { + sender.sendMessage(ChatColor.AQUA + items.getType().toString().replace("_", "").toLowerCase() + ": " + items.getAmount()); + } + } + return true; + } + else { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /invsee "); + return true; + } + final Player player = (Player)sender; + Inventory inventory = null; + final InventoryType[] types = this.types; + final int length = types.length; + int k = 0; + while (k < length) { + final InventoryType type = types[k]; + if (type.name().equalsIgnoreCase(args[0])) { + final Inventory inventoryRevert; + inventory = inventories.putIfAbsent(type, inventoryRevert = Bukkit.createInventory((InventoryHolder)player, type)); + if (inventory != null) { + break; + } + inventory = inventoryRevert; + break; + } + else { + ++k; + } + } + if (inventory == null) { + final Player target2 = BukkitUtils.playerWithNameOrUUID(args[0]); + if (sender.equals(target2)) { + sender.sendMessage(ChatColor.RED + "You cannot check the inventory of yourself."); + return true; + } + if (target2 == null) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[0])); + return true; + } + inventory = (Inventory)target2.getInventory(); + } + player.openInventory(inventory); + return true; + } + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, final String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + final InventoryType[] values = InventoryType.values(); + final List results = new ArrayList(values.length); + final Player senderPlayer = (Player)sender; + Player[] arrayOfPlayer; + for (int j = (arrayOfPlayer = Bukkit.getOnlinePlayers()).length, i = 0; i < j; ++i) { + final Player target = arrayOfPlayer[i]; + if (senderPlayer == null || senderPlayer.canSee(target)) { + results.add(target.getName()); + } + } + return BukkitUtils.getCompletions(args, results); + } + } + + + diff --git a/src/me/bruce/factions/commands/LFFCommand.java b/src/me/bruce/factions/commands/LFFCommand.java new file mode 100644 index 0000000..4057cf2 --- /dev/null +++ b/src/me/bruce/factions/commands/LFFCommand.java @@ -0,0 +1,50 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.internal.com.bruce.base.BasePlugin; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.listener.Cooldowns; + +public class LFFCommand implements CommandExecutor { + + private final LorexHCF plugin; + + public LFFCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player p = (Player) sender; + final PlayerFaction faction = LorexHCF.getInstance().getFactionManager().getPlayerFaction(p); + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This is a player only command"); + return true; + } + if (Cooldowns.isOnCooldown("lff_cooldown", p)) { + p.sendMessage("§cYou Still have a cooldown"); + return true; + } + if(faction != null) { + sender.sendMessage("§cYou are already in a faction"); + return true; + } + if (sender instanceof Player) { + final Player player = (Player) sender; + Bukkit.broadcastMessage(ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH.toString() + "--------------------------------"); + Bukkit.broadcastMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + sender.getName() + ChatColor.GRAY + " is looking for a faction!"); + Bukkit.broadcastMessage(ChatColor.DARK_GRAY + ChatColor.STRIKETHROUGH.toString() + "--------------------------------"); + Cooldowns.addCooldown("lff_cooldown", p, 900); + } + return true; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/LogoutCommand.java b/src/me/bruce/factions/commands/LogoutCommand.java new file mode 100644 index 0000000..f1e6fa8 --- /dev/null +++ b/src/me/bruce/factions/commands/LogoutCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.type.LogoutTimer; + +import java.util.Collections; +import java.util.List; + +public class LogoutCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public LogoutCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + LogoutTimer logoutTimer = plugin.getTimerManager().getLogoutTimer(); + + if (!logoutTimer.setCooldown(player, player.getUniqueId())) { + sender.sendMessage(ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + + " timer is already active."); + return true; + } + + sender.sendMessage( + ChatColor.YELLOW + "Your " + logoutTimer.getDisplayName() + ChatColor.YELLOW + " timer has started."); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/MapKitCommand.java b/src/me/bruce/factions/commands/MapKitCommand.java new file mode 100644 index 0000000..327baf1 --- /dev/null +++ b/src/me/bruce/factions/commands/MapKitCommand.java @@ -0,0 +1,82 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.WordUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.enchantments.Enchantment; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.potion.Potion; +import org.bukkit.potion.PotionType; + +import LorexMC.us.utils.InventoryUtils; +import LorexMC.us.utils.ItemBuilder; +import LorexMC.us.utils.other.chat.Lang; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.ymls.SettingsYML; + +public class MapKitCommand implements CommandExecutor, TabCompleter, Listener { + private final Set tracking = new HashSet(); + + public MapKitCommand(LorexHCF plugin) { + plugin.getServer().getPluginManager().registerEvents(this, plugin); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + List items = new ArrayList(); + for (Map.Entry entry : SettingsYML.ENCHANTMENT_LIMITS.entrySet()) { + items.add(new ItemBuilder(Material.ENCHANTED_BOOK).displayName( + ChatColor.YELLOW + Lang.fromEnchantment(entry.getKey()) + ": " + ChatColor.GREEN + entry.getValue()) + .build()); + } + for (Map.Entry entry : SettingsYML.POTION_LIMITS.entrySet()) { + items.add(new ItemBuilder(new Potion(entry.getKey()).toItemStack(1)) + .displayName(ChatColor.YELLOW + WordUtils.capitalizeFully(entry.getKey().name().replace('_', ' ')) + + ": " + ChatColor.GREEN + entry.getValue()) + .build()); + } + Player player = (Player) sender; + Inventory inventory = Bukkit.createInventory(player, InventoryUtils.getSafestInventorySize(items.size()), + "Zorex MapKit"); + this.tracking.add(inventory); + for (ItemStack item : items) { + inventory.addItem(new ItemStack[] { item }); + } + player.openInventory(inventory); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } + + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) + public void onInventoryClick(InventoryClickEvent event) { + if (this.tracking.contains(event.getInventory())) { + event.setCancelled(true); + } + } +} diff --git a/src/me/bruce/factions/commands/MedicCommand.java b/src/me/bruce/factions/commands/MedicCommand.java new file mode 100644 index 0000000..8b1379e --- /dev/null +++ b/src/me/bruce/factions/commands/MedicCommand.java @@ -0,0 +1,95 @@ +package me.bruce.factions.commands; + +import java.util.*; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.listener.Cooldowns; + +public class MedicCommand implements CommandExecutor { + private final LorexHCF plugin; + + public MedicCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + public String getUsage(final String label) { + return String.valueOf('/') + label + ' ' + "revive "; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + final Player p = (Player) sender; + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + return true; + } + if (Cooldowns.isOnCooldown("medic_cooldown", p)) { + p.sendMessage(ChatColor.RED + "You still have a " + ChatColor.DARK_GRAY + ChatColor.BOLD + "Amethyst" + + ChatColor.RED + " cooldown for another " + + (Cooldowns.getCooldownForPlayerLong("medic_cooldown", p)) + ChatColor.RED + '.'); + return true; + } + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not online."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + Relation relation = Relation.ENEMY; + if (sender instanceof Player) { + final Player player = (Player) sender; + final UUID playerUUID = player.getUniqueId(); + final int selfLives = this.plugin.getDeathbanManager().getLives(playerUUID); + Cooldowns.addCooldown("medic_cooldown", p, 5400); + final PlayerFaction playerFaction = this.plugin.getFactionManager().getPlayerFaction(player); + relation = ((playerFaction == null) ? Relation.ENEMY + : playerFaction.getFactionRelation(this.plugin.getFactionManager().getPlayerFaction(targetUUID))); + sender.sendMessage(ChatColor.YELLOW + "You have revived " + relation.toChatColour() + target.getName() + + ChatColor.YELLOW + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&8&l" + p.getName().toUpperCase() + + " &7has used their Amethyst Rank &eto revive &8&l" + target.getName().toUpperCase() + "&7.")); + } + factionTarget.removeDeathban(); + return true; + } + + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + final List results = new ArrayList(); + final Collection factionUsers = this.plugin.getUserManager().getUsers().values(); + for (final FactionUser factionUser : factionUsers) { + final Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + final String offlineName = offlinePlayer.getName(); + if (offlineName == null) { + continue; + } + results.add(offlinePlayer.getName()); + } + } + return results; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/OresCommand.java b/src/me/bruce/factions/commands/OresCommand.java new file mode 100644 index 0000000..4d6aeff --- /dev/null +++ b/src/me/bruce/factions/commands/OresCommand.java @@ -0,0 +1,96 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; + +public class OresCommand implements CommandExecutor { + + private LorexHCF hcf; + + public OresCommand(LorexHCF hcf) { + this.hcf = hcf; + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "Only players can use this command!"); + return true; + } + if (args.length > 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + Player p = (Player) sender; + if (args.length == 0) { + String uuid = p.getUniqueId().toString(); + if (hcf.getConfig().contains(uuid)) { + p.sendMessage( + ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------------------"); + p.sendMessage(ChatColor.YELLOW + "Your Ores:"); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + ChatColor.BOLD + + "Stone: " + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Stone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.DARK_GRAY + "Coal: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Coal")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.BLUE + "Lapis: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Lapis")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.RED + "Redstone: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Redstone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + "Iron: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Iron")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GOLD + "Gold: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Gold")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.AQUA + "Diamond: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Diamond")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GREEN + "Emeraid: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Emerald")); + p.sendMessage( + ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + "------------------------------------"); + } else { + p.sendMessage(ChatColor.RED + "You haven't mined anything yet!"); + } + } else { + if (args.length == 1) { + Player target = Bukkit.getPlayer(args[0]); + if (target == null) { + target = (Player) Bukkit.getOfflinePlayer(args[0]); + } + String uuid = target.getUniqueId().toString(); + if (hcf.getConfig().contains(uuid)) { + p.sendMessage(ChatColor.GRAY.toString() + ChatColor.STRIKETHROUGH + + "------------------------------------"); + p.sendMessage(ChatColor.YELLOW + target.getName() + "'s Ores:"); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + ChatColor.BOLD + + "Stone: " + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Stone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.DARK_GRAY + "Coal: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Coal")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.BLUE + "Lapis: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Lapis")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.RED + "Redstone: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Redstone")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY + "Iron: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Iron")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GOLD + "Gold: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Gold")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.AQUA + "Diamond: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Diamond")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GREEN + "Emeraid: " + + ChatColor.WHITE + hcf.getConfig().getInt(uuid + ".Mined.Emerald")); + p.sendMessage(ChatColor.WHITE.toString() + ChatColor.BOLD + " * " + ChatColor.GRAY.toString() + + ChatColor.STRIKETHROUGH + "------------------------------------"); + } else { + p.sendMessage(ChatColor.RED + target.getName() + " hasn't mined anything yet!"); + } + } + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/Panic.java b/src/me/bruce/factions/commands/Panic.java new file mode 100644 index 0000000..e879fa8 --- /dev/null +++ b/src/me/bruce/factions/commands/Panic.java @@ -0,0 +1,41 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.md_5.bungee.api.ChatColor; + +public class Panic implements CommandExecutor{ + ArrayList panic = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use in console..."); + } + Player p = (Player) sender; + for(Player staff : Bukkit.getOnlinePlayers()) { + if(!panic.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.RED + "You Have used your panic!"); + staff.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&3&lPANIC&8] " + ChatColor.RED + sender.getName() + " &7Has used there panic ")); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ss " + sender.getName()); + panic.add(p.getUniqueId()); + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&3&lPANIC&8] " + " &7You have unpaniced. ")); + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), "ss " + p.getName()); + panic.remove(p.getUniqueId()); + } + } + return true; + } +} + + + diff --git a/src/me/bruce/factions/commands/PingCommand.java b/src/me/bruce/factions/commands/PingCommand.java new file mode 100644 index 0000000..636cc3b --- /dev/null +++ b/src/me/bruce/factions/commands/PingCommand.java @@ -0,0 +1,32 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; + +public class PingCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + Player target = (Player) sender; + if(target.getPing() < 50) { + sender.sendMessage((target.equals(sender) ? (ChatColor.GREEN + "Your current ping is ") + : (ChatColor.GRAY + "Ping of §c" + (target.getName() + " §7is §c"))) + target.getPing()); + return true; + } + if(target.getPing() > 50){ + target.sendMessage("§cWarning Your ping is to high."); + return true; + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/PlayTimeCommand.java b/src/me/bruce/factions/commands/PlayTimeCommand.java new file mode 100644 index 0000000..62504c9 --- /dev/null +++ b/src/me/bruce/factions/commands/PlayTimeCommand.java @@ -0,0 +1,47 @@ +package me.bruce.factions.commands; + +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import me.bruce.factions.LorexHCF; + +public class PlayTimeCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + OfflinePlayer target; + if (args.length >= 1) { + target = BukkitUtils.offlinePlayerWithNameOrUUID(args[0]); + } else { + if (!(sender instanceof Player)) { + sender.sendMessage("You can only use this if you are a player!"); + return true; + } + target = (OfflinePlayer) sender; + } + if ((!target.hasPlayedBefore()) && (!target.isOnline())) { + sender.sendMessage( + String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, new Object[] { args[0] })); + return true; + } + sender.sendMessage(ChatColor.GREEN.toString() + ChatColor.BOLD + target.getName() + ChatColor.GRAY + + " has been playing Zorex for " + ChatColor.GREEN + + DurationFormatUtils.formatDurationWords( + LorexHCF.getInstance().getPlayTimeManager().getTotalPlayTime(target.getUniqueId()), true, true) + + ChatColor.GRAY + "."); + return true; + } + + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 1 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/PotsCommand.java b/src/me/bruce/factions/commands/PotsCommand.java new file mode 100644 index 0000000..4250fde --- /dev/null +++ b/src/me/bruce/factions/commands/PotsCommand.java @@ -0,0 +1,136 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.economy.EconomyManager; + +public class PotsCommand implements CommandExecutor, Listener { + + private final LorexHCF plugin; + + public PotsCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots = Bukkit.getServer().createInventory(null, 9 * 3, + ChatColor.RED + ChatColor.BOLD.toString() + "Pots gui"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.POTION, 1, (short) 16421); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion"); + lore.add(ChatColor.RED + "press to buy for 500"); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + ItemStack slow = new ItemStack(Material.POTION, 1, (short) 16458); + ItemMeta smeta = health.getItemMeta(); + smeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion"); + lore1.add(ChatColor.RED + "press to buy for 1000"); + smeta.setLore(lore1); + slow.setItemMeta(smeta); + + ItemStack invis = new ItemStack(Material.POTION, 1, (short) 8270); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion"); + lore2.add(ChatColor.RED + "press to buy for 1000"); + smeta.setLore(lore2); + invis.setItemMeta(imeta); + + pots.setItem(13, health); + pots.setItem(10, slow); + pots.setItem(16, invis); + p.openInventory(pots); + return false; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.RED + ChatColor.BOLD.toString() + "Pots gui")) { + event.setCancelled(true); + if (item.equals(null) && !item.hasItemMeta()) { + Bukkit.getConsoleSender().sendMessage(""); + return; + } + + int senderBalance = p != null ? plugin.getEconomyManager().getBalance(p.getUniqueId()) : 1024; + + if (senderBalance < 99 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "100 in you're bank."); + + } else if (senderBalance > 498 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Health Potion")) { + ItemStack health = new ItemStack(Material.POTION, 1, (short) 16421); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 500); + + p.getInventory().addItem(health); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Health potion for " + EconomyManager.ECONOMY_SYMBOL + "500"); + p.closeInventory(); + } + if (senderBalance < 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "1000 in you're bank."); + + } else if (senderBalance > 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Slowness Potion")) { + ItemStack slow = new ItemStack(Material.POTION, 1, (short) 16458); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 1000); + + p.getInventory().addItem(slow); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Slowness potion for " + EconomyManager.ECONOMY_SYMBOL + "1000"); + p.closeInventory(); + } + if (senderBalance < 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion")) { + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You Do not Have " + EconomyManager.ECONOMY_SYMBOL + "1000 in you're bank."); + + } else if (senderBalance > 999 && item.getItemMeta().getDisplayName() + .equals(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Invisibility Potion")) { + ItemStack invis = new ItemStack(Material.POTION, 1, (short) 8270); + final UUID uuid = p.getUniqueId(); + plugin.getEconomyManager().subtractBalance(uuid, 1000); + + p.getInventory().addItem(invis); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + + "You Have Bought the Invisibility potion for " + EconomyManager.ECONOMY_SYMBOL + "1000"); + p.closeInventory(); + } + } + } +} diff --git a/src/me/bruce/factions/commands/Pro.java b/src/me/bruce/factions/commands/Pro.java new file mode 100644 index 0000000..8e3dc91 --- /dev/null +++ b/src/me/bruce/factions/commands/Pro.java @@ -0,0 +1,66 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class Pro implements CommandExecutor { + + private final LorexHCF plugin; + + public Pro(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lPro Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + + + diff --git a/src/me/bruce/factions/commands/PvPCommand.java b/src/me/bruce/factions/commands/PvPCommand.java new file mode 100644 index 0000000..0f0c681 --- /dev/null +++ b/src/me/bruce/factions/commands/PvPCommand.java @@ -0,0 +1,98 @@ +package me.bruce.factions.commands; + + +import com.google.common.collect.ImmutableList; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.timer.type.InvincibilityTimer; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to manage the {@link InvincibilityTimer} of {@link Player}s. + */ +public class PvPCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public PvPCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + InvincibilityTimer pvpTimer = plugin.getTimerManager().getInvincibilityTimer(); + + if (args.length < 1) { + printUsage(sender, label, pvpTimer); + return true; + } + + if (args[0].equalsIgnoreCase("enable") || args[0].equalsIgnoreCase("remove") || args[0].equalsIgnoreCase("off")) { + if (pvpTimer.getRemaining(player) <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " timer is now off."); + pvpTimer.clearCooldown(player); + return true; + } + + if (args[0].equalsIgnoreCase("remaining") || args[0].equalsIgnoreCase("time") || args[0].equalsIgnoreCase("left") || args[0].equalsIgnoreCase("check")) { + long remaining = pvpTimer.getRemaining(player); + if (remaining <= 0L) { + sender.sendMessage(ChatColor.RED + "Your " + pvpTimer.getDisplayName() + ChatColor.RED + " timer is currently not active."); + return true; + } + + sender.sendMessage(ChatColor.YELLOW + "Your " + pvpTimer.getDisplayName() + ChatColor.YELLOW + " timer is active for another " + ChatColor.BOLD + + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.YELLOW + (pvpTimer.isPaused(player) ? " and is currently paused" : "") + '.'); + + return true; + } + + printUsage(sender, label, pvpTimer); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 1 ? BukkitUtils.getCompletions(args, COMPLETIONS) : Collections.emptyList(); + } + + private static final ImmutableList COMPLETIONS = ImmutableList.of("enable", "time"); + + /** + * Prints the usage of this command to a sender. + * + * @param sender + * the sender to print for + * @param label + * the label used for command + */ + private void printUsage(CommandSender sender, String label, InvincibilityTimer pvpTimer) { + sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.STRIKETHROUGH + "-*-----------------------------------------*-"); + sender.sendMessage(ChatColor.GOLD.toString() + ChatColor.BOLD + "PVP Help" + ChatColor.GRAY + " (Page 1 of 1)"); + sender.sendMessage(ChatColor.YELLOW + "/" + label + " enable" + ChatColor.GRAY + " §7" + ChatColor.WHITE +"Removes your PVP Timer"); + sender.sendMessage(ChatColor.YELLOW + "/" + label + " time"+ ChatColor.GRAY + "§7 " + ChatColor.WHITE + "Check remaining PVP Timer"); + sender.sendMessage(ChatColor.YELLOW + "/lives " + ChatColor.GRAY + " §7" + ChatColor.WHITE + "Displays help for player lives."); + sender.sendMessage(ChatColor.DARK_GRAY.toString() + ChatColor.STRIKETHROUGH + "-*-----------------------------------------*-"); + } +} diff --git a/src/me/bruce/factions/commands/RefundCommand.java b/src/me/bruce/factions/commands/RefundCommand.java new file mode 100644 index 0000000..a5f5e3c --- /dev/null +++ b/src/me/bruce/factions/commands/RefundCommand.java @@ -0,0 +1,92 @@ +package me.bruce.factions.commands; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.PlayerDeathEvent; +import org.bukkit.inventory.ItemStack; +import org.bukkit.plugin.Plugin; + +import me.bruce.factions.LorexHCF; +import net.md_5.bungee.api.ChatColor; + +public class RefundCommand implements CommandExecutor, Listener { + private LorexHCF mainPlugin; + private Map rollbackInv; + + public Map getRollbackInv() { + return this.rollbackInv; + } + + public RefundCommand(final LorexHCF mainPlugin) { + this.mainPlugin = mainPlugin; + this.mainPlugin.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this.mainPlugin); + this.rollbackInv = new HashMap(); + } + + public boolean onCommand(final CommandSender s, final Command c, final String alias, final String[] args) { + if (!s.hasPermission("core.refund")) { + s.sendMessage(ChatColor.RED + "You do not have permission."); + return true; + } + if (args.length != 1) { + s.sendMessage(ChatColor.RED + "Correct Usage: /" + c.getName() + " "); + return true; + } + final Player p = this.mainPlugin.getServer().getPlayer(args[0]); + if (p == null) { + s.sendMessage(ChatColor.RED + "Player is not online."); + return true; + } + if (!this.rollbackInv.containsKey(p.getUniqueId())) { + s.sendMessage(ChatColor.RED + p.getName() + " does not have a stored record of his/her inventory."); + } + else { + s.sendMessage(ChatColor.GREEN + p.getName() + "'s inventory has been restored."); + p.sendMessage(ChatColor.GREEN + "Your inventory was restored by " + s.getName() + "."); + final InventorySet invSet = this.rollbackInv.get(p.getUniqueId()); + p.getInventory().setContents(invSet.getInv()); + p.getInventory().setArmorContents(invSet.getArmor()); + } + return true; + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onDeath(final PlayerDeathEvent e) { + final UUID entityUUID = e.getEntity().getUniqueId(); + this.rollbackInv.put(entityUUID, new InventorySet(e.getEntity())); + } + + public class InventorySet + { + private Player p; + private ItemStack[] inv; + private ItemStack[] armor; + + public Player getP() { + return this.p; + } + + public ItemStack[] getInv() { + return this.inv; + } + + public ItemStack[] getArmor() { + return this.armor; + } + + public InventorySet(final Player p) { + this.p = p; + this.inv = p.getInventory().getContents(); + this.armor = p.getInventory().getArmorContents(); + } + } + } diff --git a/src/me/bruce/factions/commands/RegenCommand.java b/src/me/bruce/factions/commands/RegenCommand.java new file mode 100644 index 0000000..1bad313 --- /dev/null +++ b/src/me/bruce/factions/commands/RegenCommand.java @@ -0,0 +1,83 @@ +package me.bruce.factions.commands; + + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.struct.RegenStatus; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; +import net.minecraft.util.org.apache.commons.lang3.time.DurationFormatUtils; + +import java.util.Collections; +import java.util.List; + +public class RegenCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public RegenCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + Player player = (Player) sender; + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + if (playerFaction == null) { + sender.sendMessage(ChatColor.RED + "You are not in a faction."); + return true; + } + + RegenStatus regenStatus = playerFaction.getRegenStatus(); + switch (regenStatus) { + case FULL: + sender.sendMessage(ChatColor.RED + "Your faction currently has full DTR."); + return true; + case PAUSED: + sender.sendMessage(ChatColor.RED + "Your faction is currently on DTR freeze for another " + ChatColor.WHITE + + DurationFormatUtils.formatDurationWords(playerFaction.getRemainingRegenerationTime(), true, true) + + ChatColor.RED + '.'); + + return true; + case REGENERATING: + sender.sendMessage( + ChatColor.YELLOW + "Your faction currently has " + ChatColor.YELLOW + regenStatus.getSymbol() + ' ' + + playerFaction.getDeathsUntilRaidable() + ChatColor.YELLOW + + " DTR and is regenerating at a rate of " + ChatColor.GOLD + + SettingsYML.DTR_INCREMENT_BETWEEN_UPDATES + ChatColor.YELLOW + " every " + ChatColor.GOLD + + SettingsYML.DTR_WORDS_BETWEEN_UPDATES + ChatColor.YELLOW + + ". Your ETA for maximum DTR is " + ChatColor.RED + DurationFormatUtils + .formatDurationWords(getRemainingRegenMillis(playerFaction), true, true) + + ChatColor.YELLOW + '.'); + + return true; + } + + sender.sendMessage( + ChatColor.RED + "Unrecognised regeneration status, please inform an Developer or an System Admin."); + return true; + } + + public long getRemainingRegenMillis(PlayerFaction faction) { + long millisPassedSinceLastUpdate = System.currentTimeMillis() - faction.getLastDtrUpdateTimestamp(); + double dtrRequired = faction.getMaximumDeathsUntilRaidable() - faction.getDeathsUntilRaidable(); + return (long) ((SettingsYML.DTR_MILLIS_BETWEEN_UPDATES / SettingsYML.DTR_INCREMENT_BETWEEN_UPDATES) + * dtrRequired) - millisPassedSinceLastUpdate; + } + + @Override + public List onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/RenameCommand.java b/src/me/bruce/factions/commands/RenameCommand.java new file mode 100644 index 0000000..66dcdb7 --- /dev/null +++ b/src/me/bruce/factions/commands/RenameCommand.java @@ -0,0 +1,58 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class RenameCommand implements CommandExecutor { + + private LorexHCF plugin; + + public RenameCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + public String getUsage(String label) { + return String.valueOf('/') + label + ' ' + ""; + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if (args.length < 1) { + p.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&7If you want to use any color make sure you do & and then the color code.")); + } else { + ItemStack hand = p.getItemInHand(); + if (hand.getType() != Material.AIR) { + String name = ""; + for (int i = 0; i != args.length; i++) + name += args[i] + " "; + + ItemMeta meta = hand.getItemMeta(); + meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', "&r" + name)); + hand.setItemMeta(meta); + + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou have successfully renamed your &c" + + hand.getType().name().toLowerCase() + " &7to &r" + name)); + } else { + p.sendMessage(ChatColor.RED + "You cannot rename Air!"); + + } + } + return true; + } + +} diff --git a/src/me/bruce/factions/commands/ReviveCommand.java b/src/me/bruce/factions/commands/ReviveCommand.java new file mode 100644 index 0000000..83d09d6 --- /dev/null +++ b/src/me/bruce/factions/commands/ReviveCommand.java @@ -0,0 +1,73 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; + +public class ReviveCommand implements CommandExecutor, TabCompleter { + private final LorexHCF plugin; + + public ReviveCommand(final LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(ChatColor.RED + "Player '" + ChatColor.WHITE + args[0] + ChatColor.RED + "' not found."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = LorexHCF.getInstance().getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + Command.broadcastCommandMessage(sender, + ChatColor.GREEN + "A staff member has successfully revived " + target.getName() + "."); + return false; + } + + @Override + public List onTabComplete(final CommandSender sender, final Command command, final String label, + final String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + final List results = new ArrayList(); + for (final FactionUser factionUser : this.plugin.getUserManager().getUsers().values()) { + final Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + final String name = offlinePlayer.getName(); + if (name == null) { + continue; + } + results.add(name); + } + } + return BukkitUtils.getCompletions(args, results); + } +} diff --git a/src/me/bruce/factions/commands/RulesCommand.java b/src/me/bruce/factions/commands/RulesCommand.java new file mode 100644 index 0000000..d690052 --- /dev/null +++ b/src/me/bruce/factions/commands/RulesCommand.java @@ -0,0 +1,26 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +public class RulesCommand implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&C&LSERVER RULES ")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cNo racism / excessive insults")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CSpamming is a kickable offense")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cAll server members, are treated the same (Staff, Donators, Players)")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CStaff cannot punish higher staff members [Only applied in game]")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CDDoSing / Doxing Threats, are a bannable offense on both the Discord and the Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cGeneral threats are a bannable offense on both the Discord and the Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cSuicidal jokes are a kickable offense on the Discord Server.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &CNo screamers or IP loggers allowed. (Will result in a blacklist ingame & discord)")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &cNo advertising other servers.")); + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&4» &c No voice changers / trolling staff.")); + return true; + } + +} diff --git a/src/me/bruce/factions/commands/SPCOMMAND.java b/src/me/bruce/factions/commands/SPCOMMAND.java new file mode 100644 index 0000000..0b597b7 --- /dev/null +++ b/src/me/bruce/factions/commands/SPCOMMAND.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class SPCOMMAND implements CommandExecutor{ + + public static ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7speed.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7speed.")); + p.removePotionEffect(PotionEffectType.SPEED); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/SetPrefixCommand.java b/src/me/bruce/factions/commands/SetPrefixCommand.java new file mode 100644 index 0000000..be7b2d7 --- /dev/null +++ b/src/me/bruce/factions/commands/SetPrefixCommand.java @@ -0,0 +1,43 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import ru.tehkode.permissions.bukkit.PermissionsEx; + +public class SetPrefixCommand implements CommandExecutor +{ + public boolean onCommand(final CommandSender sender, final Command cmd, final String label, final String[] args) { + if (!sender.hasPermission("zentrix.admin")) { + sender.sendMessage("§cNo permission."); + return true; + } + if (args.length == 0) { + sender.sendMessage("§cUsage: /setprefix "); + return true; + } + final Player pl = Bukkit.getPlayer(args[0]); + if (pl == null) { + sender.sendMessage("§cPlayer not found!"); + return true; + } + if (args.length < 2) { + sender.sendMessage("§cUsage: /setprefix "); + return true; + } + if (args[1].equals("remove")) { + + pl.sendMessage(LorexHCF.PREFIX + "Your prefix has been removed by: " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(sender.getName()).getPrefix() + sender.getName())); + sender.sendMessage(LorexHCF.PREFIX + "You have removed " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(pl.getName()).getPrefix() + pl.getName()) + "'s prefix!"); + return true; + } + pl.sendMessage(LorexHCF.PREFIX + "Your prefix has been set to: " + ChatColor.translateAlternateColorCodes('&', args[1]) + " by " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(sender.getName()).getPrefix() + sender.getName())); + sender.sendMessage(LorexHCF.PREFIX + "You have set " + ChatColor.translateAlternateColorCodes('&', PermissionsEx.getUser(pl.getName()).getSuffix() + pl.getName()) + "'s prefix to: " + ChatColor.translateAlternateColorCodes('&', args[1])); + return true; + } +} diff --git a/src/me/bruce/factions/commands/SettingsCommand.java b/src/me/bruce/factions/commands/SettingsCommand.java new file mode 100644 index 0000000..980a725 --- /dev/null +++ b/src/me/bruce/factions/commands/SettingsCommand.java @@ -0,0 +1,264 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class SettingsCommand implements CommandExecutor, Listener { + + + public static ArrayList lines = new ArrayList(); + public static ArrayList scoreboard = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots = Bukkit.getServer().createInventory(null, 9 * 3, + ChatColor.BLUE + ChatColor.BOLD.toString() + "Settings GUI"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.BAKED_POTATO); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "ClearChat"); + lore.add(ChatColor.YELLOW + "This will only clear you're chat"); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + ItemStack slow = new ItemStack(Material.BLAZE_ROD); + ItemMeta smeta = health.getItemMeta(); + smeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Scoreboard"); + if(scoreboard.contains(p.getUniqueId())) { + lore1.add(ChatColor.YELLOW + "Balance on scoreboard §aEnabled§7!"); + smeta.setLore(lore1); + } + else { + lore1.add(ChatColor.YELLOW + "Balance on scoreboard §cDisabled§7!"); + smeta.setLore(lore1); + } + slow.setItemMeta(smeta); + + ItemStack invis = new ItemStack(Material.DIAMOND_BLOCK); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Lines on scoreboard"); + if(lines.contains(p.getUniqueId())) { + lore2.add(ChatColor.YELLOW + "Lines on scoreboard §cDisabled§7!"); + imeta.setLore(lore2); + } + else { + lore2.add(ChatColor.YELLOW + "Lines on scoreboard §aEnabled§7!"); + imeta.setLore(lore2); + } + invis.setItemMeta(imeta); + + pots.setItem(13, health); + pots.setItem(10, slow); + pots.setItem(16, invis); + p.openInventory(pots); + return false; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Settings GUI")) { + + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "ClearChat")) { + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(""); + p.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + + "You're Chat Has Been Cleared."); + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Scoreboard")) { + if(scoreboard.contains(p.getUniqueId())) { + scoreboard.remove(p.getUniqueId()); + p.closeInventory(); + } + else { + scoreboard.add(p.getUniqueId()); + p.closeInventory(); + } + + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Lines on scoreboard")) { + if(lines.contains(p.getUniqueId())) { + lines.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "No lines has been §cDisabled§7." ); + p.closeInventory(); + + } + else if(!lines.contains(p.getUniqueId())) { + lines.add(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "No lines has been §aEnabled§7." ); + p.closeInventory(); + + } + + } + } + } +} diff --git a/src/me/bruce/factions/commands/SpawnCommand.java b/src/me/bruce/factions/commands/SpawnCommand.java new file mode 100644 index 0000000..e515df6 --- /dev/null +++ b/src/me/bruce/factions/commands/SpawnCommand.java @@ -0,0 +1,42 @@ +package me.bruce.factions.commands; + +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.Listener; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.ymls.SettingsYML; +import net.md_5.bungee.api.ChatColor; + +public class SpawnCommand implements CommandExecutor, Listener { + + + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + if(!(sender instanceof Player)) { + sender.sendMessage("Cannot use this command in console."); + return true; + } + Player p = (Player) sender; + if(!p.hasPermission("staff.spawn")) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» §cTravel to 0.0")); + return true; + } + else { + if(SettingsYML.KIT_MAP == true) { + p.teleport(new Location(Bukkit.getWorld("World"), 0,80,-1)); + } + } + if(SettingsYML.KIT_MAP == false) { + p.teleport(new Location(Bukkit.getWorld("World"), 0,73,-1)); + } + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &eYou Have teleported to spawn.")); + return true; + } + } + diff --git a/src/me/bruce/factions/commands/StaffInformation.java b/src/me/bruce/factions/commands/StaffInformation.java new file mode 100644 index 0000000..924419c --- /dev/null +++ b/src/me/bruce/factions/commands/StaffInformation.java @@ -0,0 +1,30 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class StaffInformation implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + + if (cmd.getName().equalsIgnoreCase("staffguide")) { + if (p.hasPermission("zorex.staffguide")) { + if (args.length == 0) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&8&m------------------------------------------- ")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» Staff Guide")); + p.sendMessage(ChatColor.translateAlternateColorCodes('&', + "&8&m------------------------------------------- ")); + } else { + p.sendMessage(ChatColor.RED + "You Do Not Have Permission To Use this command"); + } + } + } + return false; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/commands/StaffSettings.java b/src/me/bruce/factions/commands/StaffSettings.java new file mode 100644 index 0000000..f71ce62 --- /dev/null +++ b/src/me/bruce/factions/commands/StaffSettings.java @@ -0,0 +1,113 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; + +public class StaffSettings implements CommandExecutor, Listener { + + + public static ArrayList faithful = new ArrayList(); + public static ArrayList zorex = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + Inventory pots1 = Bukkit.getServer().createInventory(null, 9, + ChatColor.BLUE + ChatColor.BOLD.toString() + "Staff GUI"); + ArrayList lore = new ArrayList(); + ArrayList lore1 = new ArrayList(); + ArrayList lore2 = new ArrayList(); + + ItemStack health = new ItemStack(Material.BAKED_POTATO); + ItemMeta hmeta = health.getItemMeta(); + hmeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Faithful Remake"); + lore.add(ChatColor.BLUE + ""); + hmeta.setLore(lore); + health.setItemMeta(hmeta); + + + + + ItemStack invis = new ItemStack(Material.DIAMOND_BLOCK); + ItemMeta imeta = invis.getItemMeta(); + imeta.setDisplayName(ChatColor.BLUE + ChatColor.BOLD.toString() + "Zorex"); + invis.setItemMeta(imeta); + + pots1.setItem(0, health); + pots1.setItem(1, invis); + p.openInventory(pots1); + return true; + } + + @EventHandler + public void InvenClick(InventoryClickEvent event) { + Player p = (Player) event.getWhoClicked(); + Inventory open = event.getInventory(); + ItemStack item = event.getCurrentItem(); + + if (open == null) { + return; + } + if (open.getName().equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Staff GUI")) { + + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Faithful Remake")) { + if(faithful.contains(p.getUniqueId())) { + faithful.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §4Disabled §7Faithful."); + } + if(!faithful.contains(p.getUniqueId())) { + faithful.add(p.getUniqueId()); + p.closeInventory(); + p.sendMessage(LorexHCF.PREFIX + "You have §aEnabled §7Faithful."); + } + if(zorex.contains(p.getUniqueId())) { + zorex.remove(p.getUniqueId()); + p.closeInventory(); + p.sendMessage(LorexHCF.PREFIX + "Zorex was still on so we disabled it."); + } + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "NONE")) { + p.closeInventory(); + } + if (item.getItemMeta().getDisplayName() + .equals(ChatColor.BLUE + ChatColor.BOLD.toString() + "Zorex")) { + if(zorex.contains(p.getUniqueId())) { + zorex.remove(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §4Disabled §7Zorex."); + p.closeInventory(); + } + if(!zorex.contains(p.getUniqueId())) { + zorex.add(p.getUniqueId()); + p.sendMessage(LorexHCF.PREFIX + "You have §aEnabled §7Zorex."); + p.closeInventory(); + } + if(faithful.contains(p.getUniqueId())) { + faithful.remove(p.getUniqueId()); + } + } + + } + + } + } + + diff --git a/src/me/bruce/factions/commands/StatsCommand.java b/src/me/bruce/factions/commands/StatsCommand.java new file mode 100644 index 0000000..4ed6de1 --- /dev/null +++ b/src/me/bruce/factions/commands/StatsCommand.java @@ -0,0 +1,31 @@ +package me.bruce.factions.commands; + +import org.bukkit.Statistic; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import net.md_5.bungee.api.ChatColor; + +public class StatsCommand implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender arg0, Command arg1, String arg2, String[] arg3) { + if(!(arg0 instanceof Player)) { + return true; + } + Player p = (Player) arg0; + arg0.sendMessage("§7§m----------------------------------------------"); + arg0.sendMessage(ChatColor.DARK_RED + ChatColor.BOLD.toString() + "Player Stats:"); + arg0.sendMessage(""); + arg0.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Kills§7:§f " + p.getStatistic(Statistic.PLAYER_KILLS)); + arg0.sendMessage(ChatColor.RED + ChatColor.BOLD.toString() + "Deaths§7:§f " + p.getStatistic(Statistic.DEATHS)); + arg0.sendMessage("§7§m----------------------------------------------"); + return true; + } +} + + + + diff --git a/src/me/bruce/factions/commands/Store.java b/src/me/bruce/factions/commands/Store.java new file mode 100644 index 0000000..f48e964 --- /dev/null +++ b/src/me/bruce/factions/commands/Store.java @@ -0,0 +1,5 @@ +package me.bruce.factions.commands; + +public class Store { + +} diff --git a/src/me/bruce/factions/commands/TLCommand.java b/src/me/bruce/factions/commands/TLCommand.java new file mode 100644 index 0000000..38df6c9 --- /dev/null +++ b/src/me/bruce/factions/commands/TLCommand.java @@ -0,0 +1,27 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class TLCommand implements CommandExecutor { + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage("No Console"); + return true; + } + final Player player = (Player)sender; + final int x = player.getLocation().getBlockX(); + final int y = player.getLocation().getBlockY(); + final int z = player.getLocation().getBlockZ(); + if (command.getName().equalsIgnoreCase("tl")) { + player.chat("/f c " + x + ", " + y + ", " + z); + return true; + } + return true; + } + } + + + diff --git a/src/me/bruce/factions/commands/Tablist.java b/src/me/bruce/factions/commands/Tablist.java new file mode 100644 index 0000000..3035903 --- /dev/null +++ b/src/me/bruce/factions/commands/Tablist.java @@ -0,0 +1,55 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerJoinEvent; + +public class Tablist implements CommandExecutor, Listener { + + public static ArrayList oof = new ArrayList(); + public static ArrayList defaulty = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { + Player p = (Player) sender; + if (args.length == 0) { + sender.sendMessage("Please say wich tablist you want"); + return true; + + } + if ((args.length == 1 && (args[0].equalsIgnoreCase("kitmap")))) { + sender.sendMessage( + ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7you have enabled Kitmap.")); + defaulty.remove(p); + oof.add(p); + return true; + } + if ((args.length == 1 && (args[0].equalsIgnoreCase("default")))) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7you have enabled default.")); + oof.remove(p); + defaulty.add(p); + return true; + } + else if(args.length == 1 ) { + sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You Must choose either kitmap are default.")); + } + + return false; + } + + @EventHandler + public void onJoin(PlayerJoinEvent e) { + Player p = e.getPlayer(); + oof.remove(p); + defaulty.add(p); + + } + +} diff --git a/src/me/bruce/factions/commands/TablistCommand.java b/src/me/bruce/factions/commands/TablistCommand.java new file mode 100644 index 0000000..84403ad --- /dev/null +++ b/src/me/bruce/factions/commands/TablistCommand.java @@ -0,0 +1,74 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; + +import me.bruce.factions.LorexHCF; +import me.tablist.api.tablist.Xernos; +import me.tablist.api.tablist.adapter.TablistAdapter; +import net.md_5.bungee.api.ChatColor; + +public class TablistCommand implements CommandExecutor,Listener { + + public static ArrayList kits = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + Player p = (Player) sender; + Inventory inv = Bukkit.createInventory(null, 9, ChatColor.GOLD + "Tablist Selector"); + ItemStack kits = new ItemStack(Material.DIAMOND_SWORD); + ItemMeta kmeta = kits.getItemMeta(); + kmeta.setDisplayName("§7Kitmap Tablist"); + kits.setItemMeta(kmeta); + + ItemStack normal = new ItemStack(Material.DIAMOND_SWORD); + ItemMeta nmeta = normal.getItemMeta(); + nmeta.setDisplayName("§7Default Tablist"); + normal.setItemMeta(nmeta); + + inv.setItem(0, kits); + inv.setItem(1, normal); + p.openInventory(inv); + return true; + } + + @EventHandler + public void onInventoryInteract(InventoryClickEvent e) { + Player p = (Player) e.getWhoClicked(); + if(e.getClickedInventory().getName().equalsIgnoreCase(ChatColor.GOLD + "Tablist Selector")) { + e.setCancelled(true); + if(e.getCurrentItem().getItemMeta() == null) { + return; + } + if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Kitmap Tablist")) { + p.sendMessage(LorexHCF.PREFIX + " You have selected the Kitmap tablist."); + TablistAdapter.tablist.add(p); + p.closeInventory(); + Xernos.getByPlayer(p).clearTab(); + + } + if(e.getCurrentItem().getItemMeta().getDisplayName().equalsIgnoreCase(ChatColor.GRAY + "Default Tablist")) { + p.sendMessage(LorexHCF.PREFIX + " You have selected the Default tablist."); + p.closeInventory(); + TablistAdapter.tablist.remove(p); + Xernos.getByPlayer(p).clearTab(); + + + } + } + } + +} diff --git a/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java b/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java new file mode 100644 index 0000000..5236b93 --- /dev/null +++ b/src/me/bruce/factions/commands/ToggleCapzoneEntryCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to toggle messages shown when entering or leaving + */ +public class ToggleCapzoneEntryCommand implements CommandExecutor, TabExecutor { + + private final LorexHCF plugin; + + public ToggleCapzoneEntryCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + FactionUser factionUser = plugin.getUserManager().getUser(((Player) sender).getUniqueId()); + boolean newStatus = !factionUser.isCapzoneEntryAlerts(); + factionUser.setCapzoneEntryAlerts(newStatus); + + sender.sendMessage( + ChatColor.YELLOW + "You will now " + (newStatus ? ChatColor.GREEN.toString() : ChatColor.RED + "un") + + "able" + ChatColor.YELLOW + " to see capture zone entry messages."); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/ToggleLightningCommand.java b/src/me/bruce/factions/commands/ToggleLightningCommand.java new file mode 100644 index 0000000..43c2343 --- /dev/null +++ b/src/me/bruce/factions/commands/ToggleLightningCommand.java @@ -0,0 +1,49 @@ +package me.bruce.factions.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabExecutor; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.Collections; +import java.util.List; + +/** + * Command used to toggle the lightning strikes on death for a {@link Player}. + */ +public class ToggleLightningCommand implements CommandExecutor, TabExecutor { + + private final LorexHCF plugin; + + public ToggleLightningCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + + FactionUser factionUser = plugin.getUserManager().getUser(((Player) sender).getUniqueId()); + boolean newShowLightning = !factionUser.isShowLightning(); + factionUser.setShowLightning(newShowLightning); + + sender.sendMessage(ChatColor.YELLOW + "You will now " + + (newShowLightning ? ChatColor.GREEN + "able" : ChatColor.RED + "unable") + ChatColor.YELLOW + + " to see lightning strikes on a players death."); + + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/commands/Vip.java b/src/me/bruce/factions/commands/Vip.java new file mode 100644 index 0000000..cf139e1 --- /dev/null +++ b/src/me/bruce/factions/commands/Vip.java @@ -0,0 +1,65 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class Vip implements CommandExecutor{ + private final LorexHCF plugin; + + public Vip(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lVip Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + + + diff --git a/src/me/bruce/factions/commands/WB.java b/src/me/bruce/factions/commands/WB.java new file mode 100644 index 0000000..1fbc412 --- /dev/null +++ b/src/me/bruce/factions/commands/WB.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class WB implements CommandExecutor{ + + ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7WATER BREATHING.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7WATER BREATHING.")); + p.removePotionEffect(PotionEffectType.WATER_BREATHING); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/ZorexDeveloper.java b/src/me/bruce/factions/commands/ZorexDeveloper.java new file mode 100644 index 0000000..b405b50 --- /dev/null +++ b/src/me/bruce/factions/commands/ZorexDeveloper.java @@ -0,0 +1,17 @@ +package me.bruce.factions.commands; + +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; + +import me.bruce.factions.LorexHCF; + +public class ZorexDeveloper implements CommandExecutor { + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { + sender.sendMessage(LorexHCF.PREFIX + "The developer of Zorex is Bruceboy!"); + return false; + } + +} diff --git a/src/me/bruce/factions/commands/ZorexRevive.java b/src/me/bruce/factions/commands/ZorexRevive.java new file mode 100644 index 0000000..d2c5339 --- /dev/null +++ b/src/me/bruce/factions/commands/ZorexRevive.java @@ -0,0 +1,63 @@ +package me.bruce.factions.commands; + +import java.util.UUID; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.Cooldowns; + +public class ZorexRevive implements CommandExecutor{ + private final LorexHCF plugin; + + public ZorexRevive(final LorexHCF plugin) { + this.plugin = plugin; + } + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + if (args.length == 0) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " revive [player]"); + return true; + } + if(args.length == 1) { + sender.sendMessage("§cPlease enter the name"); + return true; + } + else if(args.length == 2){ + final Player player = (Player)sender; + final OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (Cooldowns.isOnCooldown("revive_cooldown", player)) { + sender.sendMessage("§cYou cannot do this for another §l" + Cooldowns.getCooldownForPlayerInt("revive_cooldown", player) / 60 + " §cminutes."); + return true; + } + final UUID targetUUID = target.getUniqueId(); + final FactionUser factionTarget = this.plugin.getUserManager().getUser(targetUUID); + final Deathban deathban = factionTarget.getDeathban(); + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + factionTarget.removeDeathban(); + sender.sendMessage(ChatColor.GRAY + "You have revived " + ChatColor.AQUA + target.getName() + ChatColor.GRAY + '.'); + Bukkit.broadcastMessage(ChatColor.translateAlternateColorCodes('&', "&7[&f&lREVIVE&7] &6&l" + sender.getName() + " &ehas used his &9&lZorex Rank &eto revive &A" + target.getName())); + Cooldowns.addCooldown("revive_cooldown", player, 3600); + return true; + + } + return false; + + } +} + diff --git a/src/me/bruce/factions/commands/nv.java b/src/me/bruce/factions/commands/nv.java new file mode 100644 index 0000000..3e7cb2f --- /dev/null +++ b/src/me/bruce/factions/commands/nv.java @@ -0,0 +1,39 @@ +package me.bruce.factions.commands; + +import java.util.ArrayList; +import java.util.UUID; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +public class nv implements CommandExecutor{ + + ArrayList sp = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + Player p = (Player) sender; + if(!sp.contains(p.getUniqueId())) { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &aEnabled &7NIGHT VISION.")); + p.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, Integer.MAX_VALUE, 1)); + sp.add(p.getUniqueId()); + return true; + } + else { + p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6&lZorex &8» &7You have &cDisabled &7NIGHT VISION.")); + p.removePotionEffect(PotionEffectType.NIGHT_VISION); + sp.remove(p.getUniqueId()); + } + return false; + } + +} diff --git a/src/me/bruce/factions/commands/randomtp.java b/src/me/bruce/factions/commands/randomtp.java new file mode 100644 index 0000000..bfd108b --- /dev/null +++ b/src/me/bruce/factions/commands/randomtp.java @@ -0,0 +1,40 @@ +package me.bruce.factions.commands; + + +import org.bukkit.command.*; +import org.bukkit.*; +import org.bukkit.entity.*; +import java.util.*; + +public class randomtp implements CommandExecutor{ + + public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) { + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED + "This command is only executable by players."); + return true; + } + final Player player = (Player)sender; + final List players = new ArrayList(); + for (final Player players2 : Bukkit.getOnlinePlayers()) { + players.add(players2); + } + Collections.shuffle(players); + final Random random = new Random(); + final int randoms = random.nextInt(Bukkit.getOnlinePlayers().length); + final Player p = players.get(randoms); + if (player.canSee(p) && player.hasPermission("zorex.teleport")) { + player.teleport((Entity)p); + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY+ "You have teleported to " + p.getName()); + } + else if (player.canSee(p)) { + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.GRAY + "You have found " + p.getName()); + } + else { + player.sendMessage(ChatColor.GOLD + ChatColor.BOLD.toString() + "Zorex §8» " + ChatColor.RED + "Player could not be found."); + } + return true; +} +} + + + diff --git a/src/me/bruce/factions/conquest/ConquestExecutor.java b/src/me/bruce/factions/conquest/ConquestExecutor.java new file mode 100644 index 0000000..7574314 --- /dev/null +++ b/src/me/bruce/factions/conquest/ConquestExecutor.java @@ -0,0 +1,12 @@ +package me.bruce.factions.conquest; + +import LorexMC.us.utils.other.command.ArgumentExecutor; +import me.bruce.factions.LorexHCF; + +public class ConquestExecutor extends ArgumentExecutor { + + public ConquestExecutor(LorexHCF plugin) { + super("conquest"); + addArgument(new ConquestSetpointsArgument(plugin)); + } +} diff --git a/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java b/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java new file mode 100644 index 0000000..7c28a94 --- /dev/null +++ b/src/me/bruce/factions/conquest/ConquestSetpointsArgument.java @@ -0,0 +1,66 @@ +package me.bruce.factions.conquest; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.eventutils.EventType; +import me.bruce.factions.eventutils.tracker.ConquestTracker; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; + +public class ConquestSetpointsArgument extends CommandArgument { + + private final LorexHCF plugin; + + public ConquestSetpointsArgument(LorexHCF plugin) { + super("setpoints", "Sets the points of a faction in the Conquest event", + "hcf.command.conquest.argument.setpoints"); + this.plugin = plugin; + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + Faction faction = plugin.getFactionManager().getFaction(args[1]); + + if (!(faction instanceof PlayerFaction)) { + sender.sendMessage( + ChatColor.RED + "FactionListener " + args[1] + " is either not found or is not a player faction."); + return true; + } + + Integer amount = JavaUtils.tryParseInt(args[2]); + + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + + if (amount > SettingsYML.CONQUEST_REQUIRED_WIN_POINTS) { + sender.sendMessage( + ChatColor.RED + "Maximum points for Conquest is " + SettingsYML.CONQUEST_REQUIRED_WIN_POINTS + '.'); + return true; + } + + PlayerFaction playerFaction = (PlayerFaction) faction; + ((ConquestTracker) EventType.CONQUEST.getEventTracker()).setPoints(playerFaction, amount); + + Command.broadcastCommandMessage(sender, + ChatColor.YELLOW + "Set the points of faction " + playerFaction.getName() + " to " + amount + '.'); + return true; + } +} diff --git a/src/me/bruce/factions/deathban/Deathban.java b/src/me/bruce/factions/deathban/Deathban.java new file mode 100644 index 0000000..538b416 --- /dev/null +++ b/src/me/bruce/factions/deathban/Deathban.java @@ -0,0 +1,78 @@ +package me.bruce.factions.deathban; + +import org.bukkit.Location; +import org.bukkit.configuration.serialization.ConfigurationSerializable; + +import com.google.common.collect.Maps; + +import LorexMC.us.utils.PersistableLocation; + +import java.util.Map; + +public class Deathban implements ConfigurationSerializable { + private final String reason; + private final long creationMillis; + private final long expiryMillis; + private final PersistableLocation deathPoint; + + public Deathban(String reason, long duration, PersistableLocation deathPoint) { + this.reason = reason; + long millis = System.currentTimeMillis(); + this.creationMillis = millis; + this.expiryMillis = (millis + duration); + this.deathPoint = deathPoint; + } + + public Deathban(Map map) { + this.reason = ((String) map.get("reason")); + this.creationMillis = Long.parseLong((String) map.get("creationMillis")); + this.expiryMillis = Long.parseLong((String) map.get("expiryMillis")); + Object object = map.get("deathPoint"); + if (object != null) { + this.deathPoint = ((PersistableLocation) object); + } else { + this.deathPoint = null; + } + } + + @Override + public Map serialize() { + Map map = Maps.newLinkedHashMap(); + map.put("reason", this.reason); + map.put("creationMillis", Long.toString(this.creationMillis)); + map.put("expiryMillis", Long.toString(this.expiryMillis)); + if (this.deathPoint != null) { + map.put("deathPoint", this.deathPoint); + } + return map; + } + + public boolean isActive() { + return getRemaining() > 0L; + } + + public String getReason() { + return this.reason; + } + + public long getCreationMillis() { + return this.creationMillis; + } + + public long getExpiryMillis() { + return this.expiryMillis; + } + + public long getRemaining() { + return this.expiryMillis - System.currentTimeMillis(); + } + + public Location getDeathPoint() { + return this.deathPoint == null ? null : this.deathPoint.getLocation(); + } + + public long getInitialDuration() { + // TODO Auto-generated method stub + return 0; + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/deathban/DeathbanListener.java b/src/me/bruce/factions/deathban/DeathbanListener.java new file mode 100644 index 0000000..412ed19 --- /dev/null +++ b/src/me/bruce/factions/deathban/DeathbanListener.java @@ -0,0 +1,182 @@ +/* */ package me.bruce.factions.deathban; + +/* */ +/* */ import java.util.UUID; +/* */ import java.util.concurrent.TimeUnit; + +/* */ import net.minecraft.util.gnu.trove.map.TObjectIntMap; +/* */ import net.minecraft.util.gnu.trove.map.TObjectLongMap; +/* */ import net.minecraft.util.gnu.trove.map.hash.TObjectLongHashMap; + +/* */ import org.bukkit.ChatColor; +/* */ import org.bukkit.entity.Player; +/* */ import org.bukkit.event.EventHandler; +/* */ import org.bukkit.event.EventPriority; +/* */ import org.bukkit.event.Listener; +/* */ import org.bukkit.event.entity.PlayerDeathEvent; +/* */ import org.bukkit.event.player.PlayerLoginEvent; +/* */ import org.bukkit.event.player.PlayerQuitEvent; +/* */ import org.bukkit.event.player.PlayerRespawnEvent; +/* */ import org.bukkit.scheduler.BukkitRunnable; +import LorexMC.us.utils.DurationFormatter; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.DelayedMessageRunnable; + +/* */ +/* */ public class DeathbanListener implements Listener +/* */ { + /* 29 */ private static final long RESPAWN_KICK_DELAY_MILLIS = TimeUnit.SECONDS.toMillis(10L); + /* 30 */ private static final long RESPAWN_KICK_DELAY_TICKS = RESPAWN_KICK_DELAY_MILLIS / 50L; + /* 31 */ private static final long LIFE_USE_DELAY_MILLIS = TimeUnit.SECONDS.toMillis(30L); + /* 32 */ private static final String LIFE_USE_DELAY_WORDS = org.apache.commons.lang3.time.DurationFormatUtils + .formatDurationWords(LIFE_USE_DELAY_MILLIS, true, true); + /* */ + /* */ private static final String DEATH_BAN_BYPASS_PERMISSION = "hcf.deathban.bypass"; + /* 35 */ private final TObjectIntMap respawnTickTasks = new net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap(); + /* 36 */ private final TObjectLongMap lastAttemptedJoinMap = new TObjectLongHashMap(); + /* */ private final LorexHCF plugin; + + /* */ + /* */ public DeathbanListener(LorexHCF plugin) { + /* 40 */ this.plugin = plugin; + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) + /* */ public void onPlayerLogin(PlayerLoginEvent event) { + /* 45 */ Player player = event.getPlayer(); + /* 46 */ if (player.hasPermission("hcf.deathban.bypass")) { + /* 47 */ return; + /* */ } + /* */ + /* 50 */ FactionUser user = this.plugin.getUserManager().getUser(player.getUniqueId()); + /* 51 */ Deathban deathban = user.getDeathban(); + /* 52 */ if ((deathban == null) || (!deathban.isActive())) { + /* 53 */ return; + /* */ } + /* */ + /* 56 */ if (this.plugin.getEotwHandler().isEndOfTheWorld()) { + /* 57 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + + "Deathbanned for the entirety of the map due to EOTW.\nVisit www.zorex.us to view SOTW info."); + /* 58 */ return; + /* */ } + /* */ + /* 61 */ UUID uuid = player.getUniqueId(); + /* 62 */ int lives = this.plugin.getDeathbanManager().getLives(uuid); + /* */ + /* 64 */ String formattedRemaining = DurationFormatter.getRemaining(deathban.getRemaining(), true, false); + /* */ + /* 66 */ if (lives <= 0) { + /* 67 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, + ChatColor.RED + "You are still Deathbanned \n Duration: " + ChatColor.WHITE + formattedRemaining); + /* */ + /* 70 */ return; + /* */ } + /* */ + /* 73 */ long millis = System.currentTimeMillis(); + /* 74 */ long lastAttemptedJoinMillis = this.lastAttemptedJoinMap.get(uuid); + /* */ + /* */ + /* 77 */ if ((lastAttemptedJoinMillis != this.lastAttemptedJoinMap.getNoEntryValue()) + && (lastAttemptedJoinMillis - millis < LIFE_USE_DELAY_MILLIS)) { + /* 78 */ this.lastAttemptedJoinMap.remove(uuid); + /* 79 */ user.removeDeathban(); + /* 80 */ lives = this.plugin.getDeathbanManager().takeLives(uuid, 1); + /* */ + /* 82 */ event.setResult(PlayerLoginEvent.Result.ALLOWED); + /* 83 */ new DelayedMessageRunnable(player, + ChatColor.YELLOW + "You have used a life for entry. You now have " + ChatColor.WHITE + lives + + ChatColor.YELLOW + " lives.").runTask(this.plugin); + /* */ + /* 85 */ return; + /* */ } + /* */ + /* */ + /* 89 */ String reason = deathban.getReason(); + /* 90 */ this.lastAttemptedJoinMap.put(uuid, millis + LIFE_USE_DELAY_MILLIS); + /* */ + /* 92 */ event.disallow(PlayerLoginEvent.Result.KICK_OTHER, ChatColor.RED + + "You are currently Deathbanned for Duration: " + ChatColor.WHITE + formattedRemaining + " \n" + + /* 93 */ ChatColor.RED + "You currently have " + ChatColor.WHITE + + (lives <= 0 ? "no" : Integer.valueOf(lives)) + " lives." + ChatColor.RED + + "You may use a life by reconnecting within " + ChatColor.WHITE + + /* 94 */ LIFE_USE_DELAY_WORDS + ChatColor.RED + "."); + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.LOW) + /* */ public void onPlayerDeath(PlayerDeathEvent event) { + /* 99 */ final Player player = event.getEntity(); + /* 100 */ final Deathban deathban = this.plugin.getDeathbanManager().applyDeathBan(player, + event.getDeathMessage()); + /* 101 */ long remaining = deathban.getRemaining(); + /* 102 */ if ((remaining <= 0L) || (player.hasPermission("hcf.deathban.bypass"))) { + /* 103 */ return; + /* */ } + /* */ + /* 106 */ if ((RESPAWN_KICK_DELAY_MILLIS <= 0L) || (remaining < RESPAWN_KICK_DELAY_MILLIS)) { + /* 107 */ handleKick(player, deathban); + /* 108 */ return; + /* */ } + /* */ + /* */ + /* 112 */ this.respawnTickTasks.put(player.getUniqueId(), new BukkitRunnable() + /* */ { + /* */ @Override + public void run() { + /* 115 */ DeathbanListener.this.handleKick(player, deathban); + /* */ } + /* 117 */ }.runTaskLater(this.plugin, RESPAWN_KICK_DELAY_TICKS).getTaskId()); + /* */ } + + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + /* */ public void onPlayerRequestRespawn(PlayerRespawnEvent event) { + /* 122 */ Player player = event.getPlayer(); + /* 123 */ FactionUser user = this.plugin.getUserManager().getUser(player.getUniqueId()); + /* 124 */ Deathban deathban = user.getDeathban(); + /* 125 */ if ((deathban != null) && (deathban.getRemaining() > 0L)) { + /* 126 */ if (player.hasPermission("hcf.deathban.bypass")) { + /* 127 */ cancelRespawnKickTask(player); + /* 128 */ user.removeDeathban(); + /* 129 */ new DelayedMessageRunnable(player, ChatColor.RED + "Bypass access granted.") + .runTask(this.plugin); + /* */ + /* 131 */ return; + /* */ } + /* */ + /* */ + /* */ + /* 136 */ handleKick(player, deathban); + /* */ } + /* */ } + + /* */ + /* */ + /* */ @EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR) + /* */ public void onPlayerQuit(PlayerQuitEvent event) + /* */ { + /* 144 */ cancelRespawnKickTask(event.getPlayer()); + /* */ } + + /* */ + /* */ private void cancelRespawnKickTask(Player player) { + /* 148 */ int taskId = this.respawnTickTasks.remove(player.getUniqueId()); + /* 149 */ if (taskId != this.respawnTickTasks.getNoEntryValue()) { + /* 150 */ org.bukkit.Bukkit.getScheduler().cancelTask(taskId); + /* */ } + /* */ } + + /* */ + /* */ private void handleKick(Player player, Deathban deathban) { + /* 155 */ if (this.plugin.getEotwHandler().isEndOfTheWorld()) { + /* 156 */ player.kickPlayer(ChatColor.RED + + "Deathbanned for the entirety of the map due to EOTW.\nVisit www.zorex.us for SOTW info!"); + /* */ } else { + /* 158 */ player.kickPlayer(ChatColor.RED + "You are now Deathbanned \n Duration: " + ChatColor.WHITE + + DurationFormatter.getRemaining(deathban.getRemaining(), true, false) + " " + ChatColor.WHITE + + deathban.getReason()); + /* */ } + /* */ } + /* */ } diff --git a/src/me/bruce/factions/deathban/DeathbanManager.java b/src/me/bruce/factions/deathban/DeathbanManager.java new file mode 100644 index 0000000..43ef5fc --- /dev/null +++ b/src/me/bruce/factions/deathban/DeathbanManager.java @@ -0,0 +1,102 @@ +package me.bruce.factions.deathban; + +import gnu.trove.map.TObjectIntMap; +import org.bukkit.entity.Player; + +import java.util.UUID; +import java.util.concurrent.TimeUnit; + +public interface DeathbanManager { + + long MAX_DEATHBAN_TIME = TimeUnit.HOURS.toMillis(3); + + /** + * Gets the map storing the lives with the {@link UUID} string by the amount. + * + * @return the lives map + */ + TObjectIntMap getLivesMap(); + + /** + * Gets the lives of a player. + * + * @param uuid + * the uuid of player to get for + * @return the amount of owned lives + */ + int getLives(UUID uuid); + + /** + * Sets the amount of lives a player has. + * + * @param uuid + * the uuid of player to set for + * @param amount + * the amount to set at + * @return the new lives of the player + */ + int setLives(UUID uuid, int amount); + + /** + * Gives lives to a player. + * + * @param uuid + * the uuid of player to give to + * @param amount + * the amount to give + * @return the new lives of the player + */ + int addLives(UUID uuid, int amount); + + /** + * Takes lives away from a player. + * + * @param uuid + * the uuid of player to take for + * @param amount + * the amount to take + * @return the new lives of the player + */ + int takeLives(UUID uuid, int amount); + + /** + * Gets the deathban multiplier for a {@link Player}. + * + * @param player + * the {@link Player} to get for + * @return the deathban multiplier + */ + double getDeathBanMultiplier(Player player); + + /** + * Applies a {@link Deathban} to a {@link Player}. + * + * @param player + * the {@link Player} to apply to + * @param reason + * the reason for {@link Deathban} + * @return the {@link Deathban} that has been applied + */ + Deathban applyDeathBan(Player player, String reason); + + /** + * Applies a {@link Deathban} to a {@link Player}. + * + * @param uuid + * the uuid of player to apply to + * @param deathban + * the {@link Deathban} to be applied + * @return the {@link Deathban} that has been applied + */ + Deathban applyDeathBan(UUID uuid, Deathban deathban); + + /** + * Reloads deathban data from storage. + */ + void reloadDeathbanData(); + + /** + * Saves deathban data to storage. + */ + void saveDeathbanData(); +} diff --git a/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java b/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java new file mode 100644 index 0000000..61cb846 --- /dev/null +++ b/src/me/bruce/factions/deathban/FlatFileDeathbanManager.java @@ -0,0 +1,145 @@ +package me.bruce.factions.deathban; + +import gnu.trove.impl.Constants; +import gnu.trove.map.TObjectIntMap; +import gnu.trove.map.hash.TObjectIntHashMap; +import gnu.trove.procedure.TObjectIntProcedure; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.type.Faction; +import me.bruce.factions.ymls.SettingsYML; + +import org.bukkit.Location; +import org.bukkit.configuration.MemorySection; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.Config; +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.PersistableLocation; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + +public class FlatFileDeathbanManager implements DeathbanManager { + + private static final int MAX_DEATHBAN_MULTIPLIER = 300; + + private final LorexHCF plugin; + + private TObjectIntMap livesMap; + private Config livesConfig; + + public FlatFileDeathbanManager(LorexHCF plugin) { + this.plugin = plugin; + this.reloadDeathbanData(); + } + + @Override + public TObjectIntMap getLivesMap() { + return livesMap; + } + + @Override + public int getLives(UUID uuid) { + return livesMap.get(uuid); + } + + @Override + public int setLives(UUID uuid, int lives) { + livesMap.put(uuid, lives); + return lives; + } + + @Override + public int addLives(UUID uuid, int amount) { + return livesMap.adjustOrPutValue(uuid, amount, amount); + } + + @Override + public int takeLives(UUID uuid, int amount) { + return setLives(uuid, getLives(uuid) - amount); + } + + @Override + public double getDeathBanMultiplier(final Player player) { + for (int i = 5; i < 300; ++i) { + if (player.hasPermission("hcf.deathban.multiplier." + i)) { + return i / 100.0; + } + } + return 1.0; + } + + @Override + public Deathban applyDeathBan(Player player, String reason) { + Location location = player.getLocation(); + Faction factionAt = plugin.getFactionManager().getFactionAt(location); + + long duration = SettingsYML.DEFAULT_DEATHBAN_DURATION; + if (!factionAt.isDeathban()) { + duration /= 2; // non-deathban factions should be 50% qui + + } else if (player.hasPermission("hcf.deathban.rank.bronze")) { + duration = JavaUtils.parse("90m"); + } else if (player.hasPermission("hcf.deathban.rank.silver")) { + duration = JavaUtils.parse("75m"); + } else if (player.hasPermission("hcf.deathban.rank.cobalt")) { + duration = JavaUtils.parse("60m"); + } else if (player.hasPermission("hcf.deathban.rank.ruby")) { + duration = JavaUtils.parse("40m"); + } else if (player.hasPermission("hcf.deathban.rank.sapphire")) { + duration = JavaUtils.parse("30m"); + } else if (player.hasPermission("hcf.deathban.rank.titanium")) { + duration = JavaUtils.parse("20m"); + } else if (player.hasPermission("hcf.deathban.rank.amethyst")) { + duration = JavaUtils.parse("10m"); + } else if (player.hasPermission("hcf.deathban.rank.riots")) { + duration = JavaUtils.parse("5m"); + } else if (player.hasPermission("hcf.deathban.rank.default")) { + duration = JavaUtils.parse("120m"); + } + + duration *= getDeathBanMultiplier(player); + duration *= factionAt.getDeathbanMultiplier(); + return applyDeathBan(player.getUniqueId(), + new Deathban(reason, Math.min(MAX_DEATHBAN_TIME, duration), new PersistableLocation(location))); + } + + @Override + public Deathban applyDeathBan(UUID uuid, Deathban deathban) { + plugin.getUserManager().getUser(uuid).setDeathban(deathban); + return deathban; + } + + @Override + public void reloadDeathbanData() { + livesConfig = new Config(plugin, "lives"); + Object object = livesConfig.get("lives"); + if (object instanceof MemorySection) { + MemorySection section = (MemorySection) object; + Set keys = section.getKeys(false); + livesMap = new TObjectIntHashMap<>(keys.size(), Constants.DEFAULT_LOAD_FACTOR, 0); + for (String id : keys) { + livesMap.put(UUID.fromString(id), livesConfig.getInt(section.getCurrentPath() + "." + id)); + } + } else { + livesMap = new TObjectIntHashMap<>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, 0); + } + } + + @Override + public void saveDeathbanData() { + Map saveMap = new LinkedHashMap<>(livesMap.size()); + livesMap.forEachEntry(new TObjectIntProcedure() { + @Override + public boolean execute(UUID uuid, int i) { + saveMap.put(uuid.toString(), i); + return true; + } + }); + + livesConfig.set("lives", saveMap); + livesConfig.save(); + } +} diff --git a/src/me/bruce/factions/deathban/StaffReviveCommand.java b/src/me/bruce/factions/deathban/StaffReviveCommand.java new file mode 100644 index 0000000..17ea4b7 --- /dev/null +++ b/src/me/bruce/factions/deathban/StaffReviveCommand.java @@ -0,0 +1,84 @@ +package me.bruce.factions.deathban; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandExecutor; +import org.bukkit.command.CommandSender; +import org.bukkit.command.TabCompleter; + +import LorexMC.us.utils.BukkitUtils; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.faction.FactionUser; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.UUID; + +public class StaffReviveCommand implements CommandExecutor, TabCompleter { + + private final LorexHCF plugin; + + public StaffReviveCommand(LorexHCF plugin) { + this.plugin = plugin; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 1) { + sender.sendMessage(ChatColor.RED + "Usage: /" + label + " "); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[0]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[0] + ChatColor.GOLD + "' not found."); + return true; + } + + UUID targetUUID = target.getUniqueId(); + FactionUser factionTarget = LorexHCF.getInstance().getUserManager().getUser(targetUUID); + Deathban deathban = factionTarget.getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + factionTarget.removeDeathban(); + Command.broadcastCommandMessage(sender, ChatColor.LIGHT_PURPLE + "Staff revived " + target.getName() + "."); + // sender.sendMessage(ChatColor.GREEN +"You have revived: " + target.getName() + + // ChatColor.GRAY + ChatColor.ITALIC + "(Click here to refund + // items)").setHoverText(ChatColor.GREEN + "Click here to refund items for: " + + // ChatColor.GRAY + + // target.getPlayer().getName().setClick(ClickAction.RUN_COMMAND, "/inv " + + // target.getPlayer().getName())); + return false; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 1) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + for (FactionUser factionUser : plugin.getUserManager().getUsers().values()) { + Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String name = offlinePlayer.getName(); + if (name != null) { + results.add(name); + } + } + } + + return BukkitUtils.getCompletions(args, results); + } + +} diff --git a/src/me/bruce/factions/deathban/lives/LivesExecutor.java b/src/me/bruce/factions/deathban/lives/LivesExecutor.java new file mode 100644 index 0000000..701a78a --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/LivesExecutor.java @@ -0,0 +1,23 @@ +package me.bruce.factions.deathban.lives; + +import LorexMC.us.utils.other.command.ArgumentExecutor; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.lives.args.*; + +/** + * Handles the execution and tab completion of the lives command. + */ +public class LivesExecutor extends ArgumentExecutor { + + public LivesExecutor(LorexHCF plugin) { + super("lives"); + + addArgument(new LivesCheckArgument(plugin)); + addArgument(new LivesCheckDeathbanArgument(plugin)); + addArgument(new LivesClearDeathbansArgument(plugin)); + addArgument(new LivesGiveArgument(plugin)); + addArgument(new LivesReviveArgument(plugin)); + addArgument(new LivesSetArgument(plugin)); + addArgument(new LivesSetDeathbanTimeArgument()); + } +} \ No newline at end of file diff --git a/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java new file mode 100644 index 0000000..0dca97a --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesCheckArgument.java @@ -0,0 +1,63 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to check how many lives a {@link Player} has. + */ +public class LivesCheckArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesCheckArgument(LorexHCF plugin) { + super("check", "Check how much lives a player has"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + OfflinePlayer target; + if (args.length > 1) { + target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + } else if (sender instanceof Player) { + target = (Player) sender; + } else { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + int targetLives = plugin.getDeathbanManager().getLives(target.getUniqueId()); + + sender.sendMessage(target.getName() + ChatColor.YELLOW + " has " + ChatColor.LIGHT_PURPLE + targetLives + + ChatColor.YELLOW + ' ' + (targetLives == 1 ? "life" : "lives") + '.'); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java new file mode 100644 index 0000000..762d594 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesCheckDeathbanArgument.java @@ -0,0 +1,101 @@ +package me.bruce.factions.deathban.lives.args; + +import com.google.common.base.Strings; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.listener.DateTimeFormats; + +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.Location; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to check the {@link Deathban} of a + * {@link Player}. + */ +public class LivesCheckDeathbanArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesCheckDeathbanArgument(LorexHCF plugin) { + super("checkdeathban", "Check the deathban cause of player"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + Deathban deathban = plugin.getUserManager().getUser(target.getUniqueId()).getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + sender.sendMessage(ChatColor.DARK_AQUA + "Deathban cause of " + target.getName() + '.'); + sender.sendMessage(ChatColor.GRAY + " Time: " + DateTimeFormats.HR_MIN.format(deathban.getCreationMillis())); + sender.sendMessage(ChatColor.GRAY + " Duration: " + + DurationFormatUtils.formatDurationWords(deathban.getInitialDuration(), true, true)); + + Location location = deathban.getDeathPoint(); + if (location != null) { + sender.sendMessage(ChatColor.GRAY + " Location: (" + location.getBlockX() + ", " + location.getBlockY() + + ", " + location.getBlockZ() + ") - " + location.getWorld().getName()); + } + + sender.sendMessage( + ChatColor.GRAY + " Reason: [" + Strings.nullToEmpty(deathban.getReason()) + ChatColor.GREEN + "]"); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + for (FactionUser factionUser : plugin.getUserManager().getUsers().values()) { + Deathban deathban = factionUser.getDeathban(); + if (deathban != null && deathban.isActive()) { + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String name = offlinePlayer.getName(); + if (name != null) { + results.add(name); + } + } + } + + return results; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java new file mode 100644 index 0000000..71b0010 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesClearDeathbansArgument.java @@ -0,0 +1,40 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; + +/** + * An {@link CommandArgument} used to clear all {@link Deathban}s. + */ +public class LivesClearDeathbansArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesClearDeathbansArgument(LorexHCF plugin) { + super("cleardeathbans", "Clears the global deathbans"); + this.plugin = plugin; + this.aliases = new String[] { "resetdeathbans" }; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName(); + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + for (FactionUser user : plugin.getUserManager().getUsers().values()) { + user.removeDeathban(); + } + + Command.broadcastCommandMessage(sender, ChatColor.YELLOW + "All death-bans have been cleared."); + return true; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java new file mode 100644 index 0000000..f2e9d91 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesGiveArgument.java @@ -0,0 +1,82 @@ +package me.bruce.factions.deathban.lives.args; + +import me.bruce.factions.LorexHCF; +import com.google.common.primitives.Ints; + +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.other.command.CommandArgument; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import java.util.Collections; +import java.util.List; + +public class LivesGiveArgument extends CommandArgument { + private final LorexHCF plugin; + private static final String PERMISSION = "hcf.command.lives.argument.give.bypass"; + + public LivesGiveArgument(LorexHCF plugin) { + super("give", "Help someone out by giving them live(s)"); + this.plugin = plugin; + this.aliases = new String[] { "transfer", "send", "pay", "add" }; + this.permission = "hcf.command.lives.argument." + this.getName(); + } + + @Override + public String getUsage(String label) { + return "" + '/' + label + ' ' + this.getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + this.getUsage(label)); + return true; + } + Integer amount = Ints.tryParse(args[2]); + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + if (amount <= 0) { + sender.sendMessage(ChatColor.RED + "The amount of lives must be positive."); + return true; + } + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1])); + return true; + } + Player onlineTarget = target.getPlayer(); + if (sender instanceof Player && !sender.hasPermission(PERMISSION)) { + Player player = (Player) sender; + int ownedLives = this.plugin.getDeathbanManager().getLives(player.getUniqueId()); + if (amount > ownedLives) { + sender.sendMessage(ChatColor.RED + "You tried to give " + target.getName() + ' ' + amount + + " lives, but you only have " + ownedLives + '.'); + return true; + } + this.plugin.getDeathbanManager().takeLives(player.getUniqueId(), amount); + } + final int targetLives = this.plugin.getDeathbanManager().getLives(target.getUniqueId()); + this.plugin.getDeathbanManager().addLives(target.getUniqueId(), amount); + sender.sendMessage(ChatColor.YELLOW + "You have sent " + ChatColor.GOLD + target.getName() + ChatColor.YELLOW + + ' ' + amount + ' ' + (amount > 1 ? "life" : "lives") + '.'); + sender.sendMessage(ChatColor.GREEN + "Remaining Lives: " + ChatColor.RED + targetLives + ChatColor.RED + ' ' + + ((targetLives == 1) ? "life" : "lives") + '.'); + if (onlineTarget != null) { + onlineTarget.sendMessage(ChatColor.GOLD + sender.getName() + ChatColor.YELLOW + " has sent you " + + ChatColor.GOLD + amount + ' ' + (amount > 1 ? "life" : "lives") + '.'); + } + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java new file mode 100644 index 0000000..d966672 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesReviveArgument.java @@ -0,0 +1,140 @@ +package me.bruce.factions.deathban.lives.args; + +import com.google.common.io.ByteArrayDataOutput; +import com.google.common.io.ByteStreams; + +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.faction.FactionUser; +import me.bruce.factions.faction.struct.Relation; +import me.bruce.factions.faction.type.PlayerFaction; +import me.bruce.factions.ymls.SettingsYML; + +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.plugin.messaging.PluginMessageRecipient; + +import java.util.*; + +/** + * An {@link CommandArgument} used to revive {@link Deathban}ned + * {@link Player}s. + */ +public class LivesReviveArgument extends CommandArgument { + + private static final String REVIVE_BYPASS_PERMISSION = "hcf.revive.bypass"; + private static final String PROXY_CHANNEL_NAME = "BungeeCord"; + + private final LorexHCF plugin; + + public LivesReviveArgument(LorexHCF plugin) { + super("revive", "Revive a death-banned player"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, PROXY_CHANNEL_NAME); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + ArrayList cooldown = new ArrayList(); + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 2) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + OfflinePlayer target = Bukkit.getOfflinePlayer(args[1]); // TODO: breaking + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage( + ChatColor.GOLD + "Player '" + ChatColor.WHITE + args[1] + ChatColor.GOLD + "' not found."); + return true; + } + + UUID targetUUID = target.getUniqueId(); + FactionUser factionTarget = plugin.getUserManager().getUser(targetUUID); + Deathban deathban = factionTarget.getDeathban(); + + if (deathban == null || !deathban.isActive()) { + sender.sendMessage(ChatColor.RED + target.getName() + " is not death-banned."); + return true; + } + + Relation relation = Relation.ENEMY; + if (sender instanceof Player) { + if (!sender.hasPermission(REVIVE_BYPASS_PERMISSION)) { + if (plugin.getEotwHandler().isEndOfTheWorld()) { + sender.sendMessage(ChatColor.RED + "You cannot revive players during EOTW."); + return true; + } + } + + Player player = (Player) sender; + UUID playerUUID = player.getUniqueId(); + int selfLives = plugin.getDeathbanManager().getLives(playerUUID); + + if (selfLives <= 0) { + sender.sendMessage(ChatColor.RED + "You do not have any lives."); + return true; + } + + plugin.getDeathbanManager().setLives(playerUUID, selfLives - 1); + PlayerFaction playerFaction = plugin.getFactionManager().getPlayerFaction(player); + relation = playerFaction == null ? Relation.ENEMY + : playerFaction.getFactionRelation(plugin.getFactionManager().getPlayerFaction(targetUUID)); + sender.sendMessage(ChatColor.YELLOW + "You have used a life to revive " + relation.toChatColour() + + target.getName() + ChatColor.YELLOW + '.'); + } else { + sender.sendMessage(ChatColor.YELLOW + "You have revived " + SettingsYML.ENEMY_COLOUR + target.getName() + + ChatColor.YELLOW + '.'); + } + + if (sender instanceof PluginMessageRecipient) { + // NOTE: This server needs at least 1 player online. + ByteArrayDataOutput out = ByteStreams.newDataOutput(); + out.writeUTF("Message"); + out.writeUTF(args[1]); + + String serverDisplayName = ChatColor.GREEN + "LorexHCF"; // TODO: Non hard-coded server display name. + out.writeUTF(relation.toChatColour() + sender.getName() + ChatColor.GOLD + " has just revived you from " + + serverDisplayName + ChatColor.GOLD + '.'); + ((PluginMessageRecipient) sender).sendPluginMessage(plugin, PROXY_CHANNEL_NAME, out.toByteArray()); + } + + factionTarget.removeDeathban(); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + if (args.length != 2) { + return Collections.emptyList(); + } + + List results = new ArrayList<>(); + Collection factionUsers = plugin.getUserManager().getUsers().values(); + for (FactionUser factionUser : factionUsers) { + Deathban deathban = factionUser.getDeathban(); + if (deathban == null || !deathban.isActive()) + continue; + + OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(factionUser.getUserUUID()); + String offlineName = offlinePlayer.getName(); + if (offlineName != null) { + results.add(offlinePlayer.getName()); + } + } + + return results; + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java new file mode 100644 index 0000000..dc87da1 --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesSetArgument.java @@ -0,0 +1,68 @@ +package me.bruce.factions.deathban.lives.args; + +import org.bukkit.ChatColor; +import org.bukkit.OfflinePlayer; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import LorexMC.us.utils.BukkitUtils; +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.internal.com.bruce.base.BaseConstants; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.LorexHCF; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to set the lives of {@link Player}s. + */ +public class LivesSetArgument extends CommandArgument { + + private final LorexHCF plugin; + + public LivesSetArgument(LorexHCF plugin) { + super("set", "Set how much lives a player has"); + this.plugin = plugin; + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + " "; + } + + @Override + public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { + if (args.length < 3) { + sender.sendMessage(ChatColor.RED + "Usage: " + getUsage(label)); + return true; + } + + Integer amount = JavaUtils.tryParseInt(args[2]); + + if (amount == null) { + sender.sendMessage(ChatColor.RED + "'" + args[2] + "' is not a number."); + return true; + } + + OfflinePlayer target = BukkitUtils.offlinePlayerWithNameOrUUID(args[1]); + + if (!target.hasPlayedBefore() && !target.isOnline()) { + sender.sendMessage(String.format(BaseConstants.PLAYER_WITH_NAME_OR_UUID_NOT_FOUND, args[1])); + return true; + } + + plugin.getDeathbanManager().setLives(target.getUniqueId(), amount); + + sender.sendMessage(ChatColor.YELLOW + target.getName() + " now has " + ChatColor.GOLD + amount + + ChatColor.YELLOW + " lives."); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, Command command, String label, String[] args) { + return args.length == 2 ? null : Collections.emptyList(); + } +} diff --git a/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java b/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java new file mode 100644 index 0000000..7a2c54e --- /dev/null +++ b/src/me/bruce/factions/deathban/lives/args/LivesSetDeathbanTimeArgument.java @@ -0,0 +1,57 @@ +package me.bruce.factions.deathban.lives.args; + +import org.apache.commons.lang3.time.DurationFormatUtils; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +import LorexMC.us.utils.JavaUtils; +import LorexMC.us.utils.other.command.CommandArgument; +import me.bruce.factions.deathban.Deathban; +import me.bruce.factions.ymls.SettingsYML; + +import java.util.Collections; +import java.util.List; + +/** + * An {@link CommandArgument} used to set the base {@link Deathban} time, not + * including multipliers, etc. + */ +public class LivesSetDeathbanTimeArgument extends CommandArgument { + + public LivesSetDeathbanTimeArgument() { + super("setdeathbantime", "Sets the base deathban time"); + this.permission = "hcf.command.lives.argument." + getName(); + } + + @Override + public String getUsage(String label) { + return '/' + label + ' ' + getName() + "