···11+GNU GENERAL PUBLIC LICENSE
22+ Version 3, 29 June 2007
33+44+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
55+ Everyone is permitted to copy and distribute verbatim copies
66+ of this license document, but changing it is not allowed.
77+88+ Preamble
99+1010+ The GNU General Public License is a free, copyleft license for
1111+software and other kinds of works.
1212+1313+ The licenses for most software and other practical works are designed
1414+to take away your freedom to share and change the works. By contrast,
1515+the GNU General Public License is intended to guarantee your freedom to
1616+share and change all versions of a program--to make sure it remains free
1717+software for all its users. We, the Free Software Foundation, use the
1818+GNU General Public License for most of our software; it applies also to
1919+any other work released this way by its authors. You can apply it to
2020+your programs, too.
2121+2222+ When we speak of free software, we are referring to freedom, not
2323+price. Our General Public Licenses are designed to make sure that you
2424+have the freedom to distribute copies of free software (and charge for
2525+them if you wish), that you receive source code or can get it if you
2626+want it, that you can change the software or use pieces of it in new
2727+free programs, and that you know you can do these things.
2828+2929+ To protect your rights, we need to prevent others from denying you
3030+these rights or asking you to surrender the rights. Therefore, you have
3131+certain responsibilities if you distribute copies of the software, or if
3232+you modify it: responsibilities to respect the freedom of others.
3333+3434+ For example, if you distribute copies of such a program, whether
3535+gratis or for a fee, you must pass on to the recipients the same
3636+freedoms that you received. You must make sure that they, too, receive
3737+or can get the source code. And you must show them these terms so they
3838+know their rights.
3939+4040+ Developers that use the GNU GPL protect your rights with two steps:
4141+(1) assert copyright on the software, and (2) offer you this License
4242+giving you legal permission to copy, distribute and/or modify it.
4343+4444+ For the developers' and authors' protection, the GPL clearly explains
4545+that there is no warranty for this free software. For both users' and
4646+authors' sake, the GPL requires that modified versions be marked as
4747+changed, so that their problems will not be attributed erroneously to
4848+authors of previous versions.
4949+5050+ Some devices are designed to deny users access to install or run
5151+modified versions of the software inside them, although the manufacturer
5252+can do so. This is fundamentally incompatible with the aim of
5353+protecting users' freedom to change the software. The systematic
5454+pattern of such abuse occurs in the area of products for individuals to
5555+use, which is precisely where it is most unacceptable. Therefore, we
5656+have designed this version of the GPL to prohibit the practice for those
5757+products. If such problems arise substantially in other domains, we
5858+stand ready to extend this provision to those domains in future versions
5959+of the GPL, as needed to protect the freedom of users.
6060+6161+ Finally, every program is threatened constantly by software patents.
6262+States should not allow patents to restrict development and use of
6363+software on general-purpose computers, but in those that do, we wish to
6464+avoid the special danger that patents applied to a free program could
6565+make it effectively proprietary. To prevent this, the GPL assures that
6666+patents cannot be used to render the program non-free.
6767+6868+ The precise terms and conditions for copying, distribution and
6969+modification follow.
7070+7171+ TERMS AND CONDITIONS
7272+7373+ 0. Definitions.
7474+7575+ "This License" refers to version 3 of the GNU General Public License.
7676+7777+ "Copyright" also means copyright-like laws that apply to other kinds of
7878+works, such as semiconductor masks.
7979+8080+ "The Program" refers to any copyrightable work licensed under this
8181+License. Each licensee is addressed as "you". "Licensees" and
8282+"recipients" may be individuals or organizations.
8383+8484+ To "modify" a work means to copy from or adapt all or part of the work
8585+in a fashion requiring copyright permission, other than the making of an
8686+exact copy. The resulting work is called a "modified version" of the
8787+earlier work or a work "based on" the earlier work.
8888+8989+ A "covered work" means either the unmodified Program or a work based
9090+on the Program.
9191+9292+ To "propagate" a work means to do anything with it that, without
9393+permission, would make you directly or secondarily liable for
9494+infringement under applicable copyright law, except executing it on a
9595+computer or modifying a private copy. Propagation includes copying,
9696+distribution (with or without modification), making available to the
9797+public, and in some countries other activities as well.
9898+9999+ To "convey" a work means any kind of propagation that enables other
100100+parties to make or receive copies. Mere interaction with a user through
101101+a computer network, with no transfer of a copy, is not conveying.
102102+103103+ An interactive user interface displays "Appropriate Legal Notices"
104104+to the extent that it includes a convenient and prominently visible
105105+feature that (1) displays an appropriate copyright notice, and (2)
106106+tells the user that there is no warranty for the work (except to the
107107+extent that warranties are provided), that licensees may convey the
108108+work under this License, and how to view a copy of this License. If
109109+the interface presents a list of user commands or options, such as a
110110+menu, a prominent item in the list meets this criterion.
111111+112112+ 1. Source Code.
113113+114114+ The "source code" for a work means the preferred form of the work
115115+for making modifications to it. "Object code" means any non-source
116116+form of a work.
117117+118118+ A "Standard Interface" means an interface that either is an official
119119+standard defined by a recognized standards body, or, in the case of
120120+interfaces specified for a particular programming language, one that
121121+is widely used among developers working in that language.
122122+123123+ The "System Libraries" of an executable work include anything, other
124124+than the work as a whole, that (a) is included in the normal form of
125125+packaging a Major Component, but which is not part of that Major
126126+Component, and (b) serves only to enable use of the work with that
127127+Major Component, or to implement a Standard Interface for which an
128128+implementation is available to the public in source code form. A
129129+"Major Component", in this context, means a major essential component
130130+(kernel, window system, and so on) of the specific operating system
131131+(if any) on which the executable work runs, or a compiler used to
132132+produce the work, or an object code interpreter used to run it.
133133+134134+ The "Corresponding Source" for a work in object code form means all
135135+the source code needed to generate, install, and (for an executable
136136+work) run the object code and to modify the work, including scripts to
137137+control those activities. However, it does not include the work's
138138+System Libraries, or general-purpose tools or generally available free
139139+programs which are used unmodified in performing those activities but
140140+which are not part of the work. For example, Corresponding Source
141141+includes interface definition files associated with source files for
142142+the work, and the source code for shared libraries and dynamically
143143+linked subprograms that the work is specifically designed to require,
144144+such as by intimate data communication or control flow between those
145145+subprograms and other parts of the work.
146146+147147+ The Corresponding Source need not include anything that users
148148+can regenerate automatically from other parts of the Corresponding
149149+Source.
150150+151151+ The Corresponding Source for a work in source code form is that
152152+same work.
153153+154154+ 2. Basic Permissions.
155155+156156+ All rights granted under this License are granted for the term of
157157+copyright on the Program, and are irrevocable provided the stated
158158+conditions are met. This License explicitly affirms your unlimited
159159+permission to run the unmodified Program. The output from running a
160160+covered work is covered by this License only if the output, given its
161161+content, constitutes a covered work. This License acknowledges your
162162+rights of fair use or other equivalent, as provided by copyright law.
163163+164164+ You may make, run and propagate covered works that you do not
165165+convey, without conditions so long as your license otherwise remains
166166+in force. You may convey covered works to others for the sole purpose
167167+of having them make modifications exclusively for you, or provide you
168168+with facilities for running those works, provided that you comply with
169169+the terms of this License in conveying all material for which you do
170170+not control copyright. Those thus making or running the covered works
171171+for you must do so exclusively on your behalf, under your direction
172172+and control, on terms that prohibit them from making any copies of
173173+your copyrighted material outside their relationship with you.
174174+175175+ Conveying under any other circumstances is permitted solely under
176176+the conditions stated below. Sublicensing is not allowed; section 10
177177+makes it unnecessary.
178178+179179+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180180+181181+ No covered work shall be deemed part of an effective technological
182182+measure under any applicable law fulfilling obligations under article
183183+11 of the WIPO copyright treaty adopted on 20 December 1996, or
184184+similar laws prohibiting or restricting circumvention of such
185185+measures.
186186+187187+ When you convey a covered work, you waive any legal power to forbid
188188+circumvention of technological measures to the extent such circumvention
189189+is effected by exercising rights under this License with respect to
190190+the covered work, and you disclaim any intention to limit operation or
191191+modification of the work as a means of enforcing, against the work's
192192+users, your or third parties' legal rights to forbid circumvention of
193193+technological measures.
194194+195195+ 4. Conveying Verbatim Copies.
196196+197197+ You may convey verbatim copies of the Program's source code as you
198198+receive it, in any medium, provided that you conspicuously and
199199+appropriately publish on each copy an appropriate copyright notice;
200200+keep intact all notices stating that this License and any
201201+non-permissive terms added in accord with section 7 apply to the code;
202202+keep intact all notices of the absence of any warranty; and give all
203203+recipients a copy of this License along with the Program.
204204+205205+ You may charge any price or no price for each copy that you convey,
206206+and you may offer support or warranty protection for a fee.
207207+208208+ 5. Conveying Modified Source Versions.
209209+210210+ You may convey a work based on the Program, or the modifications to
211211+produce it from the Program, in the form of source code under the
212212+terms of section 4, provided that you also meet all of these conditions:
213213+214214+ a) The work must carry prominent notices stating that you modified
215215+ it, and giving a relevant date.
216216+217217+ b) The work must carry prominent notices stating that it is
218218+ released under this License and any conditions added under section
219219+ 7. This requirement modifies the requirement in section 4 to
220220+ "keep intact all notices".
221221+222222+ c) You must license the entire work, as a whole, under this
223223+ License to anyone who comes into possession of a copy. This
224224+ License will therefore apply, along with any applicable section 7
225225+ additional terms, to the whole of the work, and all its parts,
226226+ regardless of how they are packaged. This License gives no
227227+ permission to license the work in any other way, but it does not
228228+ invalidate such permission if you have separately received it.
229229+230230+ d) If the work has interactive user interfaces, each must display
231231+ Appropriate Legal Notices; however, if the Program has interactive
232232+ interfaces that do not display Appropriate Legal Notices, your
233233+ work need not make them do so.
234234+235235+ A compilation of a covered work with other separate and independent
236236+works, which are not by their nature extensions of the covered work,
237237+and which are not combined with it such as to form a larger program,
238238+in or on a volume of a storage or distribution medium, is called an
239239+"aggregate" if the compilation and its resulting copyright are not
240240+used to limit the access or legal rights of the compilation's users
241241+beyond what the individual works permit. Inclusion of a covered work
242242+in an aggregate does not cause this License to apply to the other
243243+parts of the aggregate.
244244+245245+ 6. Conveying Non-Source Forms.
246246+247247+ You may convey a covered work in object code form under the terms
248248+of sections 4 and 5, provided that you also convey the
249249+machine-readable Corresponding Source under the terms of this License,
250250+in one of these ways:
251251+252252+ a) Convey the object code in, or embodied in, a physical product
253253+ (including a physical distribution medium), accompanied by the
254254+ Corresponding Source fixed on a durable physical medium
255255+ customarily used for software interchange.
256256+257257+ b) Convey the object code in, or embodied in, a physical product
258258+ (including a physical distribution medium), accompanied by a
259259+ written offer, valid for at least three years and valid for as
260260+ long as you offer spare parts or customer support for that product
261261+ model, to give anyone who possesses the object code either (1) a
262262+ copy of the Corresponding Source for all the software in the
263263+ product that is covered by this License, on a durable physical
264264+ medium customarily used for software interchange, for a price no
265265+ more than your reasonable cost of physically performing this
266266+ conveying of source, or (2) access to copy the
267267+ Corresponding Source from a network server at no charge.
268268+269269+ c) Convey individual copies of the object code with a copy of the
270270+ written offer to provide the Corresponding Source. This
271271+ alternative is allowed only occasionally and noncommercially, and
272272+ only if you received the object code with such an offer, in accord
273273+ with subsection 6b.
274274+275275+ d) Convey the object code by offering access from a designated
276276+ place (gratis or for a charge), and offer equivalent access to the
277277+ Corresponding Source in the same way through the same place at no
278278+ further charge. You need not require recipients to copy the
279279+ Corresponding Source along with the object code. If the place to
280280+ copy the object code is a network server, the Corresponding Source
281281+ may be on a different server (operated by you or a third party)
282282+ that supports equivalent copying facilities, provided you maintain
283283+ clear directions next to the object code saying where to find the
284284+ Corresponding Source. Regardless of what server hosts the
285285+ Corresponding Source, you remain obligated to ensure that it is
286286+ available for as long as needed to satisfy these requirements.
287287+288288+ e) Convey the object code using peer-to-peer transmission, provided
289289+ you inform other peers where the object code and Corresponding
290290+ Source of the work are being offered to the general public at no
291291+ charge under subsection 6d.
292292+293293+ A separable portion of the object code, whose source code is excluded
294294+from the Corresponding Source as a System Library, need not be
295295+included in conveying the object code work.
296296+297297+ A "User Product" is either (1) a "consumer product", which means any
298298+tangible personal property which is normally used for personal, family,
299299+or household purposes, or (2) anything designed or sold for incorporation
300300+into a dwelling. In determining whether a product is a consumer product,
301301+doubtful cases shall be resolved in favor of coverage. For a particular
302302+product received by a particular user, "normally used" refers to a
303303+typical or common use of that class of product, regardless of the status
304304+of the particular user or of the way in which the particular user
305305+actually uses, or expects or is expected to use, the product. A product
306306+is a consumer product regardless of whether the product has substantial
307307+commercial, industrial or non-consumer uses, unless such uses represent
308308+the only significant mode of use of the product.
309309+310310+ "Installation Information" for a User Product means any methods,
311311+procedures, authorization keys, or other information required to install
312312+and execute modified versions of a covered work in that User Product from
313313+a modified version of its Corresponding Source. The information must
314314+suffice to ensure that the continued functioning of the modified object
315315+code is in no case prevented or interfered with solely because
316316+modification has been made.
317317+318318+ If you convey an object code work under this section in, or with, or
319319+specifically for use in, a User Product, and the conveying occurs as
320320+part of a transaction in which the right of possession and use of the
321321+User Product is transferred to the recipient in perpetuity or for a
322322+fixed term (regardless of how the transaction is characterized), the
323323+Corresponding Source conveyed under this section must be accompanied
324324+by the Installation Information. But this requirement does not apply
325325+if neither you nor any third party retains the ability to install
326326+modified object code on the User Product (for example, the work has
327327+been installed in ROM).
328328+329329+ The requirement to provide Installation Information does not include a
330330+requirement to continue to provide support service, warranty, or updates
331331+for a work that has been modified or installed by the recipient, or for
332332+the User Product in which it has been modified or installed. Access to a
333333+network may be denied when the modification itself materially and
334334+adversely affects the operation of the network or violates the rules and
335335+protocols for communication across the network.
336336+337337+ Corresponding Source conveyed, and Installation Information provided,
338338+in accord with this section must be in a format that is publicly
339339+documented (and with an implementation available to the public in
340340+source code form), and must require no special password or key for
341341+unpacking, reading or copying.
342342+343343+ 7. Additional Terms.
344344+345345+ "Additional permissions" are terms that supplement the terms of this
346346+License by making exceptions from one or more of its conditions.
347347+Additional permissions that are applicable to the entire Program shall
348348+be treated as though they were included in this License, to the extent
349349+that they are valid under applicable law. If additional permissions
350350+apply only to part of the Program, that part may be used separately
351351+under those permissions, but the entire Program remains governed by
352352+this License without regard to the additional permissions.
353353+354354+ When you convey a copy of a covered work, you may at your option
355355+remove any additional permissions from that copy, or from any part of
356356+it. (Additional permissions may be written to require their own
357357+removal in certain cases when you modify the work.) You may place
358358+additional permissions on material, added by you to a covered work,
359359+for which you have or can give appropriate copyright permission.
360360+361361+ Notwithstanding any other provision of this License, for material you
362362+add to a covered work, you may (if authorized by the copyright holders of
363363+that material) supplement the terms of this License with terms:
364364+365365+ a) Disclaiming warranty or limiting liability differently from the
366366+ terms of sections 15 and 16 of this License; or
367367+368368+ b) Requiring preservation of specified reasonable legal notices or
369369+ author attributions in that material or in the Appropriate Legal
370370+ Notices displayed by works containing it; or
371371+372372+ c) Prohibiting misrepresentation of the origin of that material, or
373373+ requiring that modified versions of such material be marked in
374374+ reasonable ways as different from the original version; or
375375+376376+ d) Limiting the use for publicity purposes of names of licensors or
377377+ authors of the material; or
378378+379379+ e) Declining to grant rights under trademark law for use of some
380380+ trade names, trademarks, or service marks; or
381381+382382+ f) Requiring indemnification of licensors and authors of that
383383+ material by anyone who conveys the material (or modified versions of
384384+ it) with contractual assumptions of liability to the recipient, for
385385+ any liability that these contractual assumptions directly impose on
386386+ those licensors and authors.
387387+388388+ All other non-permissive additional terms are considered "further
389389+restrictions" within the meaning of section 10. If the Program as you
390390+received it, or any part of it, contains a notice stating that it is
391391+governed by this License along with a term that is a further
392392+restriction, you may remove that term. If a license document contains
393393+a further restriction but permits relicensing or conveying under this
394394+License, you may add to a covered work material governed by the terms
395395+of that license document, provided that the further restriction does
396396+not survive such relicensing or conveying.
397397+398398+ If you add terms to a covered work in accord with this section, you
399399+must place, in the relevant source files, a statement of the
400400+additional terms that apply to those files, or a notice indicating
401401+where to find the applicable terms.
402402+403403+ Additional terms, permissive or non-permissive, may be stated in the
404404+form of a separately written license, or stated as exceptions;
405405+the above requirements apply either way.
406406+407407+ 8. Termination.
408408+409409+ You may not propagate or modify a covered work except as expressly
410410+provided under this License. Any attempt otherwise to propagate or
411411+modify it is void, and will automatically terminate your rights under
412412+this License (including any patent licenses granted under the third
413413+paragraph of section 11).
414414+415415+ However, if you cease all violation of this License, then your
416416+license from a particular copyright holder is reinstated (a)
417417+provisionally, unless and until the copyright holder explicitly and
418418+finally terminates your license, and (b) permanently, if the copyright
419419+holder fails to notify you of the violation by some reasonable means
420420+prior to 60 days after the cessation.
421421+422422+ Moreover, your license from a particular copyright holder is
423423+reinstated permanently if the copyright holder notifies you of the
424424+violation by some reasonable means, this is the first time you have
425425+received notice of violation of this License (for any work) from that
426426+copyright holder, and you cure the violation prior to 30 days after
427427+your receipt of the notice.
428428+429429+ Termination of your rights under this section does not terminate the
430430+licenses of parties who have received copies or rights from you under
431431+this License. If your rights have been terminated and not permanently
432432+reinstated, you do not qualify to receive new licenses for the same
433433+material under section 10.
434434+435435+ 9. Acceptance Not Required for Having Copies.
436436+437437+ You are not required to accept this License in order to receive or
438438+run a copy of the Program. Ancillary propagation of a covered work
439439+occurring solely as a consequence of using peer-to-peer transmission
440440+to receive a copy likewise does not require acceptance. However,
441441+nothing other than this License grants you permission to propagate or
442442+modify any covered work. These actions infringe copyright if you do
443443+not accept this License. Therefore, by modifying or propagating a
444444+covered work, you indicate your acceptance of this License to do so.
445445+446446+ 10. Automatic Licensing of Downstream Recipients.
447447+448448+ Each time you convey a covered work, the recipient automatically
449449+receives a license from the original licensors, to run, modify and
450450+propagate that work, subject to this License. You are not responsible
451451+for enforcing compliance by third parties with this License.
452452+453453+ An "entity transaction" is a transaction transferring control of an
454454+organization, or substantially all assets of one, or subdividing an
455455+organization, or merging organizations. If propagation of a covered
456456+work results from an entity transaction, each party to that
457457+transaction who receives a copy of the work also receives whatever
458458+licenses to the work the party's predecessor in interest had or could
459459+give under the previous paragraph, plus a right to possession of the
460460+Corresponding Source of the work from the predecessor in interest, if
461461+the predecessor has it or can get it with reasonable efforts.
462462+463463+ You may not impose any further restrictions on the exercise of the
464464+rights granted or affirmed under this License. For example, you may
465465+not impose a license fee, royalty, or other charge for exercise of
466466+rights granted under this License, and you may not initiate litigation
467467+(including a cross-claim or counterclaim in a lawsuit) alleging that
468468+any patent claim is infringed by making, using, selling, offering for
469469+sale, or importing the Program or any portion of it.
470470+471471+ 11. Patents.
472472+473473+ A "contributor" is a copyright holder who authorizes use under this
474474+License of the Program or a work on which the Program is based. The
475475+work thus licensed is called the contributor's "contributor version".
476476+477477+ A contributor's "essential patent claims" are all patent claims
478478+owned or controlled by the contributor, whether already acquired or
479479+hereafter acquired, that would be infringed by some manner, permitted
480480+by this License, of making, using, or selling its contributor version,
481481+but do not include claims that would be infringed only as a
482482+consequence of further modification of the contributor version. For
483483+purposes of this definition, "control" includes the right to grant
484484+patent sublicenses in a manner consistent with the requirements of
485485+this License.
486486+487487+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488488+patent license under the contributor's essential patent claims, to
489489+make, use, sell, offer for sale, import and otherwise run, modify and
490490+propagate the contents of its contributor version.
491491+492492+ In the following three paragraphs, a "patent license" is any express
493493+agreement or commitment, however denominated, not to enforce a patent
494494+(such as an express permission to practice a patent or covenant not to
495495+sue for patent infringement). To "grant" such a patent license to a
496496+party means to make such an agreement or commitment not to enforce a
497497+patent against the party.
498498+499499+ If you convey a covered work, knowingly relying on a patent license,
500500+and the Corresponding Source of the work is not available for anyone
501501+to copy, free of charge and under the terms of this License, through a
502502+publicly available network server or other readily accessible means,
503503+then you must either (1) cause the Corresponding Source to be so
504504+available, or (2) arrange to deprive yourself of the benefit of the
505505+patent license for this particular work, or (3) arrange, in a manner
506506+consistent with the requirements of this License, to extend the patent
507507+license to downstream recipients. "Knowingly relying" means you have
508508+actual knowledge that, but for the patent license, your conveying the
509509+covered work in a country, or your recipient's use of the covered work
510510+in a country, would infringe one or more identifiable patents in that
511511+country that you have reason to believe are valid.
512512+513513+ If, pursuant to or in connection with a single transaction or
514514+arrangement, you convey, or propagate by procuring conveyance of, a
515515+covered work, and grant a patent license to some of the parties
516516+receiving the covered work authorizing them to use, propagate, modify
517517+or convey a specific copy of the covered work, then the patent license
518518+you grant is automatically extended to all recipients of the covered
519519+work and works based on it.
520520+521521+ A patent license is "discriminatory" if it does not include within
522522+the scope of its coverage, prohibits the exercise of, or is
523523+conditioned on the non-exercise of one or more of the rights that are
524524+specifically granted under this License. You may not convey a covered
525525+work if you are a party to an arrangement with a third party that is
526526+in the business of distributing software, under which you make payment
527527+to the third party based on the extent of your activity of conveying
528528+the work, and under which the third party grants, to any of the
529529+parties who would receive the covered work from you, a discriminatory
530530+patent license (a) in connection with copies of the covered work
531531+conveyed by you (or copies made from those copies), or (b) primarily
532532+for and in connection with specific products or compilations that
533533+contain the covered work, unless you entered into that arrangement,
534534+or that patent license was granted, prior to 28 March 2007.
535535+536536+ Nothing in this License shall be construed as excluding or limiting
537537+any implied license or other defenses to infringement that may
538538+otherwise be available to you under applicable patent law.
539539+540540+ 12. No Surrender of Others' Freedom.
541541+542542+ If conditions are imposed on you (whether by court order, agreement or
543543+otherwise) that contradict the conditions of this License, they do not
544544+excuse you from the conditions of this License. If you cannot convey a
545545+covered work so as to satisfy simultaneously your obligations under this
546546+License and any other pertinent obligations, then as a consequence you may
547547+not convey it at all. For example, if you agree to terms that obligate you
548548+to collect a royalty for further conveying from those to whom you convey
549549+the Program, the only way you could satisfy both those terms and this
550550+License would be to refrain entirely from conveying the Program.
551551+552552+ 13. Use with the GNU Affero General Public License.
553553+554554+ Notwithstanding any other provision of this License, you have
555555+permission to link or combine any covered work with a work licensed
556556+under version 3 of the GNU Affero General Public License into a single
557557+combined work, and to convey the resulting work. The terms of this
558558+License will continue to apply to the part which is the covered work,
559559+but the special requirements of the GNU Affero General Public License,
560560+section 13, concerning interaction through a network will apply to the
561561+combination as such.
562562+563563+ 14. Revised Versions of this License.
564564+565565+ The Free Software Foundation may publish revised and/or new versions of
566566+the GNU General Public License from time to time. Such new versions will
567567+be similar in spirit to the present version, but may differ in detail to
568568+address new problems or concerns.
569569+570570+ Each version is given a distinguishing version number. If the
571571+Program specifies that a certain numbered version of the GNU General
572572+Public License "or any later version" applies to it, you have the
573573+option of following the terms and conditions either of that numbered
574574+version or of any later version published by the Free Software
575575+Foundation. If the Program does not specify a version number of the
576576+GNU General Public License, you may choose any version ever published
577577+by the Free Software Foundation.
578578+579579+ If the Program specifies that a proxy can decide which future
580580+versions of the GNU General Public License can be used, that proxy's
581581+public statement of acceptance of a version permanently authorizes you
582582+to choose that version for the Program.
583583+584584+ Later license versions may give you additional or different
585585+permissions. However, no additional obligations are imposed on any
586586+author or copyright holder as a result of your choosing to follow a
587587+later version.
588588+589589+ 15. Disclaimer of Warranty.
590590+591591+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592592+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593593+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594594+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595595+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596596+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597597+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598598+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599599+600600+ 16. Limitation of Liability.
601601+602602+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603603+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604604+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605605+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606606+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607607+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608608+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609609+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610610+SUCH DAMAGES.
611611+612612+ 17. Interpretation of Sections 15 and 16.
613613+614614+ If the disclaimer of warranty and limitation of liability provided
615615+above cannot be given local legal effect according to their terms,
616616+reviewing courts shall apply local law that most closely approximates
617617+an absolute waiver of all civil liability in connection with the
618618+Program, unless a warranty or assumption of liability accompanies a
619619+copy of the Program in return for a fee.
620620+621621+ END OF TERMS AND CONDITIONS
622622+623623+ How to Apply These Terms to Your New Programs
624624+625625+ If you develop a new program, and you want it to be of the greatest
626626+possible use to the public, the best way to achieve this is to make it
627627+free software which everyone can redistribute and change under these terms.
628628+629629+ To do so, attach the following notices to the program. It is safest
630630+to attach them to the start of each source file to most effectively
631631+state the exclusion of warranty; and each file should have at least
632632+the "copyright" line and a pointer to where the full notice is found.
633633+634634+ <one line to give the program's name and a brief idea of what it does.>
635635+ Copyright (C) <year> <name of author>
636636+637637+ This program is free software: you can redistribute it and/or modify
638638+ it under the terms of the GNU General Public License as published by
639639+ the Free Software Foundation, either version 3 of the License, or
640640+ (at your option) any later version.
641641+642642+ This program is distributed in the hope that it will be useful,
643643+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644644+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645645+ GNU General Public License for more details.
646646+647647+ You should have received a copy of the GNU General Public License
648648+ along with this program. If not, see <https://www.gnu.org/licenses/>.
649649+650650+Also add information on how to contact you by electronic and paper mail.
651651+652652+ If the program does terminal interaction, make it output a short
653653+notice like this when it starts in an interactive mode:
654654+655655+ <program> Copyright (C) <year> <name of author>
656656+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657+ This is free software, and you are welcome to redistribute it
658658+ under certain conditions; type `show c' for details.
659659+660660+The hypothetical commands `show w' and `show c' should show the appropriate
661661+parts of the General Public License. Of course, your program's commands
662662+might be different; for a GUI interface, you would use an "about box".
663663+664664+ You should also get your employer (if you work as a programmer) or school,
665665+if any, to sign a "copyright disclaimer" for the program, if necessary.
666666+For more information on this, and how to apply and follow the GNU GPL, see
667667+<https://www.gnu.org/licenses/>.
668668+669669+ The GNU General Public License does not permit incorporating your program
670670+into proprietary programs. If your program is a subroutine library, you
671671+may consider it more useful to permit linking proprietary applications with
672672+the library. If this is what you want to do, use the GNU Lesser General
673673+Public License instead of this License. But first, please read
674674+<https://www.gnu.org/licenses/why-not-lgpl.html>.
+165
COPYING.LESSER
···11+GNU LESSER GENERAL PUBLIC LICENSE
22+ Version 3, 29 June 2007
33+44+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
55+ Everyone is permitted to copy and distribute verbatim copies
66+ of this license document, but changing it is not allowed.
77+88+99+ This version of the GNU Lesser General Public License incorporates
1010+the terms and conditions of version 3 of the GNU General Public
1111+License, supplemented by the additional permissions listed below.
1212+1313+ 0. Additional Definitions.
1414+1515+ As used herein, "this License" refers to version 3 of the GNU Lesser
1616+General Public License, and the "GNU GPL" refers to version 3 of the GNU
1717+General Public License.
1818+1919+ "The Library" refers to a covered work governed by this License,
2020+other than an Application or a Combined Work as defined below.
2121+2222+ An "Application" is any work that makes use of an interface provided
2323+by the Library, but which is not otherwise based on the Library.
2424+Defining a subclass of a class defined by the Library is deemed a mode
2525+of using an interface provided by the Library.
2626+2727+ A "Combined Work" is a work produced by combining or linking an
2828+Application with the Library. The particular version of the Library
2929+with which the Combined Work was made is also called the "Linked
3030+Version".
3131+3232+ The "Minimal Corresponding Source" for a Combined Work means the
3333+Corresponding Source for the Combined Work, excluding any source code
3434+for portions of the Combined Work that, considered in isolation, are
3535+based on the Application, and not on the Linked Version.
3636+3737+ The "Corresponding Application Code" for a Combined Work means the
3838+object code and/or source code for the Application, including any data
3939+and utility programs needed for reproducing the Combined Work from the
4040+Application, but excluding the System Libraries of the Combined Work.
4141+4242+ 1. Exception to Section 3 of the GNU GPL.
4343+4444+ You may convey a covered work under sections 3 and 4 of this License
4545+without being bound by section 3 of the GNU GPL.
4646+4747+ 2. Conveying Modified Versions.
4848+4949+ If you modify a copy of the Library, and, in your modifications, a
5050+facility refers to a function or data to be supplied by an Application
5151+that uses the facility (other than as an argument passed when the
5252+facility is invoked), then you may convey a copy of the modified
5353+version:
5454+5555+ a) under this License, provided that you make a good faith effort to
5656+ ensure that, in the event an Application does not supply the
5757+ function or data, the facility still operates, and performs
5858+ whatever part of its purpose remains meaningful, or
5959+6060+ b) under the GNU GPL, with none of the additional permissions of
6161+ this License applicable to that copy.
6262+6363+ 3. Object Code Incorporating Material from Library Header Files.
6464+6565+ The object code form of an Application may incorporate material from
6666+a header file that is part of the Library. You may convey such object
6767+code under terms of your choice, provided that, if the incorporated
6868+material is not limited to numerical parameters, data structure
6969+layouts and accessors, or small macros, inline functions and templates
7070+(ten or fewer lines in length), you do both of the following:
7171+7272+ a) Give prominent notice with each copy of the object code that the
7373+ Library is used in it and that the Library and its use are
7474+ covered by this License.
7575+7676+ b) Accompany the object code with a copy of the GNU GPL and this license
7777+ document.
7878+7979+ 4. Combined Works.
8080+8181+ You may convey a Combined Work under terms of your choice that,
8282+taken together, effectively do not restrict modification of the
8383+portions of the Library contained in the Combined Work and reverse
8484+engineering for debugging such modifications, if you also do each of
8585+the following:
8686+8787+ a) Give prominent notice with each copy of the Combined Work that
8888+ the Library is used in it and that the Library and its use are
8989+ covered by this License.
9090+9191+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
9292+ document.
9393+9494+ c) For a Combined Work that displays copyright notices during
9595+ execution, include the copyright notice for the Library among
9696+ these notices, as well as a reference directing the user to the
9797+ copies of the GNU GPL and this license document.
9898+9999+ d) Do one of the following:
100100+101101+ 0) Convey the Minimal Corresponding Source under the terms of this
102102+ License, and the Corresponding Application Code in a form
103103+ suitable for, and under terms that permit, the user to
104104+ recombine or relink the Application with a modified version of
105105+ the Linked Version to produce a modified Combined Work, in the
106106+ manner specified by section 6 of the GNU GPL for conveying
107107+ Corresponding Source.
108108+109109+ 1) Use a suitable shared library mechanism for linking with the
110110+ Library. A suitable mechanism is one that (a) uses at run time
111111+ a copy of the Library already present on the user's computer
112112+ system, and (b) will operate properly with a modified version
113113+ of the Library that is interface-compatible with the Linked
114114+ Version.
115115+116116+ e) Provide Installation Information, but only if you would otherwise
117117+ be required to provide such information under section 6 of the
118118+ GNU GPL, and only to the extent that such information is
119119+ necessary to install and execute a modified version of the
120120+ Combined Work produced by recombining or relinking the
121121+ Application with a modified version of the Linked Version. (If
122122+ you use option 4d0, the Installation Information must accompany
123123+ the Minimal Corresponding Source and Corresponding Application
124124+ Code. If you use option 4d1, you must provide the Installation
125125+ Information in the manner specified by section 6 of the GNU GPL
126126+ for conveying Corresponding Source.)
127127+128128+ 5. Combined Libraries.
129129+130130+ You may place library facilities that are a work based on the
131131+Library side by side in a single library together with other library
132132+facilities that are not Applications and are not covered by this
133133+License, and convey such a combined library under terms of your
134134+choice, if you do both of the following:
135135+136136+ a) Accompany the combined library with a copy of the same work based
137137+ on the Library, uncombined with any other library facilities,
138138+ conveyed under the terms of this License.
139139+140140+ b) Give prominent notice with the combined library that part of it
141141+ is a work based on the Library, and explaining where to find the
142142+ accompanying uncombined form of the same work.
143143+144144+ 6. Revised Versions of the GNU Lesser General Public License.
145145+146146+ The Free Software Foundation may publish revised and/or new versions
147147+of the GNU Lesser General Public License from time to time. Such new
148148+versions will be similar in spirit to the present version, but may
149149+differ in detail to address new problems or concerns.
150150+151151+ Each version is given a distinguishing version number. If the
152152+Library as you received it specifies that a certain numbered version
153153+of the GNU Lesser General Public License "or any later version"
154154+applies to it, you have the option of following the terms and
155155+conditions either of that published version or of any later version
156156+published by the Free Software Foundation. If the Library as you
157157+received it does not specify a version number of the GNU Lesser
158158+General Public License, you may choose any version of the GNU Lesser
159159+General Public License ever published by the Free Software Foundation.
160160+161161+ If the Library as you received it specifies that a proxy can decide
162162+whether future versions of the GNU Lesser General Public License shall
163163+apply, that proxy's public statement of acceptance of any version is
164164+permanent authorization for you to choose that version for the
165165+Library.
+5
Makefile
···11+main: include/textstore.h src/textstore.c example/main.c
22+ cc -Iinclude/ -Wall -pedantic example/main.c src/textstore.c -o main
33+44+cleanup:
55+ rm main
+3
README.md
···11+# textstore
22+33+A data structure for storing reference-counted, de-duplicated strings for access by other structures.
+94
example/main.c
···11+/**
22+ * Runs a tests to make sure the text-store works.
33+ */
44+55+#include <stdio.h>
66+#include <string.h>
77+#include <textstore.h>
88+99+int main(int argc, char **argv) {
1010+ textstore_t store;
1111+ if(textstore_init(&store, 64)) {
1212+ fprintf(stderr, "ERROR: textstore_init() failed.\n");
1313+ return 1;
1414+ }
1515+1616+ // A reference counted string handle.
1717+ char *handle1_expected = "Hello world!";
1818+ textstore_handle handle1 = textstore_intern(&store, handle1_expected);
1919+ if (strcmp(textstore_string(&store, handle1), handle1_expected) != 0) {
2020+ fprintf(stderr, "ERROR: handle1 does not equal \"%s\"\n", handle1_expected);
2121+ return 1;
2222+ }
2323+2424+ char *handle2_expected = "A different string!";
2525+ textstore_handle handle2 = textstore_intern(&store, handle2_expected);
2626+ if (strcmp(textstore_string(&store, handle2), handle2_expected)) {
2727+ fprintf(stderr, "ERROR: handle2 does not equal \"%s\"\n", handle2_expected);
2828+ return 1;
2929+ }
3030+3131+ // A handle may become invalidated after all references to it are released.
3232+ textstore_release(&store, handle1);
3333+ if (textstore_gc(&store) != 0) {
3434+ fprintf(stderr, "ERROR: Garbage collector failed.\n");
3535+ return 1;
3636+ }
3737+3838+ // Trying to get the data of an inactive handle should return null.
3939+ char *invalid_string = textstore_string(&store, handle1);
4040+ if (invalid_string != NULL) {
4141+ fprintf(stderr, "ERROR: handle1 should be null, but isn't: \"%s\"\n", invalid_string);
4242+ return 1;
4343+ }
4444+4545+ // Interning new strings may re-use previously gc'd handle indexes.
4646+ // But they are not equal due to their cycle bits.
4747+ textstore_handle handle3 = textstore_intern(&store, "Hello world.");
4848+ if (handle1 == handle3) {
4949+ fprintf(stderr, "ERROR: handle1 and handle3 should not be equal.\n");
5050+ return 1;
5151+ }
5252+5353+ // And trying to access a previously gc'd handle will still return an error,
5454+ // even if its index is in use.
5555+ invalid_string = textstore_string(&store, handle1);
5656+ if (invalid_string != NULL) {
5757+ fprintf(stderr, "ERROR: handle1 should be null, but isn't: \"%s\"\n", invalid_string);
5858+ return 1;
5959+ }
6060+6161+ // Likewise, interning the same string will result in identical handles.
6262+ textstore_handle handle4 = textstore_intern(&store, "Hello world.");
6363+ if (handle3 != handle4) {
6464+ fprintf(stderr, "ERROR: handle3 and handle4 should be equal.\n");
6565+ return 1;
6666+ }
6767+6868+ {
6969+ textstore_handle temp_handle;
7070+ temp_handle = textstore_intern(&store, "blah blah");
7171+ textstore_release(&store, temp_handle);
7272+ temp_handle = textstore_intern(&store, "random text");
7373+ textstore_release(&store, temp_handle);
7474+ temp_handle = textstore_intern(&store, "text");
7575+ textstore_release(&store, temp_handle);
7676+ temp_handle = textstore_intern(&store, "random text2");
7777+ textstore_release(&store, temp_handle);
7878+ }
7979+8080+ textstore_handle handle5 = textstore_intern(&store, "All your bases...");
8181+ textstore_gc(&store);
8282+ // Even after a GC and the underlying text being invalidated and shifted
8383+ // about, valid handles can still be used.
8484+ if (strcmp(textstore_string(&store, handle5), "All your bases...") != 0) {
8585+ fprintf(stderr, "ERROR: handle5 is wrong? \"%s\"\n", textstore_string(&store, handle5));
8686+ return 1;
8787+ }
8888+8989+ textstore_free(&store);
9090+9191+ printf("All tests passed.\n");
9292+ return 0;
9393+}
9494+
+113
include/textstore.h
···11+/* text-store - A store for storing reference-counted, de-duplicated strings.
22+ * Copyright (C) 2025 Jeremia Dominguez <me@jeremia.dev>
33+ *
44+ * This program is free software: you can redistribute it and/or modify
55+ * it under the terms of the GNU General Public License as published by
66+ * the Free Software Foundation, either version 3 of the License, or
77+ * (at your option) any later version.
88+ *
99+ * This program is distributed in the hope that it will be useful,
1010+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1111+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212+ * GNU General Public License for more details.
1313+ *
1414+ * You should have received a copy of the GNU General Public License
1515+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
1616+ */
1717+1818+1919+#ifndef TEXTSTORE_H
2020+#define TEXTSTORE_H
2121+2222+#include <assert.h>
2323+#include <stdbool.h>
2424+#include <stddef.h>
2525+#include <stdint.h>
2626+2727+/**
2828+ * A handle used to reference a string within the text store.
2929+ */
3030+typedef uint64_t textstore_handle;
3131+#define TEXTSTORE_HANDLE_ERROR UINT64_MAX
3232+3333+typedef struct {
3434+ uint32_t offset;
3535+ uint32_t len;
3636+} textstore_slice;
3737+3838+/**
3939+ * A store containing all string data.
4040+ */
4141+typedef struct textstore_t {
4242+ char *buffer; /* Buffer of all allocated text.
4343+ Pointers to this buffer are considered volatile. */
4444+ uint32_t length; /* Length of currently used buffer. */
4545+ uint32_t buffer_cap; /* The current capacity of the buffer. */
4646+ uint32_t available; /* Count of available free handles. */
4747+4848+ uint32_t *map; /* The hashmap's indexes into the tables below. */
4949+ textstore_slice *key; /* The slice a handle represents within the buffer */
5050+ uint32_t *ref; /* The reference counter for a given string. */
5151+ uint32_t *generation; /* The current/last active generation of a handle. */
5252+ bool *active; /* Whether the given handle is currently active. */
5353+5454+ uint32_t count; /* The number of string entries. */
5555+ uint32_t capacity; /* The current capacity of the hashmap. */
5656+} textstore_t;
5757+5858+int textstore_init(textstore_t *store, uint32_t initial_buffer);
5959+void textstore_free(textstore_t *store);
6060+int textstore_gc(textstore_t *store);
6161+textstore_handle textstore_intern(textstore_t *store, char *str);
6262+textstore_handle textstore_intern_len(textstore_t *store, char *str, uint32_t len);
6363+6464+static inline uint32_t textstore_as_index(textstore_handle handle) {
6565+ return (uint32_t) (handle & 0xFFFFFFFF);
6666+}
6767+static inline uint32_t textstore_as_generation(textstore_handle handle) {
6868+ return (uint32_t) (handle >> 32);
6969+}
7070+7171+static inline char *textstore_string(textstore_t *store, textstore_handle handle) {
7272+ textstore_t sstore = *store;
7373+ uint32_t index = textstore_as_index(handle);
7474+ if (index > sstore.count || !sstore.active[index]) return NULL;
7575+7676+ uint32_t generation = textstore_as_generation(handle);
7777+ if (generation != sstore.generation[index]) return NULL;
7878+7979+ return sstore.buffer + sstore.key[index].offset;
8080+}
8181+8282+static inline uint32_t textstore_length(textstore_t *store, textstore_handle handle) {
8383+ textstore_t sstore = *store;
8484+ uint32_t index = textstore_as_index(handle);
8585+ if (index == 0 || index > sstore.count || !sstore.active[index]) return 0;
8686+8787+ uint32_t generation = textstore_as_generation(handle);
8888+ if (generation != sstore.generation[index]) return 0;
8989+9090+ return sstore.key[index].len;
9191+}
9292+9393+static inline void textstore_retain(textstore_t *store, textstore_handle handle) {
9494+ uint32_t index = textstore_as_index(handle);
9595+ assert(index < store->count);
9696+ assert(store->active[index]);
9797+9898+ store->ref[index] += 1;
9999+}
100100+101101+static inline void textstore_release(textstore_t *store, textstore_handle handle) {
102102+ uint32_t index = textstore_as_index(handle);
103103+ assert(index < store->count);
104104+ assert(store->active[index]);
105105+106106+ // Avoid underflow.
107107+ uint32_t ref = store->ref[index];
108108+ if (ref) {
109109+ store->ref[index] = ref - 1;
110110+ }
111111+}
112112+113113+#endif // TEXTSTORE_H
+568
src/rapidhash.h
···11+/*
22+ * rapidhash V3 - Very fast, high quality, platform-independent hashing algorithm.
33+ *
44+ * Based on 'wyhash', by Wang Yi <godspeed_china@yeah.net>
55+ *
66+ * Copyright (C) 2025 Nicolas De Carli
77+ *
88+ * Permission is hereby granted, free of charge, to any person obtaining a copy
99+ * of this software and associated documentation files (the "Software"), to deal
1010+ * in the Software without restriction, including without limitation the rights
1111+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1212+ * copies of the Software, and to permit persons to whom the Software is
1313+ * furnished to do so, subject to the following conditions:
1414+ *
1515+ * The above copyright notice and this permission notice shall be included in all
1616+ * copies or substantial portions of the Software.
1717+ *
1818+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1919+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2020+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2121+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2222+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2323+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424+ * SOFTWARE.
2525+ *
2626+ * You can contact the author at:
2727+ * - rapidhash source repository: https://github.com/Nicoshev/rapidhash
2828+ */
2929+3030+ #pragma once
3131+3232+/*
3333+ * Includes.
3434+ */
3535+ #include <stdint.h>
3636+ #include <string.h>
3737+ #if defined(_MSC_VER)
3838+ # include <intrin.h>
3939+ # if defined(_M_X64) && !defined(_M_ARM64EC)
4040+ # pragma intrinsic(_umul128)
4141+ # endif
4242+ #endif
4343+4444+ /*
4545+ * C/C++ macros.
4646+ */
4747+4848+ #ifdef _MSC_VER
4949+ # define RAPIDHASH_ALWAYS_INLINE __forceinline
5050+ #elif defined(__GNUC__)
5151+ # define RAPIDHASH_ALWAYS_INLINE inline __attribute__((__always_inline__))
5252+ #else
5353+ # define RAPIDHASH_ALWAYS_INLINE inline
5454+ #endif
5555+5656+ #ifdef __cplusplus
5757+ # define RAPIDHASH_NOEXCEPT noexcept
5858+ # define RAPIDHASH_CONSTEXPR constexpr
5959+ # ifndef RAPIDHASH_INLINE
6060+ # define RAPIDHASH_INLINE RAPIDHASH_ALWAYS_INLINE
6161+ # endif
6262+ # if __cplusplus >= 201402L && !defined(_MSC_VER)
6363+ # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_ALWAYS_INLINE constexpr
6464+ # else
6565+ # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_ALWAYS_INLINE
6666+ # endif
6767+ #else
6868+ # define RAPIDHASH_NOEXCEPT
6969+ # define RAPIDHASH_CONSTEXPR static const
7070+ # ifndef RAPIDHASH_INLINE
7171+ # define RAPIDHASH_INLINE static RAPIDHASH_ALWAYS_INLINE
7272+ # endif
7373+ # define RAPIDHASH_INLINE_CONSTEXPR RAPIDHASH_INLINE
7474+ #endif
7575+7676+ /*
7777+ * Unrolled macro.
7878+ * Improves large input speed, but increases code size and worsens small input speed.
7979+ *
8080+ * RAPIDHASH_COMPACT: Normal behavior.
8181+ * RAPIDHASH_UNROLLED:
8282+ *
8383+ */
8484+ #ifndef RAPIDHASH_UNROLLED
8585+ # define RAPIDHASH_COMPACT
8686+ #elif defined(RAPIDHASH_COMPACT)
8787+ # error "cannot define RAPIDHASH_COMPACT and RAPIDHASH_UNROLLED simultaneously."
8888+ #endif
8989+9090+ /*
9191+ * Protection macro, alters behaviour of rapid_mum multiplication function.
9292+ *
9393+ * RAPIDHASH_FAST: Normal behavior, max speed.
9494+ * RAPIDHASH_PROTECTED: Extra protection against entropy loss.
9595+ */
9696+ #ifndef RAPIDHASH_PROTECTED
9797+ # define RAPIDHASH_FAST
9898+ #elif defined(RAPIDHASH_FAST)
9999+ # error "cannot define RAPIDHASH_PROTECTED and RAPIDHASH_FAST simultaneously."
100100+ #endif
101101+102102+ /*
103103+ * Likely and unlikely macros.
104104+ */
105105+ #if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)
106106+ # define _likely_(x) __builtin_expect(x,1)
107107+ # define _unlikely_(x) __builtin_expect(x,0)
108108+ #else
109109+ # define _likely_(x) (x)
110110+ # define _unlikely_(x) (x)
111111+ #endif
112112+113113+ /*
114114+ * Endianness macros.
115115+ */
116116+ #ifndef RAPIDHASH_LITTLE_ENDIAN
117117+ # if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
118118+ # define RAPIDHASH_LITTLE_ENDIAN
119119+ # elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
120120+ # define RAPIDHASH_BIG_ENDIAN
121121+ # else
122122+ # warning "could not determine endianness! Falling back to little endian."
123123+ # define RAPIDHASH_LITTLE_ENDIAN
124124+ # endif
125125+ #endif
126126+127127+ /*
128128+ * Default secret parameters.
129129+ */
130130+ RAPIDHASH_CONSTEXPR uint64_t rapid_secret[8] = {
131131+ 0x2d358dccaa6c78a5ull,
132132+ 0x8bb84b93962eacc9ull,
133133+ 0x4b33a62ed433d4a3ull,
134134+ 0x4d5a2da51de1aa47ull,
135135+ 0xa0761d6478bd642full,
136136+ 0xe7037ed1a0b428dbull,
137137+ 0x90ed1765281c388cull,
138138+ 0xaaaaaaaaaaaaaaaaull};
139139+140140+ /*
141141+ * 64*64 -> 128bit multiply function.
142142+ *
143143+ * @param A Address of 64-bit number.
144144+ * @param B Address of 64-bit number.
145145+ *
146146+ * Calculates 128-bit C = *A * *B.
147147+ *
148148+ * When RAPIDHASH_FAST is defined:
149149+ * Overwrites A contents with C's low 64 bits.
150150+ * Overwrites B contents with C's high 64 bits.
151151+ *
152152+ * When RAPIDHASH_PROTECTED is defined:
153153+ * Xors and overwrites A contents with C's low 64 bits.
154154+ * Xors and overwrites B contents with C's high 64 bits.
155155+ */
156156+ RAPIDHASH_INLINE_CONSTEXPR void rapid_mum(uint64_t *A, uint64_t *B) RAPIDHASH_NOEXCEPT {
157157+ #if defined(__SIZEOF_INT128__)
158158+ __uint128_t r=*A; r*=*B;
159159+ #ifdef RAPIDHASH_PROTECTED
160160+ *A^=(uint64_t)r; *B^=(uint64_t)(r>>64);
161161+ #else
162162+ *A=(uint64_t)r; *B=(uint64_t)(r>>64);
163163+ #endif
164164+ #elif defined(_MSC_VER) && (defined(_WIN64) || defined(_M_HYBRID_CHPE_ARM64))
165165+ #if defined(_M_X64)
166166+ #ifdef RAPIDHASH_PROTECTED
167167+ uint64_t a, b;
168168+ a=_umul128(*A,*B,&b);
169169+ *A^=a; *B^=b;
170170+ #else
171171+ *A=_umul128(*A,*B,B);
172172+ #endif
173173+ #else
174174+ #ifdef RAPIDHASH_PROTECTED
175175+ uint64_t a, b;
176176+ b = __umulh(*A, *B);
177177+ a = *A * *B;
178178+ *A^=a; *B^=b;
179179+ #else
180180+ uint64_t c = __umulh(*A, *B);
181181+ *A = *A * *B;
182182+ *B = c;
183183+ #endif
184184+ #endif
185185+ #else
186186+ uint64_t ha=*A>>32, hb=*B>>32, la=(uint32_t)*A, lb=(uint32_t)*B;
187187+ uint64_t rh=ha*hb, rm0=ha*lb, rm1=hb*la, rl=la*lb, t=rl+(rm0<<32), c=t<rl;
188188+ uint64_t lo=t+(rm1<<32);
189189+ c+=lo<t;
190190+ uint64_t hi=rh+(rm0>>32)+(rm1>>32)+c;
191191+ #ifdef RAPIDHASH_PROTECTED
192192+ *A^=lo; *B^=hi;
193193+ #else
194194+ *A=lo; *B=hi;
195195+ #endif
196196+ #endif
197197+ }
198198+199199+ /*
200200+ * Multiply and xor mix function.
201201+ *
202202+ * @param A 64-bit number.
203203+ * @param B 64-bit number.
204204+ *
205205+ * Calculates 128-bit C = A * B.
206206+ * Returns 64-bit xor between high and low 64 bits of C.
207207+ */
208208+ RAPIDHASH_INLINE_CONSTEXPR uint64_t rapid_mix(uint64_t A, uint64_t B) RAPIDHASH_NOEXCEPT { rapid_mum(&A,&B); return A^B; }
209209+210210+ /*
211211+ * Read functions.
212212+ */
213213+ #ifdef RAPIDHASH_LITTLE_ENDIAN
214214+ RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return v;}
215215+ RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return v;}
216216+ #elif defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__clang__)
217217+ RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return __builtin_bswap64(v);}
218218+ RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return __builtin_bswap32(v);}
219219+ #elif defined(_MSC_VER)
220220+ RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint64_t v; memcpy(&v, p, sizeof(uint64_t)); return _byteswap_uint64(v);}
221221+ RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT { uint32_t v; memcpy(&v, p, sizeof(uint32_t)); return _byteswap_ulong(v);}
222222+ #else
223223+ RAPIDHASH_INLINE uint64_t rapid_read64(const uint8_t *p) RAPIDHASH_NOEXCEPT {
224224+ uint64_t v; memcpy(&v, p, 8);
225225+ return (((v >> 56) & 0xff)| ((v >> 40) & 0xff00)| ((v >> 24) & 0xff0000)| ((v >> 8) & 0xff000000)| ((v << 8) & 0xff00000000)| ((v << 24) & 0xff0000000000)| ((v << 40) & 0xff000000000000)| ((v << 56) & 0xff00000000000000));
226226+ }
227227+ RAPIDHASH_INLINE uint64_t rapid_read32(const uint8_t *p) RAPIDHASH_NOEXCEPT {
228228+ uint32_t v; memcpy(&v, p, 4);
229229+ return (((v >> 24) & 0xff)| ((v >> 8) & 0xff00)| ((v << 8) & 0xff0000)| ((v << 24) & 0xff000000));
230230+ }
231231+ #endif
232232+233233+ /*
234234+ * rapidhash main function.
235235+ *
236236+ * @param key Buffer to be hashed.
237237+ * @param len @key length, in bytes.
238238+ * @param seed 64-bit seed used to alter the hash result predictably.
239239+ * @param secret Triplet of 64-bit secrets used to alter hash result predictably.
240240+ *
241241+ * Returns a 64-bit hash.
242242+ */
243243+RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT {
244244+ const uint8_t *p=(const uint8_t *)key;
245245+ seed ^= rapid_mix(seed ^ secret[2], secret[1]);
246246+ uint64_t a=0, b=0;
247247+ size_t i = len;
248248+ if (_likely_(len <= 16)) {
249249+ if (len >= 4) {
250250+ seed ^= len;
251251+ if (len >= 8) {
252252+ const uint8_t* plast = p + len - 8;
253253+ a = rapid_read64(p);
254254+ b = rapid_read64(plast);
255255+ } else {
256256+ const uint8_t* plast = p + len - 4;
257257+ a = rapid_read32(p);
258258+ b = rapid_read32(plast);
259259+ }
260260+ } else if (len > 0) {
261261+ a = (((uint64_t)p[0])<<45)|p[len-1];
262262+ b = p[len>>1];
263263+ } else
264264+ a = b = 0;
265265+ } else {
266266+ if (len > 112) {
267267+ uint64_t see1 = seed, see2 = seed;
268268+ uint64_t see3 = seed, see4 = seed;
269269+ uint64_t see5 = seed, see6 = seed;
270270+#ifdef RAPIDHASH_COMPACT
271271+ do {
272272+ seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed);
273273+ see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1);
274274+ see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2);
275275+ see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3);
276276+ see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4);
277277+ see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5);
278278+ see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6);
279279+ p += 112;
280280+ i -= 112;
281281+ } while(i > 112);
282282+#else
283283+ while (i > 224) {
284284+ seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed);
285285+ see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1);
286286+ see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2);
287287+ see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3);
288288+ see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4);
289289+ see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5);
290290+ see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6);
291291+ seed = rapid_mix(rapid_read64(p + 112) ^ secret[0], rapid_read64(p + 120) ^ seed);
292292+ see1 = rapid_mix(rapid_read64(p + 128) ^ secret[1], rapid_read64(p + 136) ^ see1);
293293+ see2 = rapid_mix(rapid_read64(p + 144) ^ secret[2], rapid_read64(p + 152) ^ see2);
294294+ see3 = rapid_mix(rapid_read64(p + 160) ^ secret[3], rapid_read64(p + 168) ^ see3);
295295+ see4 = rapid_mix(rapid_read64(p + 176) ^ secret[4], rapid_read64(p + 184) ^ see4);
296296+ see5 = rapid_mix(rapid_read64(p + 192) ^ secret[5], rapid_read64(p + 200) ^ see5);
297297+ see6 = rapid_mix(rapid_read64(p + 208) ^ secret[6], rapid_read64(p + 216) ^ see6);
298298+ p += 224;
299299+ i -= 224;
300300+ }
301301+ if (i > 112) {
302302+ seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed);
303303+ see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1);
304304+ see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2);
305305+ see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3);
306306+ see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4);
307307+ see5 = rapid_mix(rapid_read64(p + 80) ^ secret[5], rapid_read64(p + 88) ^ see5);
308308+ see6 = rapid_mix(rapid_read64(p + 96) ^ secret[6], rapid_read64(p + 104) ^ see6);
309309+ p += 112;
310310+ i -= 112;
311311+ }
312312+#endif
313313+ seed ^= see1;
314314+ see2 ^= see3;
315315+ see4 ^= see5;
316316+ seed ^= see6;
317317+ see2 ^= see4;
318318+ seed ^= see2;
319319+ }
320320+ if (i > 16) {
321321+ seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed);
322322+ if (i > 32) {
323323+ seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed);
324324+ if (i > 48) {
325325+ seed = rapid_mix(rapid_read64(p + 32) ^ secret[1], rapid_read64(p + 40) ^ seed);
326326+ if (i > 64) {
327327+ seed = rapid_mix(rapid_read64(p + 48) ^ secret[1], rapid_read64(p + 56) ^ seed);
328328+ if (i > 80) {
329329+ seed = rapid_mix(rapid_read64(p + 64) ^ secret[2], rapid_read64(p + 72) ^ seed);
330330+ if (i > 96) {
331331+ seed = rapid_mix(rapid_read64(p + 80) ^ secret[1], rapid_read64(p + 88) ^ seed);
332332+ }
333333+ }
334334+ }
335335+ }
336336+ }
337337+ }
338338+ a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8);
339339+ }
340340+ a ^= secret[1];
341341+ b ^= seed;
342342+ rapid_mum(&a, &b);
343343+ return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i);
344344+}
345345+346346+ /*
347347+ * rapidhashMicro main function.
348348+ *
349349+ * @param key Buffer to be hashed.
350350+ * @param len @key length, in bytes.
351351+ * @param seed 64-bit seed used to alter the hash result predictably.
352352+ * @param secret Triplet of 64-bit secrets used to alter hash result predictably.
353353+ *
354354+ * Returns a 64-bit hash.
355355+ */
356356+ RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT {
357357+ const uint8_t *p=(const uint8_t *)key;
358358+ seed ^= rapid_mix(seed ^ secret[2], secret[1]);
359359+ uint64_t a=0, b=0;
360360+ size_t i = len;
361361+ if (_likely_(len <= 16)) {
362362+ if (len >= 4) {
363363+ seed ^= len;
364364+ if (len >= 8) {
365365+ const uint8_t* plast = p + len - 8;
366366+ a = rapid_read64(p);
367367+ b = rapid_read64(plast);
368368+ } else {
369369+ const uint8_t* plast = p + len - 4;
370370+ a = rapid_read32(p);
371371+ b = rapid_read32(plast);
372372+ }
373373+ } else if (len > 0) {
374374+ a = (((uint64_t)p[0])<<45)|p[len-1];
375375+ b = p[len>>1];
376376+ } else
377377+ a = b = 0;
378378+ } else {
379379+ if (i > 80) {
380380+ uint64_t see1 = seed, see2 = seed;
381381+ uint64_t see3 = seed, see4 = seed;
382382+ do {
383383+ seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed);
384384+ see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1);
385385+ see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2);
386386+ see3 = rapid_mix(rapid_read64(p + 48) ^ secret[3], rapid_read64(p + 56) ^ see3);
387387+ see4 = rapid_mix(rapid_read64(p + 64) ^ secret[4], rapid_read64(p + 72) ^ see4);
388388+ p += 80;
389389+ i -= 80;
390390+ } while(i > 80);
391391+ seed ^= see1;
392392+ see2 ^= see3;
393393+ seed ^= see4;
394394+ seed ^= see2;
395395+ }
396396+ if (i > 16) {
397397+ seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed);
398398+ if (i > 32) {
399399+ seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed);
400400+ if (i > 48) {
401401+ seed = rapid_mix(rapid_read64(p + 32) ^ secret[1], rapid_read64(p + 40) ^ seed);
402402+ if (i > 64) {
403403+ seed = rapid_mix(rapid_read64(p + 48) ^ secret[1], rapid_read64(p + 56) ^ seed);
404404+ }
405405+ }
406406+ }
407407+ }
408408+ a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8);
409409+ }
410410+ a ^= secret[1];
411411+ b ^= seed;
412412+ rapid_mum(&a, &b);
413413+ return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i);
414414+ }
415415+416416+ /*
417417+ * rapidhashNano main function.
418418+ *
419419+ * @param key Buffer to be hashed.
420420+ * @param len @key length, in bytes.
421421+ * @param seed 64-bit seed used to alter the hash result predictably.
422422+ * @param secret Triplet of 64-bit secrets used to alter hash result predictably.
423423+ *
424424+ * Returns a 64-bit hash.
425425+ */
426426+ RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano_internal(const void *key, size_t len, uint64_t seed, const uint64_t* secret) RAPIDHASH_NOEXCEPT {
427427+ const uint8_t *p=(const uint8_t *)key;
428428+ seed ^= rapid_mix(seed ^ secret[2], secret[1]);
429429+ uint64_t a=0, b=0;
430430+ size_t i = len;
431431+ if (_likely_(len <= 16)) {
432432+ if (len >= 4) {
433433+ seed ^= len;
434434+ if (len >= 8) {
435435+ const uint8_t* plast = p + len - 8;
436436+ a = rapid_read64(p);
437437+ b = rapid_read64(plast);
438438+ } else {
439439+ const uint8_t* plast = p + len - 4;
440440+ a = rapid_read32(p);
441441+ b = rapid_read32(plast);
442442+ }
443443+ } else if (len > 0) {
444444+ a = (((uint64_t)p[0])<<45)|p[len-1];
445445+ b = p[len>>1];
446446+ } else
447447+ a = b = 0;
448448+ } else {
449449+ if (i > 48) {
450450+ uint64_t see1 = seed, see2 = seed;
451451+ do {
452452+ seed = rapid_mix(rapid_read64(p) ^ secret[0], rapid_read64(p + 8) ^ seed);
453453+ see1 = rapid_mix(rapid_read64(p + 16) ^ secret[1], rapid_read64(p + 24) ^ see1);
454454+ see2 = rapid_mix(rapid_read64(p + 32) ^ secret[2], rapid_read64(p + 40) ^ see2);
455455+ p += 48;
456456+ i -= 48;
457457+ } while(i > 48);
458458+ seed ^= see1;
459459+ seed ^= see2;
460460+ }
461461+ if (i > 16) {
462462+ seed = rapid_mix(rapid_read64(p) ^ secret[2], rapid_read64(p + 8) ^ seed);
463463+ if (i > 32) {
464464+ seed = rapid_mix(rapid_read64(p + 16) ^ secret[2], rapid_read64(p + 24) ^ seed);
465465+ }
466466+ }
467467+ a=rapid_read64(p+i-16) ^ i; b=rapid_read64(p+i-8);
468468+ }
469469+ a ^= secret[1];
470470+ b ^= seed;
471471+ rapid_mum(&a, &b);
472472+ return rapid_mix(a ^ secret[7], b ^ secret[1] ^ i);
473473+ }
474474+475475+/*
476476+ * rapidhash seeded hash function.
477477+ *
478478+ * @param key Buffer to be hashed.
479479+ * @param len @key length, in bytes.
480480+ * @param seed 64-bit seed used to alter the hash result predictably.
481481+ *
482482+ * Calls rapidhash_internal using provided parameters and default secrets.
483483+ *
484484+ * Returns a 64-bit hash.
485485+ */
486486+RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT {
487487+ return rapidhash_internal(key, len, seed, rapid_secret);
488488+}
489489+490490+/*
491491+ * rapidhash general purpose hash function.
492492+ *
493493+ * @param key Buffer to be hashed.
494494+ * @param len @key length, in bytes.
495495+ *
496496+ * Calls rapidhash_withSeed using provided parameters and the default seed.
497497+ *
498498+ * Returns a 64-bit hash.
499499+ */
500500+RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhash(const void *key, size_t len) RAPIDHASH_NOEXCEPT {
501501+ return rapidhash_withSeed(key, len, 0);
502502+}
503503+504504+/*
505505+ * rapidhashMicro seeded hash function.
506506+ *
507507+ * Designed for HPC and server applications, where cache misses make a noticeable performance detriment.
508508+ * Clang-18+ compiles it to ~140 instructions without stack usage, both on x86-64 and aarch64.
509509+ * Faster for sizes up to 512 bytes, just 15%-20% slower for inputs above 1kb.
510510+ *
511511+ * @param key Buffer to be hashed.
512512+ * @param len @key length, in bytes.
513513+ * @param seed 64-bit seed used to alter the hash result predictably.
514514+ *
515515+ * Calls rapidhash_internal using provided parameters and default secrets.
516516+ *
517517+ * Returns a 64-bit hash.
518518+ */
519519+ RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT {
520520+ return rapidhashMicro_internal(key, len, seed, rapid_secret);
521521+}
522522+523523+/*
524524+ * rapidhashMicro hash function.
525525+ *
526526+ * @param key Buffer to be hashed.
527527+ * @param len @key length, in bytes.
528528+ *
529529+ * Calls rapidhash_withSeed using provided parameters and the default seed.
530530+ *
531531+ * Returns a 64-bit hash.
532532+ */
533533+RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashMicro(const void *key, size_t len) RAPIDHASH_NOEXCEPT {
534534+ return rapidhashMicro_withSeed(key, len, 0);
535535+}
536536+537537+/*
538538+ * rapidhashNano seeded hash function.
539539+ *
540540+ * @param key Buffer to be hashed.
541541+ * @param len @key length, in bytes.
542542+ * @param seed 64-bit seed used to alter the hash result predictably.
543543+ *
544544+ * Calls rapidhash_internal using provided parameters and default secrets.
545545+ *
546546+ * Returns a 64-bit hash.
547547+ */
548548+ RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano_withSeed(const void *key, size_t len, uint64_t seed) RAPIDHASH_NOEXCEPT {
549549+ return rapidhashNano_internal(key, len, seed, rapid_secret);
550550+}
551551+552552+/*
553553+ * rapidhashNano hash function.
554554+ *
555555+ * Designed for Mobile and embedded applications, where keeping a small code size is a top priority.
556556+ * Clang-18+ compiles it to less than 100 instructions without stack usage, both on x86-64 and aarch64.
557557+ * The fastest for sizes up to 48 bytes, but may be considerably slower for larger inputs.
558558+ *
559559+ * @param key Buffer to be hashed.
560560+ * @param len @key length, in bytes.
561561+ *
562562+ * Calls rapidhash_withSeed using provided parameters and the default seed.
563563+ *
564564+ * Returns a 64-bit hash.
565565+ */
566566+RAPIDHASH_INLINE_CONSTEXPR uint64_t rapidhashNano(const void *key, size_t len) RAPIDHASH_NOEXCEPT {
567567+ return rapidhashNano_withSeed(key, len, 0);
568568+}