Regulatory Pain Points
Transcript By: Bryan Bishop
Tags: Research, Regulation
Category: Workshop
Regulatory pain points
Ryosuke Ushida
https://twitter.com/kanzure/status/1229838162827993088
Introduction
Hi, good morning everyone. I am a Japanese financial regulator at JFSA. My goal is to promote financial innovations and still ensure the financial stability and various regulatory goals. I have nearly 10 years experience as a regulator. I don’t have a strong background in technology, so I hope I can rely on the other stakeholders on this. I am now in Washington DC doing research on blockchain and governance policy. Based on these experiences, I would like to talk about the pain points from a regulatory perspective and then I would like to propose a multi-stakeholder approach for this ecosystem.
Financial regulation
Some of you might not be familiar with regulation. These are the very fundamental goals for regulators: financial stability maintenance, protecting investors and consumers, and preventing financial crimes. This is very important because this is in the public interest. How can we ensure achieving these goals by working together?
Conventional regulatory approach
A regulator might not be necessary in the near future, if these goals can be achieved by other means than financial regulations. The fundamental approach that is conventional is: first, identify risks and regulatory needs for some topics. Then, if the needs and risks are enough, then we enter into the process of establisihng regulations and statutory laws. Then finally, we do enforcement which is usually entity-based and targets banks or something.
The question is, how can we apply this kind of approach to decentralized finance? Or should we change some of our procedures?
Financial stability
Today’s discussion topic is financial stability. What kind of factors could effect financial stability? You know, financial stability is a very broad concept. There’s no clear definition. If the system is stable, then we can probably make a financial transaction. The idea is to prevent financial crisis. The factor is such that there might be liquidity shortages, excessive risk taking, interconnectedness between systems, operational errors or problems, then credit crunch or political instability. All of these factors can negatively effect financial stability.
Policy development after the crisis: we developed macroprudential tools, OTC derivatives reforms, etc. But were these effective? The question is, how can we apply the existing framework to decentralized financial systems?
Blockchain-based finance
Blockchain-based finance is decentralized, autonomous, globalized, immutable, permissionless and anonymized system. These are features that the traditional financial system generally doesn’t have.
Financial stability implications of decentralized financial system
I tried to sort out the issues by category of risk.
Market risks: the strength is that it could improve transparency of financial transactions, which could enable regulators to do real-time market monitoring and it would be helpful to identify source of risk and amount of risk. But on the other hand, it could have a negative impact due to volatile crypto asset markets, market integrity issues, or outdated monitoring tools.
Credit risks: The decentralized networks can help mitigate counterparty risk, and could reduce maturiy mismatch, and offer better credit assessment. But on the negatives, it could impact cyclicality, or it could cause some impact on monetary policy.
Operation risk: It could reduce human errors, at the cost of unclear responsibility like between developers and miners.
((There are a number of other risks from the slide.))
Regulator’s pain points
There’s a limitatoin on regulation because these are entity-based regulators. There’s monitoring challenges, difficulties in recovery and resolution through effective intervention, and a lack of technical understanding. Most regulators lack technical understanding. Regulation alone may not be enough to achieve regulatory goals when the financial system becomes highly decentralized.
How can we achieve the financial regulatory goals in the public interest, even in a decentralized financial system?
Lessons from the internet
I think we can take some lessons from the development of internet governance. Most of you will be familiar. Before the internet, telecommunication authorities sufficiently regulated intermedaries just like financial regulators regulate banks. But the internet made the traditional approach difficult due to its global and distributed nature similar to the blockchain. Some regulators tried to control the Internet by replacing ICANN (administrator of TCP/IP and DNS) with regulated organizations through a series of United Nation discussions in early 2000s. This attempt failed and they accepted the concept of Multi-stakeholder governance instead.
Some of the issues in cyberspace cannot be solved solely by a regulator. As an example, a regulator tried to crack down on P2P file trading because it was infeasible to crackdown on everyone. Then there was some successful experience working together with regulators and stakeholders.
So maybe we can apply this concept to the blockchain. Law/regulation can be imposed on ecosystem participants such as minors. Market intervention too incentivize players. Government can join social activities to form desirable social norms. The government can translate law into code (“code as law”).
This is from “De Filippi and Wright - Blockchain and the Law” 2018. Use the Laurence Lessig Code, 1997 graph for “classic governance model for cyberspace”- market, norm, law, and architecture.
Acknowledgement
This kind of concept is not only for us, but also for the global regulatory community. We are gradually admitting that there are limitations on traditional approaches, and we have to change our mindset to a multi-stakeholder application. As long as the objectives are considered in the design of applications and protocols, then we think that could help. We need a dialogue with all the stakeholders.
Our idea
What we want is to further develop this concept. We want to develop architectures/codes that comply with law/reuglation, align with norms, and is competitive in the market. This was published last month:
“Call for multi-stakeholder communication to establish a governance mechanism for the emerging blockchain-based financial ecosystem”
Developing such architecture requires multi-stakeholder cooperation. Regulators should give impetus or incentive to develop multi-stakeholder governance, rather than hindering innovation and communication among stakeholders.
Easy?
There’s a lack of harmonization among stakeholders in the blockchain-based financial system. The lack of harmonization is an issue, especially when it comes to the relationship between open-source engineers and regulators. Some engineers might view regulators as enemies, and maybe sometimes vice-versa. We have to bridge the gap between stakeholders.
Healthy governance
The reason for this workshop in many countries is to help figure out multi-stakeholder discussions. Our ultimate goal is to achieve healthy governance through the introduction of code as law and market mechanisms. The regulator should play just one part of the role in the entire ecosystem, in joint with the other stakeholders. Joint work is necessary.
Our journey so far
This is a repetition, but our journey so far is that we had the FSB report on decentralized financial technologies, a June 2019 G20 finance ministers and central bank governors meeting in Fukuoaka, and then there are other workshops listed.
Blockchain global governance conferences
In March in Tokyo there will be a two-day workshop, one is a pane ldiscussion and the other is a day of unconference-style discussions. The participants will include academia, engineers, authorities and central banks, industry experts, etc.
Issues for discussion
Some of the discussion topics can include: privacy vs traceability: are these incompatible values? What are the appropriate KYC/AML requirements? What about standardization and interoperability? Should we wait for organic development for interoperability between blockchains? What about better incentive design to encourage good/bad behavior? What about backdoors and the technical neutrality of regulation? Architecture design ideal for engineers and regulators.
Maybe a regulator can operate a node on the blockchain and record transaction information themselves. This might take some time to change the regulatory mindset, but we should join the discussion and achieve regulatory goals that we want in the discussion together.
These transcripts are sponsored by Blockchain Commons.


Entity Framework Support¶
An EntityFramework-based implementation is provided for the configuration and operational data extensibility points in IdentityServer. The use of EntityFramework allows any EF-supported database to be used with this library.
The repo for this library is located here and the NuGet package is here.
The features provided by this library are broken down into two main areas: configuration store and operational store support. These two different areas can be used independently or together, based upon the needs of the hosting application.
Configuration Store support for Clients, Resources, and CORS settings¶
If client, identity resource, API resource, or CORS data is desired to be loaded from a EF-supported database
(rather than use in-memory configuration), then the configuration store can be used.
This support provides implementations of the IClientStore
, IResourceStore
, and the ICorsPolicyService
extensibility points.
These implementations use a DbContext
-derived class called ConfigurationDbContext
to model the tables in the database.
To use the configuration store support, use the AddConfigurationStore
extension method after the call to AddIdentityServer
:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.EntityFramework-2.0.0;trusted_connection=yes;";
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer()
// this adds the config data from DB (clients, resources, CORS)
.AddConfigurationStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
});
}
To configure the configuration store, use the ConfigurationStoreOptions
options object passed to the configuration callback.
ConfigurationStoreOptions¶
This options class contains properties to control the configuration store and ConfigurationDbContext
.
ConfigureDbContext
- Delegate of type
Action<DbContextOptionsBuilder>
used as a callback to configure the underlyingConfigurationDbContext
. The delegate can configure theConfigurationDbContext
in the same way if EF were being used directly withAddDbContext
, which allows any EF-supported database to be used. DefaultSchema
- Allows setting the default database schema name for all the tables in the
ConfigurationDbContext
.
Operational Store support for authorization grants, consents, and tokens (refresh and reference)¶
If authorization grants, consents, and tokens (refresh and reference) are desired to be loaded from a EF-supported database
(rather than the default in-memory database), then the operational store can be used.
This support provides implementations of the IPersistedGrantStore
extensibility point.
The implementation uses a DbContext
-derived class called PersistedGrantDbContext
to model the table in the database.
To use the operational store support, use the AddOperationalStore
extension method after the call to AddIdentityServer
:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
const string connectionString = @"Data Source=(LocalDb)\MSSQLLocalDB;database=IdentityServer4.EntityFramework-2.0.0;trusted_connection=yes;";
var migrationsAssembly = typeof(Startup).GetTypeInfo().Assembly.GetName().Name;
services.AddIdentityServer()
// this adds the operational data from DB (codes, tokens, consents)
.AddOperationalStore(options =>
{
options.ConfigureDbContext = builder =>
builder.UseSqlServer(connectionString,
sql => sql.MigrationsAssembly(migrationsAssembly));
// this enables automatic token cleanup. this is optional.
options.EnableTokenCleanup = true;
options.TokenCleanupInterval = 30; // interval in seconds
});
}
To configure the operational store, use the OperationalStoreOptions
options object passed to the configuration callback.
OperationalStoreOptions¶
This options class contains properties to control the operational store and PersistedGrantDbContext
.
ConfigureDbContext
- Delegate of type
Action<DbContextOptionsBuilder>
used as a callback to configure the underlyingPersistedGrantDbContext
. The delegate can configure thePersistedGrantDbContext
in the same way if EF were being used directly withAddDbContext
, which allows any EF-supported database to be used. DefaultSchema
- Allows setting the default database schema name for all the tables in the
PersistedGrantDbContext
. EnableTokenCleanup
- Indicates whether stale entries will be automatically cleaned up from the database. The default is
false
. TokenCleanupInterval
- The token cleanup interval (in seconds). The default is 3600 (1 hour).
Database creation and schema changes across different versions of IdentityServer¶
It is very likely that across different versions of IdentityServer (and the EF support) that the database schema will change to accommodate new and changing features.
We do not provide any support for creating your database or migrating your data from one version to another.
Using EF migrations is one possible approach to this. If you do wish to use migrations, then see the EF quickstart for samples on how to get started, or consult the Microsoft documentation on EF migrations.
We also publish sample SQL scripts for the current version of the database schema.


Every man you've ever met, whether they'll admit it or not, has a celebrity man crush.  For me, that man is Paul Rudd.
Here's my top ten favorite movies he's starred in:
These last two are TV shows, but they had me in stitches, so whatever.
You can see the rest of Paul Rudd's filmography here.
Designed & Coded by Henry Quinn


Já Disponível
Observe um texto sem sentido sendo lido, sim, agora mesmo você está fazendo isso, incrivel, não?
Gratuito
One Game
Another One Game
Tree And Half
Fourtress
Five Fools
Sixteen
anything 01
anything 02
anything 03
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything
anything


Carrera Diario Ultimas Noticias 15 km
Quito ECU
Website: www.quitoultimasnoticias15k.ec
Race Winners
(57 runnings)
03 Jun
2007
04 Jun
2006
05 Jun
2005
20 Jun
2004
08 Jun
2003
2002
03 Jun
2001
2000
1999
29 Nov
1998
15 Jun
1997
17 Nov
1996
1995
21 Aug
1994
1993
1992
1991
1990
04 Jun
1989
12 Jun
1988
1987
1986
1985
1984
1983
1982
1981
1980
1979
1978
1977
1976
1975
1974
1973
1972
1971
1970
1969
1968
1967
1966
1965
1964
1963
1962
1961
28 Feb
1960
Notes: 1960 was the inaugural year.
04 Jun
2017
15 km
46:05
Christian Pacheco Mendoza (PER)
54:10
Diana-Judith Landi-3
11 Sepl
2016
15 km
46:06
Bisluke Kiplagat Kipkorir (KEN)
53:41
Wilma-Janeth Arizapana Yucra (PER)
07 Jun
2015
15 km
46:09
Elisha Korir Chumo (KEN)
51:33
Ines Melchor Huiza-3
08 Jun
2014
15 km
46:14
Julius Kipyego Keter (KEN)
52:00
Ines Melchor Huiza-2
02 Jun
2013
15 km
46:42
Miguel-Angel Almachi (ECU)
51:38
Ines Melchor Huiza (PER)
03 Jun
2012
15 km
46:41
Elijah Korir (KEN)
53:35
Gladys-Luci Tejeda Pucuhuarainga (PER)
05 Jun
2011
15 km
46:25
Constantino Leon Lopez (PER)
52:23
Diana-Judith Landi-2
13 Jun
2010
15 km
46:27
Diego-Alberto Colorado (COL)
51:56
Diana-Judith Landi (ECU)
Jun
2009
15 km
44:44.4
Patrick Nthiwa (KEN)
52:49.7
Genoveva Kigen Chelegat (KEN)
01 Jun
2008
15 km
46:13
Isaac Kimaiyo Kemboi (KEN)
53:32
Karina Perez Delgado (MEX)
15 km
46:55
Paulino Canchanya (PER)
54:11
Martha-Ines Ronceria (COL)
15 km
46:40
Franklin Tenorio-2
55:01
Martha Tenorio-10
14 km
43:45
Franklin Tenorio (ECU)
51:08
Martha Tenorio-9
14 km
43:09
Jose-Alirio Carrasco (COL)
51:41
Martha Tenorio-8
13.9 km
42:52
Lazarus Nyakeraka Oyondi (KEN)
51:30
Susana Diaz Escobar (MEX)
---
---
n/a
---
Martha Tenorio-7
13.5 km
42:48
Silvio Guerra-4
49:14
Martha Tenorio-6
---
---
n/a
---
Martha Tenorio-5
---
---
not held due to Pichincha Volcano
eruption
---
not held
due to Pichincha Volcano eruption
13.5 km
42:49
Silvio Guerra-3
48:03
Jane Omoro Moraa (KEN)
13.5 km
42:18
Silvio Guerra-2
50:15
Martha Tenorio-4
13.5 km
42:01
Franklin Tenorio (ECU)
48:30
Martha Tenorio-3
---
---
Rolando Vera-8
---
Martha Tenorio-2
14 km
41:33
Silvio Guerra (ECU)
49:30
Marilu Salazar Musayon (PER)
---
---
Rolando Vera-7
---
n/a
---
---
Rolando Vera-6
---
n/a
---
---
n/a
---
n/a
---
---
Rolando Vera-5
---
n/a
14.3 km
42:45
Rolando Vera-4
---
Martha Tenorio (ECU)
13.7 km
42:18
Rolando Vera-3
50:40
Cecilia Villamarin (ECU)
---
---
Rolando Vera-2
---
n/a
---
---
Rolando Vera (ECU)
---
n/a
---
---
n/a
---
n/a
---
---
n/a
---
n/a
---
---
n/a
---
n/a
---
---
n/a
---
n/a
---
---
Luis Tipan-6
---
n/a
---
---
Luis Tipan-5
---
n/a
---
---
Luis Tipan-4
---
n/a
---
---
Luis Tipan-3
---
n/a
---
---
n/a
---
---
n/a
---
---
n/a
---
---
Luis Tipan-2
---
---
n/a
---
Luis Tipan (ECU)
---
---
n/a
---
---
n/a
---
---
n/a
---
---
n/a
---
---
n/a
---
---
Efren Castelo-3
---
---
Efren Castelo-2
---
---
Efren Castelo (ECU)
---
---
n/a
---
---
n/a
---
---
n/a
6.76 km
---
n/a
Most Wins (1960/date)
Men
8
Rolando
Vera (ECU)
1986-90,1992-93,1995
Women
10
Martha
Tenorio (ECU)
1989,1996-97,2000-02,2004-06
Prize Money (ADR qualified runners)
Year Men Women Total 2017 $8,550 $7,650 $16,200 .... 2015 8,650 7,900 16,550 Sums $17,200 $15,550 $32,750
Race Time Bias (sec/km)
Year Men Women 2017 +5.6 n/c .... 2014 +1.8 n/c .... 2012 +5.3 +8.8 .... 2010 -0.4 n/c .... 2006 +0.9 n/c .... 2004 +1.6 n/c Avgs +2.5 +8.8
Competitive Level (1990-date)
Year Men Women 2017 n/c 190 .... 2015<PHONE_NUMBER> 261 312 .... 2012 368 232 .... 2010 338 408 .... 2008 265 n/c .... 2006 296 n/c .... 2004 410 264 .... 1998 557 n/c 1997 343 n/c 1996 277 n/c
Quality Performances
Men <45:00 1 <45:20 1 <45:40 2 <46:00 2 Women <52:00 3 <52:30 6 <53:00 10 <53:30 13 <54:00 21
Last Updated on 10 Jun 2017
Contributor: Luis Vinker (30)


SQLAlchemy includes an event API which publishes a wide variety of hooks into the internals of both SQLAlchemy Core and ORM.
New in version 0.7: The system supercedes the previous system of “extension”, “proxy”, and “listener” classes.
Subscribing to an event occurs through a single API point, the listen() function. This function accepts a user-defined listening function, a string identifier which identifies the event to be intercepted, and a target. Additional positional and keyword arguments may be supported by specific types of events, which may specify alternate interfaces for the given event function, or provide instructions regarding secondary event targets based on the given target.
The name of an event and the argument signature of a corresponding listener function is derived from a class bound specification method, which exists bound to a marker class that’s described in the documentation. For example, the documentation for PoolEvents.connect() indicates that the event name is "connect" and that a user-defined listener function should receive two positional arguments:
from sqlalchemy.event import listen
from sqlalchemy.pool import Pool
def my_on_connect(dbapi_con, connection_record):
print "New DBAPI connection:", dbapi_con
listen(Pool, 'connect', my_on_connect)
The listen() function is very flexible regarding targets. It generally accepts classes, instances of those classes, and related classes or objects from which the appropriate target can be derived. For example, the above mentioned "connect" event accepts Engine classes and objects as well as Pool classes and objects:
from sqlalchemy.event import listen
from sqlalchemy.pool import Pool, QueuePool
from sqlalchemy import create_engine
from sqlalchemy.engine import Engine
import psycopg2
def connect():
return psycopg2.connect(username='ed', host='<IP_ADDRESS>', dbname='test')
my_pool = QueuePool(connect)
my_engine = create_engine('postgresql://ed@localhost/test')
# associate listener with all instances of Pool
listen(Pool, 'connect', my_on_connect)
# associate listener with all instances of Pool
# via the Engine class
listen(Engine, 'connect', my_on_connect)
# associate listener with my_pool
listen(my_pool, 'connect', my_on_connect)
# associate listener with my_engine.pool
listen(my_engine, 'connect', my_on_connect)
Some listeners allow modifiers to be passed to listen(). These modifiers sometimes provide alternate calling signatures for listeners. Such as with ORM events, some event listeners can have a return value which modifies the subsequent handling. By default, no listener ever requires a return value, but by passing retval=True this value can be supported:
def validate_phone(target, value, oldvalue, initiator):
"""Strip non-numeric characters from a phone number"""
return re.sub(r'(?![0-9])', '', value)
# setup listener on UserContact.phone attribute, instructing
# it to use the return value
listen(UserContact.phone, 'set', validate_phone, retval=True)
Both SQLAlchemy Core and SQLAlchemy ORM feature a wide variety of event hooks:
Register a listener function for the given target.
e.g.:
from sqlalchemy import event
from sqlalchemy.schema import UniqueConstraint
def unique_constraint_name(const, table):
const.name = "uq_%s_%s" % (
table.name,
list(const.columns)[0].name
)
event.listen(
UniqueConstraint,
"after_parent_attach",
unique_constraint_name)
Decorate a function as a listener for the given target + identifier.
e.g.:
from sqlalchemy import event
from sqlalchemy.schema import UniqueConstraint
@event.listens_for(UniqueConstraint, "after_parent_attach")
def unique_constraint_name(const, table):
const.name = "uq_%s_%s" % (
table.name,
list(const.columns)[0].name
)


Covid19 Estimator
Region
Region name
Region Average Age
Average daily income in USD
$
Average daily income population
Use decimal points!
Info
Estimate in days/weeks/months?
Period type
Days
Weeks
Months
Time to elapse
Reported cases
Population
Total hostpital beds


BTS, also known as Bangtan Boys, is a seven-member South Korean boy band formed by Big Hit Entertainment.
On the forth year of their debut, BTS were listed by Forbes as the most retweeted artist on Twitter in March 2016. In 2017, BTS won a Billboard Music Award for Top Social Artist. In June 2017, Time magazine named the band one of the 25 most influential people on the internet.
As a huge fan BTS since 2014, I would like to present a timeline of their albums and links to music videos of my favorite songs in the albums!
| Year of Release | Album name | Youtube Link | Description |
|---|---|---|---|
| 2013.6.12 | 2 COOL 4 SKOOL | No More Dream | Debut EP |
| 2013.9.14 | O!RUL8,2? | N.O | 1st Mini Album |
| 2014.2.12 | Skool Luv Affair | Boy In Luv | 2rd Mini Album |
| 2014.8.20 | DARK & WILD | Hormone War | 1st Album |
| 2015.4.21 | The Most Beautiful Moment in Life Pt.1 | I Need U | 3rd Mini Album |
| 2015.11.30 | The Most Beautiful Moment in Life Pt.2 | Dope | 4th Mini Album |
| 2016.5.2 | Young Forever | Fire | Special Album |
| 2016.10.10 | Wings | Blood Sweat & Tears | 2rd Album |
| 2017.2.13 | You Never Walk Alone | Not Today | Special Album |
| 2017.9.18 | Love Yourself 承 'Her' | DNA | 5th Mini Album |


This is a prototype for registering eligible migrants and refugees into the Adult Migrant English Program (AMEP). This prototype is for testing concepts and does not represent actual specifications for development.
https://gombul.github.io/SkillsHUB/


This demo uses Cobra for Web and the WebVoiceProcessor packages to create an instance of Cobra that listens for voice activity and outputs them to the page. After entering the AccessKey, click the "run Cobra" button.


This page requires JavaScript. Please enable JavaScript in your browser and reload this page.
Products Demo
Back to Demos
View Source
Adobe Software
Product
Category
{name}
{category}
{name}
{category}
Product Overview
{desc}
New Features
{feature}


|
SmartFactory_SorticRoboter_MQTTCommunication
|
The SmartFactroy_MQTTCommunication is an modular part of the SmartFactory project.
MQTTCommunication establishes a WLAN-connection and allows you to connect
with an MQTT-Broker to send and receive message.
Incomming messages need to be in a known JSON-format and will be converted into a struct.
These messages-structs are stored in a circular-buffer.
SmartFactory_MQTTCommunication is part of the SmartFactory-project. It provides a library with basic MQTT-Communication functions.
Other SmartFactory-components are:
A possible implementation of the SmartFactory-project can be seen in the Sortic-showcase:
The associated repositorys are:
SmartFactory-Sortic
SmartFactory_Box-Sortic
SmartFactory_Vehicle-Sortic
SmartFactory_Vehicle-Basis
SmartFactory_MQTTCommunication
The Source-code is written in C++. To achieve this project, the following tools and technologies were used.
Doxygen is used for the documentation of the source code.
An intorduction to Doxygen and how to install it can be found in the ArdFSM-Repo.
The used IDE is VSCode with the PlatformIO-extension.
MQTT (Message Queuing Telemetry Transport) is a lightweight publish-subscribe messaging protocol and requires a broker to relay the messages. It's used for M2M (machine-to-machine) communication.
An MQTT-system always consist of a broker and one or multiple clients, which can be either subscriber or publisher.
[Image: MQTT101 - Eclispe Foundation]
A client can subscribe and publish to one or multiple topics. Topics are organized in a tree similar to a folder-structure in Windows. Here's an example of how such a topic-tree and published message can look like:
This images also illustrates the scalability of MQTT appropriately.
For more Infos about MQTT and MQTT-topics check out the MQTT-Wiki on Github.
[Source: Wiki:MQTT, MQTT ]
A circular buffer or a ring-buffer uses an buffer with fixed Size. If the buffer is full the oldest element gets overwritten.
[Image: Wiki: Circular buffer]
This code needs a WLAN-shield to function properly.
It's tested with a Adafruit Feather M0 WiFi - ATSAMD21 + ATWINC1500 from Adafruit.
All functions and files are documented on the GitHub-Page with Doxygen
Click on the image to open doxygen-documentation.
External libraries:
Click on the image to open doxygen-documentation.
The MQTTCommunication.h-file serves as interface. It provides the functions for:
In the CommunicationConfiguration.h-file are all important settings defined:
In the myJSONStr.h-file is defined how the JSON-message and hence the struct looks like.
This is how the JSON-message (received as String) can look like:
And the corresponding struct in which the message gets parsed:
All you need to do is add the GitHub-Link to this Repo under lib_deps in your platformio.ini File and you're set up. All dependencies are downloaded automatic.
All the Configuration data is stored in the CommunicationConfiguration.h file and can be edited there.
Incoming messages need to be in a know JSON-Format which is defined in* myJSONStr.h* and needs to match the implementation in myJSON::parsingJSONToStruct. If you would like to change this format you need to adapt both files.
The open ToDo's can be found in the Documentation on the GitHub-Page
V 1.0 - Release BA FS19 - Luca Mazzoleni
MIT License


|
|
|
We're introducing the EnterpriseReady Podcast, a new show advancing the conversation about how to build for the enterprise.
|
|
The first two episodes are available now. In them I talk with Adam Jacob, CTO of Chef, and Tom Preston-Werner, Cofounder of GitHub and Chatterbug.
|
|
|
|
|
|
This show features in-depth interviews with industry experts and enterprise software founders. We break through the jargon, establish a common vernacular and share the lessons learned from BUILDING the world’s best enterprise software.
|
|
EnterpriseReady is hosted by me, Grant Miller, creator of EnterpriseReady and co-founder and CEO of Replicated, who are powering the worlds best enterprise software.
|
|
Be sure to subscribe to the podcast because up and coming episodes include interviews with Peter Reinhardt, CEO and Cofounder of Segment; Alex Polvi, CEO and Cofounder of CoreOS; and Andrew Peterson, CEO and Founder of Signal Sciences.
|
|
If you'd like to listen to the episodes outside of iTunes, you can listen on Heavybit. If you’ve enjoyed the podcast, please leave a quick iTunes review here, it will help more people discover EnterpriseReady.
|
- Grant Miller & The Team at EnterpriseReady
|


--- layout: post status: publish published: true title: Whidbey SDR? author: display_name: Tomas Restrepo login: tomasr email<EMAIL_ADDRESS>url: http://winterdom.com/ author_login: tomasr author_email<EMAIL_ADDRESS>author_url: http://winterdom.com/ wordpress_id: 414 wordpress_url: http://winterdom.com/2003/06/whidbeysdr date: '2003-06-28 07:28:28 +0000' date_gmt: '2003-06-28 07:28:28 +0000' categories: - ".NET" tags: [] comments: [] ---
It seems a few people were last week at the Whidbey SDR in Redmond.
Cool. Now my question is: What is the focus of such an SDR? Now, I'm not asking for
what was specifically said during the SDR; I'm just curious whether what kinds of
things where covered in the SDR that's not somehow already covered by the SDRs the
individual teams in the suite already do... (unless, this SDR was not about VS.NET
per se, but rather the framework, in which case I supose it'd be understandable).


csvfind [OPTIONS] TEXT_TO_MATCH
csvfind processes a CSV file as input returning rows that contain the column with matched text. Columns are count from one instead of zero. Supports exact match as well as some Levenshtein matching.
-allow-duplicates allow duplicates when searching for matches
-append-edit-distance append column with edit distance found (useful for tuning levenshtein)
-case-sensitive perform a case sensitive match (default is false)
-col column to search for match in the CSV file
-contains use contains phrase for matching
-delete-cost set the delete cost to use for levenshtein matching
-h display help
-help display help
-i input filename
-input input filename
-insert-cost set the insert cost to use for levenshtein matching
-l display license
-levenshtein use levenshtein matching
-license display license
-max-edit-distance set the edit distance thresh hold for match, default 0
-o output filename
-output output filename
-skip-header-row skip the header row
-stop-words use the colon delimited list of stop words
-substitute-cost set the substitution cost to use for levenshtein matching
-trim-spaces trim spaces around cell values before comparing
-v display version
-version display version
Find the rows where the third column matches “The Red Book of Westmarch” exactly
csvfind -i books.csv -col=2 "The Red Book of Westmarch"
Find the rows where the third column (colums numbered 0,1,2) matches approximately “The Red Book of Westmarch”
csvfind -i books.csv -col=2 -levenshtein \
-insert-cost=1 -delete-cost=1 -substitute-cost=3 \
-max-edit-distance=50 -append-edit-distance \
"The Red Book of Westmarch"
In this example we’ve appended the edit distance to see how close the matches are.
You can also search for phrases in columns.
csvfind -i books.csv -col=2 -contains "Red Book"


--- layout: page title: About header-img: "img/about-bg.png" ---
A bit type A, a little OCD, I look at every side of something till I make sense of it. Yet I find it fun and get inspired, when I can sit down and figure out a problem. I love the challenge of the unknown and even though I goof up along the way, I am always a bit closer than I was before.


Design helps you empathize with your customer and learn their pain points through a repeatable process you can pick up today.
You are really in the business of providing value to your customers. If you solve their problems more effectively, you should expect growth.
Best of all, you can learn how to put these ideas into action at no cost to you, online, today. You have nothing to lose.
Complete online resource.
See growth in your business.
Inside the site, our material is a complete online resource that teaches you the basics of applying user centered design thinking to engage your real customers and find product market fit.


Urbanization refers to the increasing number of people that live in urban areas. It predominantly results in the physical growth of urban areas, be it horizontal or vertical. The United Nations projected that half of the world's population would live in urban areas at the end of 2008. By 2050 it is predicted that 64.1% and 85.9% of the developing and developed world respectively will be urbanized. Urbanization is closely linked to modernization, industrialization, and the sociological process of rationalization. Urbanization can describe a specific condition at a set time, i.e. the proportion of total population or area in cities or towns, or the term can describe the increase of this proportion over time. So the term urbanization can represent the level of urban development relative to overall population, or it can represent the rate at which the urban proportion is increasing. Urbanization is not merely a modern phenomenon, but a rapid and historic transformation of human social roots on a global scale, whereby predominantly rural culture is being rapidly replaced by predominantly urban culture. The last major change in settlement patterns was the accumulation of hunter-gatherers into villages many thousand years ago. Village culture is characterized by common bloodlines, intimate relationships, and communal behavior whereas urban culture is characterized by distant bloodlines, unfamiliar relations, and competitive behavior. This unprecedented movement of people is forecast to continue and intensify in the next few decades, mushrooming cities to sizes incomprehensible only a century ago.
Read More


Class TransformedCurve2D
A general 2D Curve which results from a non-affine transformation of the 2D space
Inheritance
System.Object
TransformedCurve2D
Implements
System.Runtime.Serialization.ISerializable
Inherited Members
System.Object.Equals(System.Object)
System.Object.Equals(System.Object, System.Object)
System.Object.GetHashCode()
System.Object.GetType()
System.Object.MemberwiseClone()
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.ToString()
Assembly: CADability.dll
public class TransformedCurve2D : TriangulatedCurve2D, ICurve2D, IQuadTreeInsertable, ISerializable
Constructors
|
Improve this Doc
View Source
Declaration
public TransformedCurve2D(ICurve2D original, ICurveTransformation2D transformation2D)
Parameters
Properties
|
Improve this Doc
View Source
Declaration
public override GeoPoint2D EndPoint { get; set; }
Property Value
Overrides
|
Improve this Doc
View Source
Declaration
public override GeoPoint2D StartPoint { get; set; }
Property Value
Overrides
Methods
|
Improve this Doc
View Source
Declaration
public override ICurve2D Clone()
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override ICurve2D CloneReverse(bool reverse)
Parameters
| Type |
Name |
Description |
| System.Boolean |
reverse |
|
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override void Copy(ICurve2D toCopyFrom)
Parameters
| Type |
Name |
Description |
| ICurve2D |
toCopyFrom |
|
Overrides
|
Improve this Doc
View Source
Declaration
public override GeoVector2D DirectionAt(double Position)
Parameters
| Type |
Name |
Description |
| System.Double |
Position |
|
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override ICurve2D GetModified(ModOp2D m)
Parameters
Returns
Overrides
|
Improve this Doc
View Source
Declaration
protected override void GetTriangulationBasis(out GeoPoint2D[] points, out GeoVector2D[] directions, out double[] parameters)
Parameters
Overrides
|
Improve this Doc
View Source
Declaration
public override void Move(double x, double y)
Parameters
| Type |
Name |
Description |
| System.Double |
x |
|
| System.Double |
y |
|
Overrides
|
Improve this Doc
View Source
Declaration
public override GeoPoint2D PointAt(double Position)
Parameters
| Type |
Name |
Description |
| System.Double |
Position |
|
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override double PositionOf(GeoPoint2D p)
Parameters
Returns
| Type |
Description |
| System.Double |
|
Overrides
|
Improve this Doc
View Source
Declaration
public override void Reverse()
Overrides
|
Improve this Doc
View Source
Declaration
public override ICurve2D[] Split(double Position)
Parameters
| Type |
Name |
Description |
| System.Double |
Position |
|
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override ICurve2D Trim(double StartPos, double EndPos)
Parameters
| Type |
Name |
Description |
| System.Double |
StartPos |
|
| System.Double |
EndPos |
|
Returns
Overrides
|
Improve this Doc
View Source
Declaration
public override bool TryPointDeriv2At(double position, out GeoPoint2D point, out GeoVector2D deriv, out GeoVector2D deriv2)
Parameters
Returns
| Type |
Description |
| System.Boolean |
|
Overrides
Implements
System.Runtime.Serialization.ISerializable


ghdlfiddle - stats
open-source vhdl judge
back to main
Downloading stats...
Start date:
End date:
Update!
©
2019-2022
Bruno Borges Paschoalinoto
No rights reserved.
Check out the code!


A comprehensive list of the courses I've taken at Stanford, with my retrospective thoughts (click to expand).
{% for semester in coursework %}
{% markdown %}
#### {{semester.name}}
{% endmarkdown %}
{% for course in semester.courses %}
{{course.name}}
{{course.desc}}
{% endfor %}
{% endfor %}


This filter includes/excludes jobs based on whether certain
job properties match regular expressions.
Options
- Regular Expression:
-
The regular expression to use for matching.
See the full list of available patterns.
- Match Value:
-
The job property to match. One of the following:
- Job name
- Name of the job itself, e.g. 'job'
- Full name of the job including parent folders, e.g. 'folder/subfolder/job'
- Display name of the job, e.g. 'Job'
- Full display name of the job including parent folders, e.g. 'Folder » SubFolder » Job'
- Job folder name: the name of the job's parent folder
- Name of the folder itself, e.g. 'subfolder'
- Full name of the folder including parent folders, e.g. 'folder/subfolder'
- Display name of the folder, e.g. 'SubFolder'
- Full display name of the folder including parent folders, e.g. 'Folder » SubFolder'
- Job description
- Job SCM configuration: matching by SCM is extremely useful if you have hundreds of jobs that need
to be "auto organized", and are already organized under source control. (Currently matches against SVN,
Git, and CVS paths/configuration)
- Email recipients: matching by email is useful for organizing by "who cares about this job."
- Maven configuration: use this to match against "what does this job do"
- Job schedule: matches against the CRON pattern and any comments for Timer and SCM triggers.
- Node label expression: matches against the Label Expression under the "Restrict where this
project can be run" option.
- Match type:
-
Whether to add or remove jobs from this view. There's two kinds of match types:
- Include matched/unmatched: adds additional jobs to this view.
- Exclude matched/unmatched: removes jobs from this view that have been included by previous filters.


template<class S> class MPIslave { public: int nprocs, myid; vector<int> idle; /* list of waiting slaves, valid on master */ MPIslave(); ~MPIslave() {finalize();} void init(); void finalize(); MPIbuf& operator<<(void (S::*m)(MPIbuf&)) template <class T> MPIbuf& operator<<(const T& x); void exec(MPIbuf& x); MPIbuf& get_returnv(); void wait_all_idle(); void bcast(MPIbuf& c=cmd); };
MPIslave is an implementation of a master-slave application. An
MPIslave object must be created within an MPI parallel region (eg
created by MPISPMD). The slave
code is implemented as a class (S say), with each method
implementing a remote procedure(see §8.3.1)
being of type void (MPIbuf&)
. Declaring a variable of type
MPIslave<S>
will set up an interpreter on the slave processor. The remote processes
are closed down once the variable is finalised, or goes out of scope.
See the file mandelbrot.cc in the mpi-examples for an example of how this works.
operator<<
is provided as a convenience -- one can compose a
message of the form:
MPIslave<S> slave; slave << &S::foo << x << send(1);without needing to declare additional MPIbufs.
For managing a list of idle slaves, the idle vector is employed, and is manipulated through the exec method, which dispatches a command to be executed on a slave, and the get_returnv() which returns the returned result as an MPIbuf, and places the processor from which it received a value back on the idle list. This technique is only valid for slave methods returning a message (even if its a null message). The wait_all_idle method waits for all slaves to return.
The bcast() method is a convenience method for sending the contents of MPISlave::cmd, or the optional MPIbuf argument to all slaves.


Measure of agreement delta was originally by Martín & Femia (2004) <doi:10.1348/000711004849268>. Since then has been considered as agreement measure for different fields, since their behavior is usually better than the usual kappa index by Cohen (1960) <doi:10.1177/001316446002000104>. The main issue with delta is that can not be computed by hand contrary to kappa. The current algorithm is based on the Version 5 of the delta windows program that can be found on <https://www.ugr.es/~bioest/software/delta/cmd.php?seccion=downloads>.
| Version: | <IP_ADDRESS> |
| Depends: | R (≥ 3.2.0) |
| Imports: | stats |
| Published: | 2018-10-04 |
| Author: | Antonio Rodriguez [aut, cre], Pedro Femia [cph, ctb], Antonio Martin [cph, ctb] |
| Maintainer: | Antonio Rodriguez <tonirodriguezcontesti at gmail.com> |
| License: | GPL-3 |
| NeedsCompilation: | no |
| CRAN checks: | Delta results |
| Reference manual: | Delta.pdf |
| Package source: | Delta_<IP_ADDRESS>.tar.gz |
| Windows binaries: | r-devel: Delta_<IP_ADDRESS>.zip, r-release: Delta_<IP_ADDRESS>.zip, r-oldrel: Delta_<IP_ADDRESS>.zip |
| OS X binaries: | r-release: Delta_<IP_ADDRESS>.tgz, r-oldrel: Delta_<IP_ADDRESS>.tgz |
| Old sources: | Delta archive |
Please use the canonical form https://CRAN.R-project.org/package=Delta to link to this page.


|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| ConcurrentReaderHashMap.java | 27,8% | 29,7% | 17,5% | 27,6% |
|
| 1 | /* | |
| 2 | File: ConcurrentReaderHashMap | |
| 3 | ||
| 4 | Written by Doug Lea. Adapted and released, under explicit | |
| 5 | permission, from JDK1.2 HashMap.java and Hashtable.java which | |
| 6 | carries the following copyright: | |
| 7 | ||
| 8 | * Copyright 1997 by Sun Microsystems, Inc., | |
| 9 | * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A. | |
| 10 | * All rights reserved. | |
| 11 | * | |
| 12 | * This software is the confidential and proprietary information | |
| 13 | * of Sun Microsystems, Inc. ("Confidential Information"). You | |
| 14 | * shall not disclose such Confidential Information and shall use | |
| 15 | * it only in accordance with the terms of the license agreement | |
| 16 | * you entered into with Sun. | |
| 17 | ||
| 18 | History: | |
| 19 | Date Who What | |
| 20 | 28oct1999 dl Created | |
| 21 | 14dec1999 dl jmm snapshot | |
| 22 | 19apr2000 dl use barrierLock | |
| 23 | 12jan2001 dl public release | |
| 24 | 17nov2001 dl Minor tunings | |
| 25 | 20may2002 dl BarrierLock can now be serialized. | |
| 26 | 09dec2002 dl Fix interference checks. | |
| 27 | */ | |
| 28 | ||
| 29 | package org.dom4j.tree; | |
| 30 | ||
| 31 | import java.io.IOException; | |
| 32 | import java.io.Serializable; | |
| 33 | import java.util.AbstractCollection; | |
| 34 | import java.util.AbstractMap; | |
| 35 | import java.util.AbstractSet; | |
| 36 | import java.util.Collection; | |
| 37 | import java.util.Enumeration; | |
| 38 | import java.util.Iterator; | |
| 39 | import java.util.Map; | |
| 40 | import java.util.NoSuchElementException; | |
| 41 | import java.util.Set; | |
| 42 | ||
| 43 | /** | |
| 44 | * A version of Hashtable that supports mostly-concurrent reading, but exclusive | |
| 45 | * writing. Because reads are not limited to periods without writes, a | |
| 46 | * concurrent reader policy is weaker than a classic reader/writer policy, but | |
| 47 | * is generally faster and allows more concurrency. This class is a good choice | |
| 48 | * especially for tables that are mainly created by one thread during the | |
| 49 | * start-up phase of a program, and from then on, are mainly read (with perhaps | |
| 50 | * occasional additions or removals) in many threads. If you also need | |
| 51 | * concurrency among writes, consider instead using ConcurrentHashMap. | |
| 52 | *
 | |
| 53 | * | |
| 54 | * Successful retrievals using get(key) and containsKey(key) usually run without | |
| 55 | * locking. Unsuccessful ones (i.e., when the key is not present) do involve | |
| 56 | * brief synchronization (locking). Also, the size and isEmpty methods are | |
| 57 | * always synchronized. | |
| 58 | * | |
| 59 | *
 | |
| 60 | * Because retrieval operations can ordinarily overlap with writing operations | |
| 61 | * (i.e., put, remove, and their derivatives), retrievals can only be guaranteed | |
| 62 | * to return the results of the most recently completed operations | |
| 63 | * holding upon their onset. Retrieval operations may or may not return results | |
| 64 | * reflecting in-progress writing operations. However, the retrieval operations | |
| 65 | * do always return consistent results -- either those holding before any single | |
| 66 | * modification or after it, but never a nonsense result. For aggregate | |
| 67 | * operations such as putAll and clear, concurrent reads may reflect insertion | |
| 68 | * or removal of only some entries. In those rare contexts in which you use a | |
| 69 | * hash table to synchronize operations across threads (for example, to prevent | |
| 70 | * reads until after clears), you should either encase operations in | |
| 71 | * synchronized blocks, or instead use java.util.Hashtable. | |
| 72 | * | |
| 73 | *
 | |
| 74 | * | |
| 75 | * This class also supports optional guaranteed exclusive reads, simply by | |
| 76 | * surrounding a call within a synchronized block, as in
 | |
| 77 | * ConcurrentReaderHashMap t; ... Object v;
 | |
| 78 | * synchronized(t) { v = t.get(k); }
 | |
| 79 | * | |
| 80 | * But this is not usually necessary in practice. For example, it is generally | |
| 81 | * inefficient to write: | |
| 82 | * | |
| 83 | *
 | |
| 84 | * | |
| 85 | * | |
| 86 | * ConcurrentReaderHashMap t; ... // Inefficient version | |
| 87 | * Object key; ... | |
| 88 | * Object value; ... | |
| 89 | * synchronized(t) { | |
| 90 | * if (!t.containsKey(key)) | |
| 91 | * t.put(key, value); | |
| 92 | * // other code if not previously present | |
| 93 | * } | |
| 94 | * else { | |
| 95 | * // other code if it was previously present | |
| 96 | * } | |
| 97 | * } | |
| 98 | * | |
| 99 | * | |
| 100 | *
 | |
| 101 | * | |
| 102 | * Instead, if the values are intended to be the same in each case, just take | |
| 103 | * advantage of the fact that put returns null if the key was not previously | |
| 104 | * present: | |
| 105 | * | |
| 106 | *
 | |
| 107 | * | |
| 108 | * | |
| 109 | * ConcurrentReaderHashMap t; ... // Use this instead | |
| 110 | * Object key; ... | |
| 111 | * Object value; ... | |
| 112 | * Object oldValue = t.put(key, value); | |
| 113 | * if (oldValue == null) { | |
| 114 | * // other code if not previously present | |
| 115 | * } | |
| 116 | * else { | |
| 117 | * // other code if it was previously present | |
| 118 | * } | |
| 119 | * | |
| 120 | * | |
| 121 | *
 | |
| 122 | * | |
| 123 | *
 | |
| 124 | * | |
| 125 | * Iterators and Enumerations (i.e., those returned by keySet().iterator(), | |
| 126 | * entrySet().iterator(), values().iterator(), keys(), and elements()) return | |
| 127 | * elements reflecting the state of the hash table at some point at or since the | |
| 128 | * creation of the iterator/enumeration. They will return at most one instance | |
| 129 | * of each element (via next()/nextElement()), but might or might not reflect | |
| 130 | * puts and removes that have been processed since they were created. They do | |
| 131 | * not throw ConcurrentModificationException. However, these | |
| 132 | * iterators are designed to be used by only one thread at a time. Sharing an | |
| 133 | * iterator across multiple threads may lead to unpredictable results if the | |
| 134 | * table is being concurrently modified. Again, you can ensure interference-free | |
| 135 | * iteration by enclosing the iteration in a synchronized block. | |
| 136 | *
 | |
| 137 | * | |
| 138 | * This class may be used as a direct replacement for any use of | |
| 139 | * java.util.Hashtable that does not depend on readers being blocked during | |
| 140 | * updates. Like Hashtable but unlike java.util.HashMap, this class does NOT | |
| 141 | * allow <tt>null</tt> to be used as a key or value. This class is also | |
| 142 | * typically faster than ConcurrentHashMap when there is usually only one thread | |
| 143 | * updating the table, but possibly many retrieving values from it. | |
| 144 | *
 | |
| 145 | * | |
| 146 | * Implementation note: A slightly faster implementation of this class will be | |
| 147 | * possible once planned Java Memory Model revisions are in place. | |
| 148 | * | |
| 149 | *
[  | |
| 151 | * Introduction to this package. ] | |
| 152 | * | |
| 153 | */ | |
| 154 | ||
| 155 | class ConcurrentReaderHashMap extends AbstractMap implements Map, Cloneable, | |
| 156 | Serializable { | |
| 157 | ||
| 158 | /* | |
| 159 | * The basic strategy is an optimistic-style scheme based on the guarantee | |
| 160 | * that the hash table and its lists are always kept in a consistent enough | |
| 161 | * state to be read without locking: | |
| 162 | * | |
| 163 | * Read operations first proceed without locking, by traversing the | |
| 164 | * apparently correct list of the apparently correct bin. If an entry is | |
| 165 | * found, but not invalidated (value field null), it is returned. If not | |
| 166 | * found, operations must recheck (after a memory barrier) to make sure they | |
| 167 | * are using both the right list and the right table (which can change under | |
| 168 | * resizes). If invalidated, reads must acquire main update lock to wait out | |
| 169 | * the update, and then re-traverse. | |
| 170 | * | |
| 171 | * All list additions are at the front of each bin, making it easy to check | |
| 172 | * changes, and also fast to traverse. Entry next pointers are never | |
| 173 | * assigned. Remove() builds new nodes when necessary to preserve this. | |
| 174 | * | |
| 175 | * Remove() (also clear()) invalidates removed nodes to alert read | |
| 176 | * operations that they must wait out the full modifications. | |
| 177 | * | |
| 178 | */ | |
| 179 | ||
| 180 | /** A Serializable class for barrier lock * */ | |
| 181 | protected static class BarrierLock implements java.io.Serializable { | |
| 182 | } | |
| 183 | ||
| 184 | /** | |
| 185 | * Lock used only for its memory effects. | |
| 186 | */ | |
| 187 | protected final BarrierLock barrierLock = new BarrierLock(); | |
| 188 | ||
| 189 | /** | |
| 190 | * field written to only to guarantee lock ordering. | |
| 191 | */ | |
| 192 | ||
| 193 | protected transient Object lastWrite; | |
| 194 | ||
| 195 | /** | |
| 196 | * Force a memory synchronization that will cause all readers to see table. | |
| 197 | * Call only when already holding main synch lock. | |
| 198 | */ | |
| 199 | 20624 | protected final void recordModification(Object x) { |
| 200 | 20624 | synchronized (barrierLock) { |
| 201 | 20624 | lastWrite = x; |
| 202 | } | |
| 203 | } | |
| 204 | ||
| 205 | /** | |
| 206 | * Get ref to table; the reference and the cells it accesses will be at | |
| 207 | * least as fresh as from last use of barrierLock | |
| 208 | */ | |
| 209 | 41248 | protected final Entry[] getTableForReading() { |
| 210 | 41248 | synchronized (barrierLock) { |
| 211 | 41248 | return table; |
| 212 | } | |
| 213 | } | |
| 214 | ||
| 215 | /** | |
| 216 | * The default initial number of table slots for this table (32). Used when | |
| 217 | * not otherwise specified in constructor. | |
| 218 | */ | |
| 219 | public static int DEFAULT_INITIAL_CAPACITY = 32; | |
| 220 | ||
| 221 | /** | |
| 222 | * The minimum capacity, used if a lower value is implicitly specified by | |
| 223 | * either of the constructors with arguments. MUST be a power of two. | |
| 224 | */ | |
| 225 | private static final int MINIMUM_CAPACITY = 4; | |
| 226 | ||
| 227 | /** | |
| 228 | * The maximum capacity, used if a higher value is implicitly specified by | |
| 229 | * either of the constructors with arguments. MUST be a power of two <= 1 < | |
| 230 | * <30. | |
| 231 | */ | |
| 232 | private static final int MAXIMUM_CAPACITY = 1 << 30; | |
| 233 | ||
| 234 | /** | |
| 235 | * The default load factor for this table (1.0). Used when not otherwise | |
| 236 | * specified in constructor. | |
| 237 | */ | |
| 238 | ||
| 239 | public static final float DEFAULT_LOAD_FACTOR = 0.75f; | |
| 240 | ||
| 241 | /** | |
| 242 | * The hash table data. | |
| 243 | */ | |
| 244 | protected transient Entry[] table; | |
| 245 | ||
| 246 | /** | |
| 247 | * The total number of mappings in the hash table. | |
| 248 | */ | |
| 249 | protected transient int count; | |
| 250 | ||
| 251 | /** | |
| 252 | * The table is rehashed when its size exceeds this threshold. (The value of | |
| 253 | * this field is always (int)(capacity * loadFactor).) | |
| 254 | * | |
| 255 | * @serial | |
| 256 | */ | |
| 257 | protected int threshold; | |
| 258 | ||
| 259 | /** | |
| 260 | * The load factor for the hash table. | |
| 261 | * | |
| 262 | * @serial | |
| 263 | */ | |
| 264 | protected float loadFactor; | |
| 265 | ||
| 266 | /** | |
| 267 | * Returns the appropriate capacity (power of two) for the specified initial | |
| 268 | * capacity argument. | |
| 269 | */ | |
| 270 | 10476 | private int p2capacity(int initialCapacity) { |
| 271 | 10476 | int cap = initialCapacity; |
| 272 | ||
| 273 | // Compute the appropriate capacity | |
| 274 | 10476 | int result; |
| 275 | 10476 | if (cap > MAXIMUM_CAPACITY || cap < 0) { |
| 276 | 0 | result = MAXIMUM_CAPACITY; |
| 277 | } else { | |
| 278 | 10476 | result = MINIMUM_CAPACITY; |
| 279 | 10476 | while (result < cap) |
| 280 | 31428 | result <<= 1; |
| 281 | } | |
| 282 | 10476 | return result; |
| 283 | } | |
| 284 | ||
| 285 | /** | |
| 286 | * Return hash code for Object x. Since we are using power-of-two tables, it | |
| 287 | * is worth the effort to improve hashcode via the same multiplicative | |
| 288 | * scheme as used in IdentityHashMap. | |
| 289 | */ | |
| 290 | 2283990 | private static int hash(Object x) { |
| 291 | 2283990 | int h = x.hashCode(); |
| 292 | // Multiply by 127 (quickly, via shifts), and mix in some high | |
| 293 | // bits to help guard against bunching of codes that are | |
| 294 | // consecutive or equally spaced. | |
| 295 | 2283990 | return ((h << 7) - h + (h >>> 9) + (h >>> 17)); |
| 296 | } | |
| 297 | ||
| 298 | /** | |
| 299 | * Check for equality of non-null references x and y. | |
| 300 | */ | |
| 301 | 2222118 | protected boolean eq(Object x, Object y) { |
| 302 | 2222118 | return x == y || x.equals(y); |
| 303 | } | |
| 304 | ||
| 305 | /** | |
| 306 | * Constructs a new, empty map with the specified initial capacity and the | |
| 307 | * specified load factor. | |
| 308 | * | |
| 309 | * @param initialCapacity | |
| 310 | * the initial capacity The actual initial capacity is rounded to | |
| 311 | * the nearest power of two. | |
| 312 | * @param loadFactor | |
| 313 | * the load factor of the ConcurrentReaderHashMap | |
| 314 | * @throws IllegalArgumentException | |
| 315 | * if the initial maximum number of elements is less than zero, | |
| 316 | * or if the load factor is nonpositive. | |
| 317 | */ | |
| 318 | ||
| 319 | 10476 | public ConcurrentReaderHashMap(int initialCapacity, float loadFactor) { |
| 320 | 10476 | if (loadFactor <= 0) |
| 321 | 0 | throw new IllegalArgumentException("Illegal Load factor: " |
| 322 | + loadFactor); | |
| 323 | 10476 | this.loadFactor = loadFactor; |
| 324 | ||
| 325 | 10476 | int cap = p2capacity(initialCapacity); |
| 326 | ||
| 327 | 10476 | table = new Entry[cap]; |
| 328 | 10476 | threshold = (int) (cap * loadFactor); |
| 329 | } | |
| 330 | ||
| 331 | /** | |
| 332 | * Constructs a new, empty map with the specified initial capacity and | |
| 333 | * default load factor. | |
| 334 | * | |
| 335 | * @param initialCapacity | |
| 336 | * the initial capacity of the ConcurrentReaderHashMap. | |
| 337 | * @throws IllegalArgumentException | |
| 338 | * if the initial maximum number of elements is less than zero. | |
| 339 | */ | |
| 340 | ||
| 341 | 0 | public ConcurrentReaderHashMap(int initialCapacity) { |
| 342 | 0 | this(initialCapacity, DEFAULT_LOAD_FACTOR); |
| 343 | } | |
| 344 | ||
| 345 | /** | |
| 346 | * Constructs a new, empty map with a default initial capacity and load | |
| 347 | * factor. | |
| 348 | */ | |
| 349 | ||
| 350 | 10476 | public ConcurrentReaderHashMap() { |
| 351 | 10476 | this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR); |
| 352 | } | |
| 353 | ||
| 354 | /** | |
| 355 | * Constructs a new map with the same mappings as the given map. The map is | |
| 356 | * created with a capacity of twice the number of mappings in the given map | |
| 357 | * or 16 (whichever is greater), and a default load factor. | |
| 358 | */ | |
| 359 | ||
| 360 | 0 | public ConcurrentReaderHashMap(Map t) { |
| 361 | 0 | this(Math.max((int) (t.size() / DEFAULT_LOAD_FACTOR) + 1, 16), |
| 362 | DEFAULT_LOAD_FACTOR); | |
| 363 | 0 | putAll(t); |
| 364 | } | |
| 365 | ||
| 366 | /** | |
| 367 | * Returns the number of key-value mappings in this map. | |
| 368 | * | |
| 369 | * @return the number of key-value mappings in this map. | |
| 370 | */ | |
| 371 | ||
| 372 | 0 | public synchronized int size() { |
| 373 | 0 | return count; |
| 374 | } | |
| 375 | ||
| 376 | /** | |
| 377 | * Returns <tt>true</tt> if this map contains no key-value mappings. | |
| 378 | * | |
| 379 | * @return <tt>true</tt> if this map contains no key-value mappings. | |
| 380 | */ | |
| 381 | ||
| 382 | 0 | public synchronized boolean isEmpty() { |
| 383 | 0 | return count == 0; |
| 384 | } | |
| 385 | ||
| 386 | /** | |
| 387 | * Returns the value to which the specified key is mapped in this table. | |
| 388 | * | |
| 389 | * @param key | |
| 390 | * a key in the table. | |
| 391 | * @return the value to which the key is mapped in this table; | |
| 392 | * null if the key is not mapped to any value in this | |
| 393 | * table. | |
| 394 | * @exception NullPointerException | |
| 395 | * if the key is null. | |
| 396 | * @see #put(Object, Object) | |
| 397 | */ | |
| 398 | ||
| 399 | 2263360 | public Object get(Object key) { |
| 400 | ||
| 401 | // throw null pointer exception if key null | |
| 402 | 2263360 | int hash = hash(key); |
| 403 | ||
| 404 | /* | |
| 405 | * Start off at the apparently correct bin. If entry is found, we need | |
| 406 | * to check after a barrier anyway. If not found, we need a barrier to | |
| 407 | * check if we are actually in right bin. So either way, we encounter | |
| 408 | * only one barrier unless we need to retry. And we only need to fully | |
| 409 | * synchronize if there have been concurrent modifications. | |
| 410 | */ | |
| 411 | ||
| 412 | 2263360 | Entry[] tab = table; |
| 413 | 2263360 | int index = hash & (tab.length - 1); |
| 414 | 2263360 | Entry first = tab[index]; |
| 415 | 2263360 | Entry e = first; |
| 416 | ||
| 417 | 2263360 | for (;;) { |
| 418 | 2272846 | if (e == null) { |
| 419 | ||
| 420 | // If key apparently not there, check to | |
| 421 | // make sure this was a valid read | |
| 422 | ||
| 423 | 41248 | Entry[] reread = getTableForReading(); |
| 424 | 41248 | if (tab == reread && first == tab[index]) |
| 425 | 41248 | return null; |
| 426 | else { | |
| 427 | // Wrong list -- must restart traversal at new first | |
| 428 | 0 | tab = reread; |
| 429 | 0 | e = first = tab[index = hash & (tab.length - 1)]; |
| 430 | } | |
| 431 | ||
| 432 | } | |
| 433 | ||
| 434 | 2231598 | else if (e.hash == hash && eq(key, e.key)) { |
| 435 | 2222112 | Object value = e.value; |
| 436 | 2222112 | if (value != null) |
| 437 | 2222112 | return value; |
| 438 | ||
| 439 | // Entry was invalidated during deletion. But it could | |
| 440 | // have been re-inserted, so we must retraverse. | |
| 441 | // To avoid useless contention, get lock to wait out | |
| 442 | // modifications | |
| 443 | // before retraversing. | |
| 444 | ||
| 445 | 0 | synchronized (this) { |
| 446 | 0 | tab = table; |
| 447 | } | |
| 448 | 0 | e = first = tab[index = hash & (tab.length - 1)]; |
| 449 | ||
| 450 | } else | |
| 451 | 9486 | e = e.next; |
| 452 | } | |
| 453 | } | |
| 454 | ||
| 455 | /** | |
| 456 | * Tests if the specified object is a key in this table. | |
| 457 | * | |
| 458 | * @param key | |
| 459 | * possible key. | |
| 460 | * @return true if and only if the specified object is a key | |
| 461 | * in this table, as determined by the <tt>equals</tt> method; | |
| 462 | * false otherwise. | |
| 463 | * @exception NullPointerException | |
| 464 | * if the key is null. | |
| 465 | * @see #contains(Object) | |
| 466 | */ | |
| 467 | ||
| 468 | 0 | public boolean containsKey(Object key) { |
| 469 | 0 | return get(key) != null; |
| 470 | } | |
| 471 | ||
| 472 | /** | |
| 473 | * Maps the specified key to the specified value | |
| 474 | * in this table. Neither the key nor the value can be null. | |
| 475 | *
 | |
| 476 | * | |
| 477 | * The value can be retrieved by calling the get method with | |
| 478 | * a key that is equal to the original key. | |
| 479 | * | |
| 480 | * @param key | |
| 481 | * the table key. | |
| 482 | * @param value | |
| 483 | * the value. | |
| 484 | * @return the previous value of the specified key in this table, or | |
| 485 | * null if it did not have one. | |
| 486 | * @exception NullPointerException | |
| 487 | * if the key or value is null. | |
| 488 | * @see Object#equals(Object) | |
| 489 | * @see #get(Object) | |
| 490 | */ | |
| 491 | ||
| 492 | 20630 | public Object put(Object key, Object value) { |
| 493 | 20630 | if (value == null) |
| 494 | 0 | throw new NullPointerException(); |
| 495 | ||
| 496 | 20630 | int hash = hash(key); |
| 497 | 20630 | Entry[] tab = table; |
| 498 | 20630 | int index = hash & (tab.length - 1); |
| 499 | 20630 | Entry first = tab[index]; |
| 500 | 20630 | Entry e; |
| 501 | ||
| 502 | 20630 | for (e = first; e != null; e = e.next) |
| 503 | 4289 | if (e.hash == hash && eq(key, e.key)) |
| 504 | 6 | break; |
| 505 | ||
| 506 | 20630 | synchronized (this) { |
| 507 | 20630 | if (tab == table) { |
| 508 | 20630 | if (e == null) { |
| 509 | // make sure we are adding to correct list | |
| 510 | 20624 | if (first == tab[index]) { |
| 511 | // Add to front of list | |
| 512 | 20624 | Entry newEntry = new Entry(hash, key, value, first); |
| 513 | 20624 | tab[index] = newEntry; |
| 514 | 20624 | if (++count >= threshold) |
| 515 | 9 | rehash(); |
| 516 | else | |
| 517 | 20615 | recordModification(newEntry); |
| 518 | 20624 | return null; |
| 519 | } | |
| 520 | } else { | |
| 521 | 6 | Object oldValue = e.value; |
| 522 | 6 | if (first == tab[index] && oldValue != null) { |
| 523 | 6 | e.value = value; |
| 524 | 6 | return oldValue; |
| 525 | } | |
| 526 | } | |
| 527 | } | |
| 528 | ||
| 529 | // retry if wrong list or lost race against concurrent remove | |
| 530 | 0 | return sput(key, value, hash); |
| 531 | } | |
| 532 | } | |
| 533 | ||
| 534 | /** | |
| 535 | * Continuation of put(), called only when synch lock is held and | |
| 536 | * interference has been detected. | |
| 537 | */ | |
| 538 | 0 | protected Object sput(Object key, Object value, int hash) { |
| 539 | ||
| 540 | 0 | Entry[] tab = table; |
| 541 | 0 | int index = hash & (tab.length - 1); |
| 542 | 0 | Entry first = tab[index]; |
| 543 | 0 | Entry e = first; |
| 544 | ||
| 545 | 0 | for (;;) { |
| 546 | 0 | if (e == null) { |
| 547 | 0 | Entry newEntry = new Entry(hash, key, value, first); |
| 548 | 0 | tab[index] = newEntry; |
| 549 | 0 | if (++count >= threshold) |
| 550 | 0 | rehash(); |
| 551 | else | |
| 552 | 0 | recordModification(newEntry); |
| 553 | 0 | return null; |
| 554 | 0 | } else if (e.hash == hash && eq(key, e.key)) { |
| 555 | 0 | Object oldValue = e.value; |
| 556 | 0 | e.value = value; |
| 557 | 0 | return oldValue; |
| 558 | } else | |
| 559 | 0 | e = e.next; |
| 560 | } | |
| 561 | } | |
| 562 | ||
| 563 | /** | |
| 564 | * Rehashes the contents of this map into a new table with a larger | |
| 565 | * capacity. This method is called automatically when the number of keys in | |
| 566 | * this map exceeds its capacity and load factor. | |
| 567 | */ | |
| 568 | 9 | protected void rehash() { |
| 569 | 9 | Entry[] oldTable = table; |
| 570 | 9 | int oldCapacity = oldTable.length; |
| 571 | 9 | if (oldCapacity >= MAXIMUM_CAPACITY) { |
| 572 | 0 | threshold = Integer.MAX_VALUE; // avoid retriggering |
| 573 | 0 | return; |
| 574 | } | |
| 575 | ||
| 576 | 9 | int newCapacity = oldCapacity << 1; |
| 577 | 9 | int mask = newCapacity - 1; |
| 578 | 9 | threshold = (int) (newCapacity * loadFactor); |
| 579 | ||
| 580 | 9 | Entry[] newTable = new Entry[newCapacity]; |
| 581 | /* | |
| 582 | * Reclassify nodes in each list to new Map. Because we are using | |
| 583 | * power-of-two expansion, the elements from each bin must either stay | |
| 584 | * at same index, or move to oldCapacity+index. We also eliminate | |
| 585 | * unnecessary node creation by catching cases where old nodes can be | |
| 586 | * reused because their next fields won't change. Statistically, at the | |
| 587 | * default threshhold, only about one-sixth of them need cloning. (The | |
| 588 | * nodes they replace will be garbage collectable as soon as they are no | |
| 589 | * longer referenced by any reader thread that may be in the midst of | |
| 590 | * traversing table right now.) | |
| 591 | */ | |
| 592 | ||
| 593 | 9 | for (int i = 0; i < oldCapacity; i++) { |
| 594 | // We need to guarantee that any existing reads of old Map can | |
| 595 | // proceed. So we cannot yet null out each bin. | |
| 596 | 16352 | Entry e = oldTable[i]; |
| 597 | ||
| 598 | 16352 | if (e != null) { |
| 599 | 8821 | int idx = e.hash & mask; |
| 600 | 8821 | Entry next = e.next; |
| 601 | ||
| 602 | // Single node on list | |
| 603 | 8821 | if (next == null) |
| 604 | 5980 | newTable[idx] = e; |
| 605 | ||
| 606 | else { | |
| 607 | // Reuse trailing consecutive sequence of all same bit | |
| 608 | 2841 | Entry lastRun = e; |
| 609 | 2841 | int lastIdx = idx; |
| 610 | 2841 | for (Entry last = next; last != null; last = last.next) { |
| 611 | 3443 | int k = last.hash & mask; |
| 612 | 3443 | if (k != lastIdx) { |
| 613 | 1921 | lastIdx = k; |
| 614 | 1921 | lastRun = last; |
| 615 | } | |
| 616 | } | |
| 617 | 2841 | newTable[lastIdx] = lastRun; |
| 618 | ||
| 619 | // Clone all remaining nodes | |
| 620 | 2841 | for (Entry p = e; p != lastRun; p = p.next) { |
| 621 | 2116 | int k = p.hash & mask; |
| 622 | 2116 | newTable[k] = new Entry(p.hash, p.key, p.value, |
| 623 | newTable[k]); | |
| 624 | } | |
| 625 | } | |
| 626 | } | |
| 627 | } | |
| 628 | ||
| 629 | 9 | table = newTable; |
| 630 | 9 | recordModification(newTable); |
| 631 | } | |
| 632 | ||
| 633 | /** | |
| 634 | * Removes the key (and its corresponding value) from this table. This | |
| 635 | * method does nothing if the key is not in the table. | |
| 636 | * | |
| 637 | * @param key | |
| 638 | * the key that needs to be removed. | |
| 639 | * @return the value to which the key had been mapped in this table, or | |
| 640 | * null if the key did not have a mapping. | |
| 641 | * @exception NullPointerException | |
| 642 | * if the key is null. | |
| 643 | */ | |
| 644 | ||
| 645 | 0 | public Object remove(Object key) { |
| 646 | /* | |
| 647 | * Find the entry, then 1. Set value field to null, to force get() to | |
| 648 | * retry 2. Rebuild the list without this entry. All entries following | |
| 649 | * removed node can stay in list, but all preceeding ones need to be | |
| 650 | * cloned. Traversals rely on this strategy to ensure that elements will | |
| 651 | * not be repeated during iteration. | |
| 652 | */ | |
| 653 | ||
| 654 | 0 | int hash = hash(key); |
| 655 | 0 | Entry[] tab = table; |
| 656 | 0 | int index = hash & (tab.length - 1); |
| 657 | 0 | Entry first = tab[index]; |
| 658 | 0 | Entry e = first; |
| 659 | ||
| 660 | 0 | for (e = first; e != null; e = e.next) |
| 661 | 0 | if (e.hash == hash && eq(key, e.key)) |
| 662 | 0 | break; |
| 663 | ||
| 664 | 0 | synchronized (this) { |
| 665 | 0 | if (tab == table) { |
| 666 | 0 | if (e == null) { |
| 667 | 0 | if (first == tab[index]) |
| 668 | 0 | return null; |
| 669 | } else { | |
| 670 | 0 | Object oldValue = e.value; |
| 671 | 0 | if (first == tab[index] && oldValue != null) { |
| 672 | 0 | e.value = null; |
| 673 | 0 | count--; |
| 674 | ||
| 675 | 0 | Entry head = e.next; |
| 676 | 0 | for (Entry p = first; p != e; p = p.next) |
| 677 | 0 | head = new Entry(p.hash, p.key, p.value, head); |
| 678 | ||
| 679 | 0 | tab[index] = head; |
| 680 | 0 | recordModification(head); |
| 681 | 0 | return oldValue; |
| 682 | } | |
| 683 | } | |
| 684 | } | |
| 685 | ||
| 686 | // Wrong list or interference | |
| 687 | 0 | return sremove(key, hash); |
| 688 | } | |
| 689 | } | |
| 690 | ||
| 691 | /** | |
| 692 | * Continuation of remove(), called only when synch lock is held and | |
| 693 | * interference has been detected. | |
| 694 | */ | |
| 695 | ||
| 696 | 0 | protected Object sremove(Object key, int hash) { |
| 697 | 0 | Entry[] tab = table; |
| 698 | 0 | int index = hash & (tab.length - 1); |
| 699 | 0 | Entry first = tab[index]; |
| 700 | ||
| 701 | 0 | for (Entry e = first; e != null; e = e.next) { |
| 702 | 0 | if (e.hash == hash && eq(key, e.key)) { |
| 703 | 0 | Object oldValue = e.value; |
| 704 | 0 | e.value = null; |
| 705 | 0 | count--; |
| 706 | 0 | Entry head = e.next; |
| 707 | 0 | for (Entry p = first; p != e; p = p.next) |
| 708 | 0 | head = new Entry(p.hash, p.key, p.value, head); |
| 709 | ||
| 710 | 0 | tab[index] = head; |
| 711 | 0 | recordModification(head); |
| 712 | 0 | return oldValue; |
| 713 | } | |
| 714 | } | |
| 715 | 0 | return null; |
| 716 | } | |
| 717 | ||
| 718 | /** | |
| 719 | * Returns <tt>true</tt> if this map maps one or more keys to the | |
| 720 | * specified value. Note: This method requires a full internal traversal of | |
| 721 | * the hash table, and so is much slower than method <tt>containsKey</tt>. | |
| 722 | * | |
| 723 | * @param value | |
| 724 | * value whose presence in this map is to be tested. | |
| 725 | * @return <tt>true</tt> if this map maps one or more keys to the | |
| 726 | * specified value. | |
| 727 | * @exception NullPointerException | |
| 728 | * if the value is null. | |
| 729 | */ | |
| 730 | ||
| 731 | 0 | public boolean containsValue(Object value) { |
| 732 | 0 | if (value == null) |
| 733 | 0 | throw new NullPointerException(); |
| 734 | ||
| 735 | 0 | Entry tab[] = getTableForReading(); |
| 736 | ||
| 737 | 0 | for (int i = 0; i < tab.length; ++i) { |
| 738 | 0 | for (Entry e = tab[i]; e != null; e = e.next) |
| 739 | 0 | if (value.equals(e.value)) |
| 740 | 0 | return true; |
| 741 | } | |
| 742 | ||
| 743 | 0 | return false; |
| 744 | } | |
| 745 | ||
| 746 | /** | |
| 747 | * Tests if some key maps into the specified value in this table. This | |
| 748 | * operation is more expensive than the containsKey method. | |
| 749 | *
 | |
| 750 | * | |
| 751 | * Note that this method is identical in functionality to containsValue, | |
| 752 | * (which is part of the Map interface in the collections framework). | |
| 753 | * | |
| 754 | * @param value | |
| 755 | * a value to search for. | |
| 756 | * @return true if and only if some key maps to the | |
| 757 | * value argument in this table as determined by the | |
| 758 | * <tt>equals</tt> method; false otherwise. | |
| 759 | * @exception NullPointerException | |
| 760 | * if the value is null. | |
| 761 | * @see #containsKey(Object) | |
| 762 | * @see #containsValue(Object) | |
| 763 | * @see Map | |
| 764 | */ | |
| 765 | ||
| 766 | 0 | public boolean contains(Object value) { |
| 767 | 0 | return containsValue(value); |
| 768 | } | |
| 769 | ||
| 770 | /** | |
| 771 | * Copies all of the mappings from the specified map to this one. | |
| 772 | * | |
| 773 | * These mappings replace any mappings that this map had for any of the keys | |
| 774 | * currently in the specified Map. | |
| 775 | * | |
| 776 | * @param t | |
| 777 | * Mappings to be stored in this map. | |
| 778 | */ | |
| 779 | ||
| 780 | 0 | public synchronized void putAll(Map t) { |
| 781 | 0 | int n = t.size(); |
| 782 | 0 | if (n == 0) |
| 783 | 0 | return; |
| 784 | ||
| 785 | // Expand enough to hold at least n elements without resizing. | |
| 786 | // We can only resize table by factor of two at a time. | |
| 787 | // It is faster to rehash with fewer elements, so do it now. | |
| 788 | 0 | while (n >= threshold) |
| 789 | 0 | rehash(); |
| 790 | ||
| 791 | 0 | for (Iterator it = t.entrySet().iterator(); it.hasNext();) { |
| 792 | 0 | Map.Entry entry = (Map.Entry) it.next(); |
| 793 | 0 | Object key = entry.getKey(); |
| 794 | 0 | Object value = entry.getValue(); |
| 795 | 0 | put(key, value); |
| 796 | } | |
| 797 | } | |
| 798 | ||
| 799 | /** | |
| 800 | * Removes all mappings from this map. | |
| 801 | */ | |
| 802 | 0 | public synchronized void clear() { |
| 803 | 0 | Entry tab[] = table; |
| 804 | 0 | for (int i = 0; i < tab.length; ++i) { |
| 805 | ||
| 806 | // must invalidate all to force concurrent get's to wait and then | |
| 807 | // retry | |
| 808 | 0 | for (Entry e = tab[i]; e != null; e = e.next) |
| 809 | 0 | e.value = null; |
| 810 | ||
| 811 | 0 | tab[i] = null; |
| 812 | } | |
| 813 | 0 | count = 0; |
| 814 | 0 | recordModification(tab); |
| 815 | } | |
| 816 | ||
| 817 | /** | |
| 818 | * Returns a shallow copy of this <tt>ConcurrentReaderHashMap</tt> | |
| 819 | * instance: the keys and values themselves are not cloned. | |
| 820 | * | |
| 821 | * @return a shallow copy of this map. | |
| 822 | */ | |
| 823 | ||
| 824 | 0 | public synchronized Object clone() { |
| 825 | 0 | try { |
| 826 | 0 | ConcurrentReaderHashMap t = (ConcurrentReaderHashMap) super.clone(); |
| 827 | ||
| 828 | 0 | t.keySet = null; |
| 829 | 0 | t.entrySet = null; |
| 830 | 0 | t.values = null; |
| 831 | ||
| 832 | 0 | Entry[] tab = table; |
| 833 | 0 | t.table = new Entry[tab.length]; |
| 834 | 0 | Entry[] ttab = t.table; |
| 835 | ||
| 836 | 0 | for (int i = 0; i < tab.length; ++i) { |
| 837 | 0 | Entry first = null; |
| 838 | 0 | for (Entry e = tab[i]; e != null; e = e.next) |
| 839 | 0 | first = new Entry(e.hash, e.key, e.value, first); |
| 840 | 0 | ttab[i] = first; |
| 841 | } | |
| 842 | ||
| 843 | 0 | return t; |
| 844 | } catch (CloneNotSupportedException e) { | |
| 845 | // this shouldn't happen, since we are Cloneable | |
| 846 | 0 | throw new InternalError(); |
| 847 | } | |
| 848 | } | |
| 849 | ||
| 850 | // Views | |
| 851 | ||
| 852 | protected transient Set keySet = null; | |
| 853 | ||
| 854 | protected transient Set entrySet = null; | |
| 855 | ||
| 856 | protected transient Collection values = null; | |
| 857 | ||
| 858 | /** | |
| 859 | * Returns a set view of the keys contained in this map. The set is backed | |
| 860 | * by the map, so changes to the map are reflected in the set, and | |
| 861 | * vice-versa. The set supports element removal, which removes the | |
| 862 | * corresponding mapping from this map, via the <tt>Iterator.remove</tt>, | |
| 863 | * <tt>Set.remove</tt>,<tt>removeAll</tt>,<tt>retainAll</tt>, and | |
| 864 | * <tt>clear</tt> operations. It does not support the <tt>add</tt> or | |
| 865 | * <tt>addAll</tt> operations. | |
| 866 | * | |
| 867 | * @return a set view of the keys contained in this map. | |
| 868 | */ | |
| 869 | ||
| 870 | 0 | public Set keySet() { |
| 871 | 0 | Set ks = keySet; |
| 872 | 0 | return (ks != null) ? ks : (keySet = new KeySet()); |
| 873 | } | |
| 874 | ||
| 875 | private class KeySet extends AbstractSet { | |
| 876 | 0 | public Iterator iterator() { |
| 877 | 0 | return new KeyIterator(); |
| 878 | } | |
| 879 | ||
| 880 | 0 | public int size() { |
| 881 | 0 | return ConcurrentReaderHashMap.this.size(); |
| 882 | } | |
| 883 | ||
| 884 | 0 | public boolean contains(Object o) { |
| 885 | 0 | return ConcurrentReaderHashMap.this.containsKey(o); |
| 886 | } | |
| 887 | ||
| 888 | 0 | public boolean remove(Object o) { |
| 889 | 0 | return ConcurrentReaderHashMap.this.remove(o) != null; |
| 890 | } | |
| 891 | ||
| 892 | 0 | public void clear() { |
| 893 | 0 | ConcurrentReaderHashMap.this.clear(); |
| 894 | } | |
| 895 | } | |
| 896 | ||
| 897 | /** | |
| 898 | * Returns a collection view of the values contained in this map. The | |
| 899 | * collection is backed by the map, so changes to the map are reflected in | |
| 900 | * the collection, and vice-versa. The collection supports element removal, | |
| 901 | * which removes the corresponding mapping from this map, via the | |
| 902 | * <tt>Iterator.remove</tt>,<tt>Collection.remove</tt>, | |
| 903 | * <tt>removeAll</tt>,<tt>retainAll</tt>, and <tt>clear</tt> | |
| 904 | * operations. It does not support the <tt>add</tt> or <tt>addAll</tt> | |
| 905 | * operations. | |
| 906 | * | |
| 907 | * @return a collection view of the values contained in this map. | |
| 908 | */ | |
| 909 | ||
| 910 | 0 | public Collection values() { |
| 911 | 0 | Collection vs = values; |
| 912 | 0 | return (vs != null) ? vs : (values = new Values()); |
| 913 | } | |
| 914 | ||
| 915 | private class Values extends AbstractCollection { | |
| 916 | 0 | public Iterator iterator() { |
| 917 | 0 | return new ValueIterator(); |
| 918 | } | |
| 919 | ||
| 920 | 0 | public int size() { |
| 921 | 0 | return ConcurrentReaderHashMap.this.size(); |
| 922 | } | |
| 923 | ||
| 924 | 0 | public boolean contains(Object o) { |
| 925 | 0 | return ConcurrentReaderHashMap.this.containsValue(o); |
| 926 | } | |
| 927 | ||
| 928 | 0 | public void clear() { |
| 929 | 0 | ConcurrentReaderHashMap.this.clear(); |
| 930 | } | |
| 931 | } | |
| 932 | ||
| 933 | /** | |
| 934 | * Returns a collection view of the mappings contained in this map. Each | |
| 935 | * element in the returned collection is a <tt>Map.Entry</tt>. The | |
| 936 | * collection is backed by the map, so changes to the map are reflected in | |
| 937 | * the collection, and vice-versa. The collection supports element removal, | |
| 938 | * which removes the corresponding mapping from the map, via the | |
| 939 | * <tt>Iterator.remove</tt>,<tt>Collection.remove</tt>, | |
| 940 | * <tt>removeAll</tt>,<tt>retainAll</tt>, and <tt>clear</tt> | |
| 941 | * operations. It does not support the <tt>add</tt> or <tt>addAll</tt> | |
| 942 | * operations. | |
| 943 | * | |
| 944 | * @return a collection view of the mappings contained in this map. | |
| 945 | */ | |
| 946 | ||
| 947 | 0 | public Set entrySet() { |
| 948 | 0 | Set es = entrySet; |
| 949 | 0 | return (es != null) ? es : (entrySet = new EntrySet()); |
| 950 | } | |
| 951 | ||
| 952 | private class EntrySet extends AbstractSet { | |
| 953 | 0 | public Iterator iterator() { |
| 954 | 0 | return new HashIterator(); |
| 955 | } | |
| 956 | ||
| 957 | 0 | public boolean contains(Object o) { |
| 958 | 0 | if (!(o instanceof Map.Entry)) |
| 959 | 0 | return false; |
| 960 | 0 | Map.Entry entry = (Map.Entry) o; |
| 961 | 0 | Object v = ConcurrentReaderHashMap.this.get(entry.getKey()); |
| 962 | 0 | return v != null && v.equals(entry.getValue()); |
| 963 | } | |
| 964 | ||
| 965 | 0 | public boolean remove(Object o) { |
| 966 | 0 | if (!(o instanceof Map.Entry)) |
| 967 | 0 | return false; |
| 968 | 0 | return ConcurrentReaderHashMap.this |
| 969 | .findAndRemoveEntry((Map.Entry) o); | |
| 970 | } | |
| 971 | ||
| 972 | 0 | public int size() { |
| 973 | 0 | return ConcurrentReaderHashMap.this.size(); |
| 974 | } | |
| 975 | ||
| 976 | 0 | public void clear() { |
| 977 | 0 | ConcurrentReaderHashMap.this.clear(); |
| 978 | } | |
| 979 | } | |
| 980 | ||
| 981 | /** | |
| 982 | * Helper method for entrySet.remove | |
| 983 | */ | |
| 984 | 0 | protected synchronized boolean findAndRemoveEntry(Map.Entry entry) { |
| 985 | 0 | Object key = entry.getKey(); |
| 986 | 0 | Object v = get(key); |
| 987 | 0 | if (v != null && v.equals(entry.getValue())) { |
| 988 | 0 | remove(key); |
| 989 | 0 | return true; |
| 990 | } else | |
| 991 | 0 | return false; |
| 992 | } | |
| 993 | ||
| 994 | /** | |
| 995 | * Returns an enumeration of the keys in this table. | |
| 996 | * | |
| 997 | * @return an enumeration of the keys in this table. | |
| 998 | * @see Enumeration | |
| 999 | * @see #elements() | |
| 1000 | * @see #keySet() | |
| 1001 | * @see Map | |
| 1002 | */ | |
| 1003 | 0 | public Enumeration keys() { |
| 1004 | 0 | return new KeyIterator(); |
| 1005 | } | |
| 1006 | ||
| 1007 | /** | |
| 1008 | * Returns an enumeration of the values in this table. Use the Enumeration | |
| 1009 | * methods on the returned object to fetch the elements sequentially. | |
| 1010 | * | |
| 1011 | * @return an enumeration of the values in this table. | |
| 1012 | * @see java.util.Enumeration | |
| 1013 | * @see #keys() | |
| 1014 | * @see #values() | |
| 1015 | * @see Map | |
| 1016 | */ | |
| 1017 | ||
| 1018 | 0 | public Enumeration elements() { |
| 1019 | 0 | return new ValueIterator(); |
| 1020 | } | |
| 1021 | ||
| 1022 | /** | |
| 1023 | * ConcurrentReaderHashMap collision list entry. | |
| 1024 | */ | |
| 1025 | ||
| 1026 | protected static class Entry implements Map.Entry { | |
| 1027 | ||
| 1028 | /* | |
| 1029 | * The use of volatile for value field ensures that we can detect status | |
| 1030 | * changes without synchronization. The other fields are never changed, | |
| 1031 | * and are marked as final. | |
| 1032 | */ | |
| 1033 | ||
| 1034 | protected final int hash; | |
| 1035 | ||
| 1036 | protected final Object key; | |
| 1037 | ||
| 1038 | protected final Entry next; | |
| 1039 | ||
| 1040 | protected volatile Object value; | |
| 1041 | ||
| 1042 | 22740 | Entry(int hash, Object key, Object value, Entry next) { |
| 1043 | 22740 | this.hash = hash; |
| 1044 | 22740 | this.key = key; |
| 1045 | 22740 | this.next = next; |
| 1046 | 22740 | this.value = value; |
| 1047 | } | |
| 1048 | ||
| 1049 | // Map.Entry Ops | |
| 1050 | ||
| 1051 | 0 | public Object getKey() { |
| 1052 | 0 | return key; |
| 1053 | } | |
| 1054 | ||
| 1055 | /** | |
| 1056 | * Get the value. Note: In an entrySet or entrySet.iterator, unless the | |
| 1057 | * set or iterator is used under synchronization of the table as a whole | |
| 1058 | * (or you can otherwise guarantee lack of concurrent modification), | |
| 1059 | * <tt>getValue</tt> might return null, reflecting the fact | |
| 1060 | * that the entry has been concurrently removed. However, there are no | |
| 1061 | * assurances that concurrent removals will be reflected using this | |
| 1062 | * method. | |
| 1063 | * | |
| 1064 | * @return the current value, or null if the entry has been detectably | |
| 1065 | * removed. | |
| 1066 | */ | |
| 1067 | 0 | public Object getValue() { |
| 1068 | 0 | return value; |
| 1069 | } | |
| 1070 | ||
| 1071 | /** | |
| 1072 | * Set the value of this entry. Note: In an entrySet or | |
| 1073 | * entrySet.iterator), unless the set or iterator is used under | |
| 1074 | * synchronization of the table as a whole (or you can otherwise | |
| 1075 | * guarantee lack of concurrent modification), <tt>setValue</tt> is | |
| 1076 | * not strictly guaranteed to actually replace the value field obtained | |
| 1077 | * via the <tt>get</tt> operation of the underlying hash table in | |
| 1078 | * multithreaded applications. If iterator-wide synchronization is not | |
| 1079 | * used, and any other concurrent <tt>put</tt> or <tt>remove</tt> | |
| 1080 | * operations occur, sometimes even to other entries, then | |
| 1081 | * this change is not guaranteed to be reflected in the hash table. (It | |
| 1082 | * might, or it might not. There are no assurances either way.) | |
| 1083 | * | |
| 1084 | * @param value | |
| 1085 | * the new value. | |
| 1086 | * @return the previous value, or null if entry has been detectably | |
| 1087 | * removed. | |
| 1088 | * @exception NullPointerException | |
| 1089 | * if the value is null. | |
| 1090 | * | |
| 1091 | */ | |
| 1092 | ||
| 1093 | 0 | public Object setValue(Object value) { |
| 1094 | 0 | if (value == null) |
| 1095 | 0 | throw new NullPointerException(); |
| 1096 | 0 | Object oldValue = this.value; |
| 1097 | 0 | this.value = value; |
| 1098 | 0 | return oldValue; |
| 1099 | } | |
| 1100 | ||
| 1101 | 0 | public boolean equals(Object o) { |
| 1102 | 0 | if (!(o instanceof Map.Entry)) |
| 1103 | 0 | return false; |
| 1104 | 0 | Map.Entry e = (Map.Entry) o; |
| 1105 | 0 | return (key.equals(e.getKey()) && value.equals(e.getValue())); |
| 1106 | } | |
| 1107 | ||
| 1108 | 0 | public int hashCode() { |
| 1109 | 0 | return key.hashCode() ^ value.hashCode(); |
| 1110 | } | |
| 1111 | ||
| 1112 | 0 | public String toString() { |
| 1113 | 0 | return key + "=" + value; |
| 1114 | } | |
| 1115 | ||
| 1116 | } | |
| 1117 | ||
| 1118 | protected class HashIterator implements Iterator, Enumeration { | |
| 1119 | protected final Entry[] tab; // snapshot of table | |
| 1120 | ||
| 1121 | protected int index; // current slot | |
| 1122 | ||
| 1123 | protected Entry entry = null; // current node of slot | |
| 1124 | ||
| 1125 | protected Object currentKey; // key for current node | |
| 1126 | ||
| 1127 | protected Object currentValue; // value for current node | |
| 1128 | ||
| 1129 | protected Entry lastReturned = null; // last node returned by next | |
| 1130 | ||
| 1131 | 0 | protected HashIterator() { |
| 1132 | 0 | tab = ConcurrentReaderHashMap.this.getTableForReading(); |
| 1133 | 0 | index = tab.length - 1; |
| 1134 | } | |
| 1135 | ||
| 1136 | 0 | public boolean hasMoreElements() { |
| 1137 | 0 | return hasNext(); |
| 1138 | } | |
| 1139 | ||
| 1140 | 0 | public Object nextElement() { |
| 1141 | 0 | return next(); |
| 1142 | } | |
| 1143 | ||
| 1144 | 0 | public boolean hasNext() { |
| 1145 | ||
| 1146 | /* | |
| 1147 | * currentkey and currentValue are set here to ensure that next() | |
| 1148 | * returns normally if hasNext() returns true. This avoids surprises | |
| 1149 | * especially when final element is removed during traversal -- | |
| 1150 | * instead, we just ignore the removal during current traversal. | |
| 1151 | */ | |
| 1152 | ||
| 1153 | 0 | for (;;) { |
| 1154 | 0 | if (entry != null) { |
| 1155 | 0 | Object v = entry.value; |
| 1156 | 0 | if (v != null) { |
| 1157 | 0 | currentKey = entry.key; |
| 1158 | 0 | currentValue = v; |
| 1159 | 0 | return true; |
| 1160 | } else | |
| 1161 | 0 | entry = entry.next; |
| 1162 | } | |
| 1163 | ||
| 1164 | 0 | while (entry == null && index >= 0) |
| 1165 | 0 | entry = tab[index--]; |
| 1166 | ||
| 1167 | 0 | if (entry == null) { |
| 1168 | 0 | currentKey = currentValue = null; |
| 1169 | 0 | return false; |
| 1170 | } | |
| 1171 | } | |
| 1172 | } | |
| 1173 | ||
| 1174 | 0 | protected Object returnValueOfNext() { |
| 1175 | 0 | return entry; |
| 1176 | } | |
| 1177 | ||
| 1178 | 0 | public Object next() { |
| 1179 | 0 | if (currentKey == null && !hasNext()) |
| 1180 | 0 | throw new NoSuchElementException(); |
| 1181 | ||
| 1182 | 0 | Object result = returnValueOfNext(); |
| 1183 | 0 | lastReturned = entry; |
| 1184 | 0 | currentKey = currentValue = null; |
| 1185 | 0 | entry = entry.next; |
| 1186 | 0 | return result; |
| 1187 | } | |
| 1188 | ||
| 1189 | 0 | public void remove() { |
| 1190 | 0 | if (lastReturned == null) |
| 1191 | 0 | throw new IllegalStateException(); |
| 1192 | 0 | ConcurrentReaderHashMap.this.remove(lastReturned.key); |
| 1193 | 0 | lastReturned = null; |
| 1194 | } | |
| 1195 | ||
| 1196 | } | |
| 1197 | ||
| 1198 | protected class KeyIterator extends HashIterator { | |
| 1199 | 0 | protected Object returnValueOfNext() { |
| 1200 | 0 | return currentKey; |
| 1201 | } | |
| 1202 | } | |
| 1203 | ||
| 1204 | protected class ValueIterator extends HashIterator { | |
| 1205 | 0 | protected Object returnValueOfNext() { |
| 1206 | 0 | return currentValue; |
| 1207 | } | |
| 1208 | } | |
| 1209 | ||
| 1210 | /** | |
| 1211 | * Save the state of the <tt>ConcurrentReaderHashMap</tt> instance to a | |
| 1212 | * stream (i.e., serialize it). | |
| 1213 | * | |
| 1214 | * @serialData The capacity  of the ConcurrentReaderHashMap (the | |
| 1215 | * length of the bucket array) is emitted (int), followed by the | |
| 1216 | * size  of the ConcurrentReaderHashMap (the number of | |
| 1217 | * key-value mappings), followed by the key (Object) and value | |
| 1218 | * (Object) for each key-value mapping represented by the | |
| 1219 | * ConcurrentReaderHashMap The key-value mappings are emitted in | |
| 1220 | * no particular order. | |
| 1221 | */ | |
| 1222 | ||
| 1223 | 0 | private synchronized void writeObject(java.io.ObjectOutputStream s) |
| 1224 | throws IOException { | |
| 1225 | // Write out the threshold, loadfactor, and any hidden stuff | |
| 1226 | 0 | s.defaultWriteObject(); |
| 1227 | ||
| 1228 | // Write out number of buckets | |
| 1229 | 0 | s.writeInt(table.length); |
| 1230 | ||
| 1231 | // Write out size (number of Mappings) | |
| 1232 | 0 | s.writeInt(count); |
| 1233 | ||
| 1234 | // Write out keys and values (alternating) | |
| 1235 | 0 | for (int index = table.length - 1; index >= 0; index--) { |
| 1236 | 0 | Entry entry = table[index]; |
| 1237 | ||
| 1238 | 0 | while (entry != null) { |
| 1239 | 0 | s.writeObject(entry.key); |
| 1240 | 0 | s.writeObject(entry.value); |
| 1241 | 0 | entry = entry.next; |
| 1242 | } | |
| 1243 | } | |
| 1244 | } | |
| 1245 | ||
| 1246 | /** | |
| 1247 | * Reconstitute the <tt>ConcurrentReaderHashMap</tt> instance from a | |
| 1248 | * stream (i.e., deserialize it). | |
| 1249 | */ | |
| 1250 | 0 | private synchronized void readObject(java.io.ObjectInputStream s) |
| 1251 | throws IOException, ClassNotFoundException { | |
| 1252 | // Read in the threshold, loadfactor, and any hidden stuff | |
| 1253 | 0 | s.defaultReadObject(); |
| 1254 | ||
| 1255 | // Read in number of buckets and allocate the bucket array; | |
| 1256 | 0 | int numBuckets = s.readInt(); |
| 1257 | 0 | table = new Entry[numBuckets]; |
| 1258 | ||
| 1259 | // Read in size (number of Mappings) | |
| 1260 | 0 | int size = s.readInt(); |
| 1261 | ||
| 1262 | // Read the keys and values, and put the mappings in the table | |
| 1263 | 0 | for (int i = 0; i < size; i++) { |
| 1264 | 0 | Object key = s.readObject(); |
| 1265 | 0 | Object value = s.readObject(); |
| 1266 | 0 | put(key, value); |
| 1267 | } | |
| 1268 | } | |
| 1269 | ||
| 1270 | /** | |
| 1271 | * Return the number of slots in this table | |
| 1272 | */ | |
| 1273 | ||
| 1274 | 0 | public synchronized int capacity() { |
| 1275 | 0 | return table.length; |
| 1276 | } | |
| 1277 | ||
| 1278 | /** | |
| 1279 | * Return the load factor | |
| 1280 | */ | |
| 1281 | 0 | public float loadFactor() { |
| 1282 | 0 | return loadFactor; |
| 1283 | } | |
| 1284 | } |
|


Here are the entered strings:
First string:
{{ string1 }}
Second string:
{{ string2 }}
The words that the strings have in common are:
{{ union }}